# 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 ```bash # 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 # 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//` with: ``` manifest.yaml # name, version, type, description, stages capability.py # class extending BaseCapability ``` Minimal `manifest.yaml`: ```yaml name: my_plugin version: 0.1.0 type: playground description: "My custom plugin" stages: [step1, step2] ``` Minimal `capability.py`: ```python 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 ```