Building a Private Multi-Agent Teaching System from Open Source AI: An Engineering Guide
This article explains how to turn long-term documents into an interactive course using a private, self-hosted multi-agent architecture. It covers the difference between retrieval and teaching, a five-layer system design, structure-first chunking and hybrid indexing with reranking, a classroom state machine for multi-role debate, layered memory design, local deployment and security boundaries, and practical pitfalls to avoid. Readers will find role configuration examples, workflow diagrams, and a staged implementation order.
1. Why Long-Term Documents Are Hard to Actually “Learn From”
In real development and learning workflows, material is scattered across many entry points: snippets pasted into coding assistants, long articles in note-taking apps, bookmarked links in the browser, and papers and books piled up locally. These materials share one trait: they need to be retained long term and reused repeatedly, yet most tools only offer retrieval, not teaching.
The essential difference between retrieval and teaching lies in how output is organized. Retrieval returns the fragments most relevant to a query, so answer quality depends on the skill of the person asking. Teaching requires the system to build a knowledge model on its own, assess the learner’s current level, sequence topics, and insert checkpoints at key points. This is why “turning a document into a lesson” is far harder than “turning a document into a summary.”
This yields three engineering goals:
- Structured knowledge: convert unstructured long text into addressable knowledge units with hierarchy and relationships.
- Orchestrated interaction: let multiple roles collaborate according to teaching logic instead of stacking single-turn Q&A.
- Persistent memory: retain the learner profile and progress across sessions so every lesson does not start from zero.
2. Overall Architecture: What an AI Teaching Team Needs
A deployable private teaching system can usually be split into five layers. The point of layering is not formality but making each layer’s failures easy to isolate and replace.
- Ingestion layer: handle books, papers, web pages, code repositories and other inputs uniformly, performing format normalization, encoding detection, body extraction, and noise removal (headers, footers, references, navigation bars, and so on).
- Parsing and indexing layer: handle chunking, embedding, and keyword index construction while preserving source position information so any conclusion can be traced back to its origin.
- Role and orchestration layer: define the responsibilities and speaking order of roles such as professor, assistant, and peer, with an orchestrator controlling the classroom state machine.
- Memory layer: separate short-term session context, course-level progress, and a cross-course long-term learner profile.
- Delivery layer: output the syllabus, lecture notes, debate transcript, exercises, and a mistake notebook, with export to common document formats.
A sample role configuration looks like this. The key is to declare duties and constraints explicitly rather than writing a one-line persona:
{"roles": [{"id": "professor", "duty": "Build the knowledge framework and provide definitions and criteria", "constraint": "Conclusions must include citations"},{"id": "assistant", "duty": "Break down steps, generate exercises, and grade them", "constraint": "Do not give the final answer directly"},{"id": "peer", "duty": "Raise challenges and counterexamples", "constraint": "Challenges must be grounded in the material"}],"classroom": {"max_rounds": 6, "exit": "Knowledge point coverage met or rounds exhausted"}}
3. Core Mechanism 1: From Raw Material to a Teachable Knowledge Graph
High-quality lessons start with high-quality chunking. In practice, a structure-first strategy works best: split by heading hierarchy into sections, split each section into semantic paragraphs, then apply a sliding window to overly long paragraphs, keeping a certain overlap between windows to avoid semantic breaks. Each knowledge unit should carry metadata such as a source identifier, section path, page or timestamp, and topic tags.
For indexing, vector retrieval is good at semantic similarity but weak at exact matching of proper nouns, formula numbers, and clause numbers, so it usually needs to run in parallel with keyword retrieval followed by result fusion. The critical step after fusion is reranking: use a stronger relevance model to rescore candidate fragments and send only a small number of high-confidence fragments to generation. This noticeably reduces output that “reads smoothly but has no basis.”
For formulas, tables, and code, use a separate structured channel: convert formulas into readable linear expressions while keeping a reference to the original image, convert tables into key-value records, and preserve indentation and language tags for code. Otherwise this content gets flattened by generic text extraction and later explanations will inevitably be distorted.
4. Core Mechanism 2: Multi-Role Debate and the Classroom State Machine
“Interactive debate” does not mean letting a few models take turns talking; it requires clear termination conditions and deliverables. A usable classroom state machine has five states: import, ask, argue, quiz, and summary.
IMPORT -> ASK -> ARGUE(<=N rounds) -> QUIZ -> SUMMARY^ |+-- not met --+
In the ARGUE phase, the peer role raises counterexamples and edge cases, the professor role provides criteria and applicable conditions, and the assistant role brings abstract arguments back to concrete steps. A round limit is mandatory, otherwise loops that never converge are common; a rule to “stop when evidence is insufficient” is also needed so roles do not improvise where the material provides no coverage.
The QUIZ phase is the value amplifier of the whole system. Exercises should be generated automatically from the material and fall into three types: factual recall, reasoning-based application, and discriminative judgment. Grading should do more than mark right or wrong: it should point to the knowledge point ID behind each error and write mistakes back to the memory layer so they become the review entry point for the next lesson.
5. Core Mechanism 3: Memory Design and the Boundaries of Local Deployment
Long-term memory must be layered; mixing it together causes context bloat and spreads privacy risk:
- Session memory: valid only for the current lesson and reclaimed when the session ends.
- Course memory: stores the syllabus, covered knowledge points, mistakes, and mastery scores.
- Profile memory: stores preferences, weak areas, and common phrasing habits across courses, and must support one-click deletion and export.
The core benefit of local deployment is that data never leaves your domain. Document parsing, index construction, vector storage, logging, and monitoring alerts can all run in your own environment; object storage holds raw material and course artifacts, a message queue decouples time-consuming parsing tasks, and a container platform handles elastic scaling for compute-intensive parsing and indexing. If calling external model capabilities is truly necessary, transmit only the minimal required fragments and keep a fully offline fallback path in the architecture.
Three security boundaries also matter: first, isolate access between the index and the original files so lecture notes cannot leak unauthorized content; second, generated content must carry citation backlinks for human verification; third, all deletion and export operations must be logged to meet traceability requirements.
6. Practical Advice and Common Pitfalls
- Pitfall 1: chasing a “big and complete” knowledge base. A more effective approach is a small, focused topic library per course goal; the tighter the topic, the higher the quality of explanations and exercises.
- Pitfall 2: treating a summary as a lesson. A summary compresses information while a lesson rebuilds a path, and the two cannot replace each other.
- Pitfall 3: neglecting evaluation. Maintain a set of questions with reference answers and run regression tests periodically on the combined effect of parsing, retrieval, and generation.
- Implementation order: first get single-role Q&A working end to end, then add retrieval and citations, then add exercises and mistake write-back, and only then extend to multi-role debate. Introducing complex orchestration too early makes problems hard to locate.
7. Conclusion
Turning long-term documents into interactive lessons is essentially systems engineering that combines structured parsing, multi-role orchestration, and layered memory, not a one-off model call. Build it up layer by layer as described, and use traceable citations, closed-loop exercises, and clearable memory as acceptance criteria, and you can build stable, controllable, and reusable private teaching capability in your own environment.
