Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

docs: sync AGENTS runtime architecture

lilzee14d00f06d0f0
diff --git a/AGENTS.md b/AGENTS.md
index 95a57c424..1bdb97f3f 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -5,7 +5,9 @@
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.
+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
@@ -13,7 +15,12 @@ through three entry points: CLI, WebSocket API, and Python SDK.
Entry Points: CLI (Typer) | WebSocket /ws | Python SDK
↓ ↓ ↓
┌─────────────────────────────────────────────────┐
- │ ChatOrchestrator │
+ │ TurnApplicationService │
+ │ persists, coordinates, and replays turns │
+ └──────────────────────┬──────────────────────────┘
+ ↓
+ ┌─────────────────────────────────────────────────┐
+ │ TurnEngine → ChatOrchestrator │
│ routes UnifiedContext → selected Capability │
│ (defaults to `chat`) │
└──────────┬──────────────┬───────────────────────┘
@@ -24,32 +31,36 @@ Entry Points: CLI (Typer) | WebSocket /ws | Python SDK
└──────────────┘ └────────────────────┘
```
-All capabilities emit on a shared `StreamBus`; the orchestrator fans
-events out to consumers. Runtime settings live in
+`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. Four user-toggleable 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 |
-
-The rest are **context-gated**: the chat capability auto-mounts them from
-`ToolMountFlags` (presence of a KB, attachments, sandbox availability, …), and
-any of them can also be force-enabled via `--tool`. Auto-mounted set: `rag`,
-`read_source`, `read_memory`, `write_memory`, `read_skill`, `load_tools`,
-`exec` (sandboxed Python/C/C++ or shell execution),
-`list_notebook`, `write_note`, `web_fetch`, `github`, `cron`,
-`ask_user` (pauses the turn and resumes with the user's reply), plus the
-mastery-path tools. `geogebra_analysis` is parked under
-`COMING_SOON_TOOL_TYPES`.
+| 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
@@ -58,12 +69,16 @@ Multi-stage pipelines that own the turn:
| Capability | Stages |
| ---------------- | ----------------------------------------------------- |
| `chat` | exploring → responding (single agentic loop, default) |
-| `mastery_path` | responding (Guided Learning — chat loop + mastery tools, gated per topic type) |
-| `deep_solve` | planning → reasoning → writing |
+| `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-grounded reading loop) |
+| `course_study` | responding (course-state sensing and hand-off loop) |
+| `immersive_watching` | responding (timestamp-grounded video loop) |
All capabilities converge on `emit_capability_result()` in
`deeptutor/capabilities/_shared.py` so every turn emits the same envelope
@@ -106,9 +121,9 @@ deeptutor start # backend + frontend together
| `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/core/stream.py`, `stream_bus.py` | StreamEvent protocol + async fan-out |
+| `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` | `BaseCapability` + `CapabilityManifest` |
+| `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 |