mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-04 00:31:28 +08:00
Rebased onto dev (post-#348) and resolved two UI conflicts (`web/app/(workspace)/chat/[[...sessionId]]/page.tsx` drops the now-dead `replaySnapshot` helper; `web/components/chat/home/ChatMessages.tsx` switches the last-assistant action button from the old `RotateCcw`/Retry to `RefreshCcw`/Regenerate). Smoke tests green (199 passed) and all required checks pass. Merging: adds a `regenerate` capability wired through CLI (`/regenerate` · `/retry`), WebSocket (`type: "regenerate"`), and Web UI (per-message Regenerate button). Backend rolls back the trailing assistant via `SQLiteSessionStore.delete_message`, reuses `start_turn` through `_persist_user_message=False` / `_regenerate=True`, skips `memory_service.refresh_from_turn` on regeneration, and surfaces non-fatal `regenerate_busy` / `nothing_to_regenerate` errors. Also includes empty-response diagnostics in `_stage_responding`. 18 new tests.
6.1 KiB
6.1 KiB
DeepTutor — Agent-Native Architecture
Overview
DeepTutor is an agent-native intelligent learning companion built around a two-layer plugin model (Tools + Capabilities) with three entry points: CLI, WebSocket API, and Python SDK.
Architecture
Entry Points: CLI (Typer) | WebSocket /api/v1/ws | Python SDK
↓ ↓ ↓
┌─────────────────────────────────────────────────┐
│ ChatOrchestrator │
│ routes to ChatCapability (default) │
│ or a selected deep Capability │
└──────────┬──────────────┬───────────────────────┘
│ │
┌──────────▼──┐ ┌────────▼──────────┐
│ ToolRegistry │ │ CapabilityRegistry │
│ (Level 1) │ │ (Level 2) │
└──────────────┘ └────────────────────┘
Level 1 — Tools
Lightweight single-function tools the LLM calls on demand:
| Tool | Description |
|---|---|
rag |
Knowledge base retrieval (RAG) |
web_search |
Web search with citations |
code_execution |
Sandboxed Python execution |
reason |
Dedicated deep-reasoning LLM call |
brainstorm |
Breadth-first idea exploration with rationale |
paper_search |
arXiv academic paper search |
geogebra_analysis |
Image → GeoGebra commands (4-stage vision pipeline) |
Level 2 — Capabilities
Multi-step agent pipelines that take over the conversation:
| Capability | Stages |
|---|---|
chat |
responding (default, tool-augmented) |
deep_solve |
planning → reasoning → writing |
deep_question |
ideation → evaluation → generation → validation |
Playground Plugins
Extended features in deeptutor/plugins/:
| Plugin | Type | Description |
|---|---|---|
deep_research |
playground | Multi-agent research + reporting |
CLI Usage
# Install CLI
pip install -r requirements/cli.txt && pip install -e .
# Run any capability (agent-first entry point)
deeptutor run chat "Explain Fourier transform"
deeptutor run deep_solve "Solve x^2=4" -t rag --kb my-kb
deeptutor run deep_question "Linear algebra" --config num_questions=5
# Interactive REPL
deeptutor chat
# (inside the REPL: /regenerate or /retry re-runs the last user message)
# Knowledge bases
deeptutor kb list
deeptutor kb create my-kb --doc textbook.pdf
# Plugins & memory
deeptutor plugin list
deeptutor memory show
# API server (requires server.txt)
deeptutor serve --port 8001
Key Files
| Path | Purpose |
|---|---|
deeptutor/runtime/orchestrator.py |
ChatOrchestrator — unified entry |
deeptutor/core/stream.py |
StreamEvent protocol |
deeptutor/core/stream_bus.py |
Async event fan-out |
deeptutor/core/tool_protocol.py |
BaseTool abstract class |
deeptutor/core/capability_protocol.py |
BaseCapability abstract class |
deeptutor/core/context.py |
UnifiedContext dataclass |
deeptutor/runtime/registry/tool_registry.py |
Tool discovery & registration |
deeptutor/runtime/registry/capability_registry.py |
Capability discovery & registration |
deeptutor/runtime/mode.py |
RunMode (CLI vs SERVER) |
deeptutor/capabilities/ |
Built-in capability wrappers |
deeptutor/tools/builtin/ |
Built-in tool wrappers |
deeptutor/plugins/ |
Playground plugins |
deeptutor/plugins/loader.py |
Plugin discovery from manifest.yaml |
deeptutor_cli/main.py |
Typer CLI entry point |
deeptutor/api/routers/unified_ws.py |
Unified WebSocket endpoint |
Plugin Development
Create a directory under deeptutor/plugins/<name>/ with:
manifest.yaml # name, version, type, description, stages
capability.py # class extending BaseCapability
Minimal manifest.yaml:
name: my_plugin
version: 0.1.0
type: playground
description: "My custom plugin"
stages: [step1, step2]
Minimal capability.py:
from deeptutor.core.capability_protocol import BaseCapability, CapabilityManifest
from deeptutor.core.context import UnifiedContext
from deeptutor.core.stream_bus import StreamBus
class MyPlugin(BaseCapability):
manifest = CapabilityManifest(
name="my_plugin",
description="My custom plugin",
stages=["step1", "step2"],
)
async def run(self, context: UnifiedContext, stream: StreamBus) -> None:
async with stream.stage("step1", source=self.name):
await stream.content("Working on step 1...", source=self.name)
await stream.result({"response": "Done!"}, source=self.name)
Dependency Layers
requirements/cli.txt — CLI full (LLM + RAG + providers + tools)
requirements/server.txt — CLI + FastAPI/uvicorn (for Web/API)
requirements/math-animator.txt — Manim addon (for `deeptutor animate`)
requirements/dev.txt — Server + test/lint tools