Technical Architecture and Teaching Practices of an AI Learning Companion System
This article explains how to build an AI learning companion that teaches rather than simply answers questions. It breaks the system into practical modules: structured world-building and motivation modeling, a constrained Socratic questioning engine, textbook-grounded retrieval with citation and hallucination control, and cross-device state synchronization with a note system. It also outlines a phased rollout plan and an acceptance checklist focused on traceability, constraints, and knowledge accumulation.
1. Background: Why a Model That Answers Is Not a System That Teaches
Connecting a large language model directly to a chat window often produces a conversational agent that is knowledgeable but cannot teach. It tends to deliver conclusions all at once, leaving learners in a passive role. It may generate plausible content that does not exist in the textbook. And it cannot remember which concept a learner struggled with three weeks ago.
To build a usable AI learning companion, the engineering focus is not model parameters but three things: modeling learning motivation, constraining the teaching flow, and controlling knowledge sources. The sections below turn these three points into implementable module designs.
2. Module 1: Character-Driven Worldview and Motivation Modeling
An anime-style layer is not decoration; it is the motivation system. Learners can define their own worldview, storyline, companion character, and personality settings, then have learning goals packaged as a “mission.” These settings should be stored in a structured form and kept separate from teaching state:
{"world": {"name": "Star Sea Academy", "rules": ["Knowledge is the pass for access"]},"companion": {"persona": "A rigorous but gentle senior", "tone": "Restrained, encourages questions"},"mission": {"goal": "Repair the jump engine", "mapped_skill": "Linear Algebra - Eigenvalues"},"affinity": {"level": 3, "decay": 0.02}}
Three design principles matter. First, the persona should affect only how things are expressed, not the correctness of knowledge. The two must be layered to avoid “fabricating facts for the sake of character consistency.” Second, affection and affinity should be a by-product of teaching feedback, driven by observable signals such as attendance, the quality of consecutive questions, and review completion, with decay and caps to prevent unlimited farming. Third, missions should map to knowledge points through a mapping table so narrative progress aligns with course progress, preventing learners from “having fun but learning nothing.”
3. Module 2: Engineering a Socratic Questioning Engine
The core of the Socratic method is “don’t give the answer, give the next question.” In engineering terms, this can be implemented as a constrained state machine rather than free generation:
- Diagnose: use one or two preliminary questions to locate misconceptions.
- Probe: raise counterexamples or extreme cases against the misconception to create cognitive conflict.
- Guide: break the big problem into verifiable small steps and require the learner to reason explicitly.
- Converge: after the learner states a conclusion, add the formal statement and boundary conditions.
- Review: generate a one-sentence summary and a spaced review plan.
An illustrative prompt constraint (pseudocode):
SYSTEM = """You are a learning companion. Never give the final answer directly.Ask only one question per turn, and it must be answerable with the learner's current knowledge.If the learner gets stuck twice in a row, give a minimal hint instead of the answer.All conclusions must be stated by the learner first; then you correct them."""
For evaluation, it helps to define a “hint level” metric: track the average number of hints, time spent stuck, and the proportion of correct conclusions reached independently. These metrics reflect teaching effectiveness better than “number of dialogue turns” and make it easier to regression-test different hinting strategies.
4. Module 3: Textbook-Driven Knowledge Governance and Hallucination Suppression
The most effective way to suppress hallucinations is to shrink the generation space: ground answers in the textbook text and require source locations (chapter, page, or paragraph anchors). The data layer can use a three-part design of “raw files + structured parsing + chunked indexing”:
- Raw file layer: keep the original uploaded documents for traceability and cross-device completion.
- Parsing layer: extract heading hierarchy, paragraphs, formulas, and figure captions to form a chapter tree.
- Index layer: build a vector index by semantic chunks while keeping a keyword inverted index for exact retrieval.
The retrieval-augmented decision logic can be simplified as:
def answer(q, chunks, k=5):ctx = retrieve(q, chunks, k) # hybrid vector + keyword recallif max_score(ctx) < THRESHOLD: # if evidence is insufficient, say you don't knowreturn "Not covered by the textbook; supplementary material recommended", []return generate(q, ctx, must_cite=True), cite(ctx)
Engineering must also handle three real-world problems: scanned documents need optical character recognition and layout restoration; formulas and code blocks must retain their semantics without being split apart; and copyright and permissions need access control at the book level. For cloud deployment, you can use object storage to keep originals, a message queue to decouple parsing tasks, a container platform to host parsing and indexing services, and logging and monitoring with alerts to track parsing failure rates and retrieval hit rates.
5. Cross-Device Consistency and the Note System
Learning is a cross-context activity, so desktop, mobile, and cloud must share the same learning state. Split state into four categories: world configuration, course progress, class artifacts, and preferences. Use incremental sync and version vectors to resolve conflicts. Highlights and notes need textbook anchors and a snapshot of the class context so learners can “return to that class.” The value of a note center is to unify in-class highlights, post-class summaries, and progress for search, retrievable by textbook, keyword, or highlight style, forming reusable knowledge assets. When a learner imports a textbook and completes the original file on another device, existing progress should carry over, which requires using a content fingerprint rather than the file name as the primary key.
6. Rollout Roadmap and Acceptance Checklist
A four-phase approach is recommended: first build textbook parsing and citation traceability, then the questioning state machine, then connect characters and mission mapping, and finally complete cross-device sync and note retrieval. Acceptance should cover citation accuracy, the refusal rate for unsupported answers, average hint level, automatic cross-device conflict merge success rate, and parsing task retry success rate. Treating “traceable, constrained, accumulative” as three hard metrics is what allows an AI learning companion to move from a demo to long-term companion-style learning.
