DeepTutor: Lifelong Personalized Tutoring.
# DeepTutor โ Agent-Native Architecture
## Overview
DeepTutor is an **agent-native** intelligent learning companion organized
around a two-layer plugin model โ single-shot **Tools** invoked by the
LLM, and multi-stage **Capabilities** that take over a turn โ exposed
through three entry points: CLI, WebSocket API, and Python SDK. All three
enter the durable turn application service before the shared turn engine
routes a normalized context to the selected capability.
## Architecture
```
Entry Points: CLI (Typer) | WebSocket /ws | Python SDK
โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ TurnApplicationService โ
โ persists, coordinates, and replays turns โ
โโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ TurnEngine โ ChatOrchestrator โ
โ routes UnifiedContext โ selected Capability โ
โ (defaults to `chat`) โ
โโโโโโโโโโโโฌโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
โโโโโโโโโโโโผโโโ โโโโโโโโโโผโโโโโโโโโโโ
โ ToolRegistry โ โ CapabilityRegistry โ
โ (Level 1) โ โ (Level 2) โ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโ
```
`TurnApplicationService` owns durable turn state and replay through the
session store and runtime coordinator. Each execution uses a per-turn
`StreamBus`; the orchestrator emits events, the turn runtime persists them,
and adapters replay them to consumers. Runtime settings live in
`data/user/settings/*.json` โ project-root `.env` files are intentionally
ignored.
### Level 1 โ Tools
Single-function tools the LLM picks on demand. Seven user-toggleable tools
surface in `/settings/tools`:
| Tool | Description |
| -------------------- | --------------------------------------------- |
| `brainstorm` | Breadth-first idea exploration with rationale |
| `web_search` | Web search with citations |
| `paper_search` | arXiv preprint search |
| `reason` | Dedicated deep-reasoning LLM call |
| `geogebra_analysis` | Analyze math images into GeoGebra commands |
| `imagegen` | Generate images |
| `videogen` | Generate videos |
`USER_TOGGLEABLE_TOOL_NAMES` in `deeptutor/tools/builtin/__init__.py` is the
authoritative toggle list. Other built-ins are **context-gated** or
capability-owned: `CONFIGURABLE_BUILTIN_TOOL_NAMES` declares the context-gated
surface, while `deeptutor/agents/_shared/tool_composition.py` owns the mount
rules (`ToolMountFlags`) and the always-available workspace tools. Examples
include `rag`, memory and notebook tools, `read_skill`, deferred MCP/CLI tools,
`exec`, `ask_user`, and mastery navigation. `--tool` selects from the
user-toggleable whitelist; it does not bypass context or capability gates.
### Level 2 โ Capabilities
Multi-stage pipelines that own the turn:
| Capability | Stages |
| ---------------- | ----------------------------------------------------- |
| `chat` | exploring โ responding (single agentic loop, default) |
| `ask_questions` | responding (chat loop forced through `ask_user`) |
| `deep_solve` | responding (chat loop + solve planning tools) |
| `deep_question` | ideation โ generation |
| `deep_research` | rephrasing โ decomposing โ researching โ reporting |
| `visualize` | analyzing โ generating โ reviewing (SVG / Chart.js / Mermaid / HTML; or routes to Manim sub-stages via `render_type`) |
| `math_animator` | concept_analysis โ concept_design โ code_generation โ code_retry โ summary โ render_output |
| `mastery_path` | responding (Guided Learning โ chat loop + mastery tools, gated per topic type) |
| `immersive_reading` | responding (document- or timestamp-grounded media reading loop) |
| `course_study` | responding (course-state sensing and hand-off loop) |
All capabilities converge on `emit_capability_result()` in
`deeptutor/capabilities/_shared.py` so every turn emits the same envelope
(response payload + `cost_summary` from `UsageTracker`). Status copy and
prompts are i18n'd via `capabilities/prompts/{en,zh}/<name>.yaml`.
## CLI Usage
```bash
# Install
pip install deeptutor # Full app (CLI + Web/API + packaged Web assets)
pip install deeptutor-cli # CLI-only
# Run any capability
deeptutor run chat "Explain Fourier transform"
deeptutor run deep_solve "Solve x^2=4" -t rag --kb my-kb
deeptutor run visualize "Animate sine wave" --config render_mode=manim_video
# Interactive REPL
deeptutor chat
# (inside the REPL: /regenerate or /retry re-runs the last user message)
# Partners (IM-connected companions)
deeptutor partner list
# Knowledge bases, memory, server
deeptutor kb list
deeptutor kb create my-kb --doc textbook.pdf
deeptutor memory show
deeptutor serve --port 8001 # API server only
deeptutor start # backend + frontend together
```
## Key Files
| Path | Purpose |
| ------------------------------------------ | ------------------------------------ |
| `deeptutor/runtime/orchestrator.py` | `ChatOrchestrator` โ unified entry |
| `deeptutor/runtime/launcher.py` | Backend + frontend lifecycle / port discovery |
| `deeptutor/runtime/registry/` | Tool + Capability registries |
| `deeptutor/runtime/bootstrap/builtin_capabilities.py` | Built-in capability class paths |
| `deeptutor/services/config/runtime_settings.py` | JSON settings + process-env overrides |
| `deeptutor/services/subagent/` | Local/remote agent connectors; register each backend in `registry.py` and its model options in `models.py` (Grok CLI uses native `streaming-json`) |
| `deeptutor/core/stream.py`, `deeptutor/runtime/stream_bus.py` | StreamEvent protocol + async fan-out |
| `deeptutor/core/tool_protocol.py` | `BaseTool` + `ToolDefinition` |
| `deeptutor/core/capability_protocol.py` | `TurnCapability` + `CapabilityManifest` |
| `deeptutor/core/context.py` | `UnifiedContext` dataclass |
| `deeptutor/tools/builtin/__init__.py` | All built-in tool wrappers |
| `deeptutor/capabilities/` | Built-in capability implementations |
| `deeptutor/app.py` | `DeepTutorApp` โ Python SDK facade |
| `deeptutor_cli/main.py` | Typer CLI entry point |
| `deeptutor/api/routers/unified_ws.py` | Unified WebSocket endpoint |
## Dependency Layers
Public install paths and source extras are defined in `pyproject.toml`.
Requirements files mirror the same dependency groups for Docker/CI installs.
```
pip install deeptutor โ Full app (CLI + Web/API + packaged Web assets)
pip install deeptutor-cli โ CLI-only (LLM + RAG + providers + document parsing)
pip install -e . โ Source install for development
Source extras (.[ extra ], defined in pyproject.toml):
.[cli] โ CLI-only dependency set
.[server] โ Web/API server dependencies
.[partners] โ Partner channel SDKs (legacy alias: .[tutorbot])
.[matrix] โ Matrix channel for Partners (matrix-nio; needs libolm)
.[matrix-e2e] โ Matrix with end-to-end encryption (matrix-nio[e2e])
.[math-animator] โ Manim addon (powers `visualize` Manim renders + `deeptutor run math_animator`)
.[dev] โ Test / lint tooling
.[all] โ Everything above
```