Bỏ qua, tới nội dung chính

Kiến trúc · ADR 0039

Production-Grade AI Learning Intelligence Architecture

Trạng thái
accepted
Ngày
2026-11-21
Người quyết định
SmartLearn-AI Core Engineering Team

1. Context

SmartLearn-AI already features authoritative assessment engines:

  • Online Quiz auto-grading with question-level validation and human approval signatures.
  • C# / .NET, PostgreSQL SQL, HTTP Probe, and Multi-language sandbox runners.
  • AITA (AI-assisted Teacher Assistant) rubric evaluation with grounded code evidence and holistic feedback.
  • Deterministic mastery calculation (calculateTopicMasteryScore in @smartlearn/shared) with windowed exponential weighting, difficulty scaling, correlated-failure consolidation, and strict infrastructure failure isolation.

However, the educational feedback loop had key gaps:

  1. Curriculum Mapping Effort: Instructors had to manually write and map Learning Objectives (LOs/Topics) to lessons and questions, or rely on simple title-based heuristics.
  2. Pedagogical Explanation Gap: When a student failed a quiz or project, the system recorded the failure and opened a knowledge gap, but could not systematically diagnose _why_ the student failed (e.g. underlying conceptual misconceptions) beyond raw score percentages.
  3. Traceable Remediation: Remediation simply selected the first mapped lesson by position without contextual grounding in the student's specific error.
  4. Adaptive Practice: When students needed targeted practice to remediate a gap, the system lacked a flow to select suitable bank items or safely generate formative practice before attempting high-stakes independent reassessment.

---

2. Decision

We establish a Hybrid AI Learning Intelligence Layer integrated directly into the modular monolith, governed by the following architectural boundaries:

[Student / Instructor Portals]
              │
              ▼
[Curriculum Intelligence] (Layer A: AI LO Extraction & Auto-Mapping, with Heuristic Fallback)
              │
              ▼
[Existing Assessment Engines] (Layer B: Quiz, Code Runners, AITA Rubrics - 100% Authoritative)
              │
              ▼
[Deterministic Mastery Engine] (Layer C: calculateTopicMasteryScore - No LLM in grading path)
              │
              ▼
[Evidence-Grounded AI Diagnosis] (Layer D: Grounded Misconception Analysis, Fact vs Hypothesis)
              │
              ▼
[Grounded Resource Recommendation] (Layer E: LO + Hybrid Search in Course, Strict Real Lessons)
              │
              ▼
[Adaptive Practice & Reassessment] (Layer F: Bank First, Safe Formative Gen, Independent Reassessment)

2.1. Strict Authority & Non-Duplication Principle

  • No AI Grading Pipeline Duplication: The existing Quiz and Project/AITA runners remain the sole authoritative arbiters of points, scores, and test results.
  • No Direct LLM Mastery Manipulation: AI never directly assigns a mastery level (MASTERED, PROFICIENT, DEVELOPING) or closes a KnowledgeGap. All state transitions require verified assessment opportunities processed through calculateTopicMasteryScore.
  • Formative vs Official Assessment Boundary: AI-generated practice questions are strictly formative (learning exercises with instant feedback). They do not directly update TopicMastery. Only official quizzes or independent reassessments update authoritative mastery.

2.2. Curriculum Intelligence (Layer A)

  • suggestTopics: Uses AiService.generateObject with Zod schema (suggestTopicsResponseSchema) to extract measurable, Bloom-aligned learning objectives from course descriptions, module syllabus, and lesson markdown contents.
  • Fail-Safe Fallback: If AI is disabled or fails, seamlessly falls back to SYLLABUS_HEURISTIC.
  • suggestLessonTopicMappings: Suggests lesson-to-objective associations based on semantic alignment, returning confidence scores and pedagogical rationales for instructor review.

2.3. Evidence-Grounded AI Learning Diagnosis (Layer D)

  • LearningIntelligenceService builds an explicit, minimal diagnostic context containing: - Course and Topic metadata (code, title, approved objective). - Concrete failure evidence: question stems, incorrect student answers vs correct answers, or failed project rubric criteria with test outputs.
  • Uses prompt isolation (<student_evidence> blocks) to prevent prompt injection from untrusted student submissions.
  • Strict classification contract: - VERIFIED_BY_EVIDENCE: Factually established by test run or rubric evaluation. - PLAUSIBLE_EXPLANATION: Pedagogical hypothesis regarding conceptual confusion. - INSUFFICIENT_EVIDENCE: Withheld when data is too sparse.
  • Idempotent Caching: Computes an SHA-256 fingerprint over the evidence to cache diagnosis and avoid duplicate LLM costs.

2.4. Grounded Resource Retrieval & Recommendation (Layer E)

  • Recommendations prioritize: 1. Approved Lessons mapped via LessonTopic to the target objective. 2. Lessons matching the diagnosed misconception through full-text and hybrid retrieval.
  • Zero Hallucination Constraint: Every recommended resource references a real, published Lesson or Document in the student's enrolled course. External URLs or non-existent IDs are strictly forbidden.
  • Honors student dismissal (RecommendationStatus: DISMISSED), reopening only if severity escalates to CRITICAL.

2.5. Adaptive Practice & Independent Reassessment (Layer F)

  • Practice selection follows strict hierarchy: 1. Unattempted validated questions from the course question bank for the LO. 2. Distinct reassessment items (marked with phase: REASSESS or quizKind: REASSESS). 3. AI-generated formative practice when the bank is exhausted, with Zod schema verification and answer key validation.

---

3. Rejected Alternatives

  • External Vector DB SaaS (Pinecone / Qdrant): Rejected. Postgres pgvector and PostgreSQL full-text search already exist in the cluster and avoid multi-tenant network egress, extra subscriptions, and data synchronization overhead.
  • Multi-Agent Swarm for Diagnosis: Rejected. Overengineered, non-deterministic, high latency, and excessive token cost for single-student diagnostic enrichment.
  • LLM-Direct Grading / Mastery Scoring: Rejected. Violates core educational integrity. LLMs cannot be trusted to deterministically score math, code logic, or long-term competence without test runners.
  • Mandatory Instructor Form Flow: Rejected. Instructors should review suggestions optionally without being forced through intrusive multi-step wizards.

---

4. Consequences & Verification

  • Cost & Latency: AI enrichment runs asynchronously or with sub-second cached lookups; student quiz submissions and grading completions are never blocked by LLM response times.
  • Security & Authorization: Diagnosis endpoints enforce course enrollment and actor identity (load-then-check returning 404 for unauthorized cross-student queries).
  • Graceful Degradation: The entire platform functions with 100% operational integrity even if LLM keys are absent, expired, or rate-limited.