💡 A Python harness demonstrating how to leverage Bojie Li's open-source book repo (
bojieli/ai-agent-book) into production AI applications.
Every AI Agent is built on one core equation:
┌─────────────────────────────────────────────────────────────┐
│ DEEPAGENT ENGINE HARNESS │
│ │
│ ┌─────────────────┐ ┌────────────────┐ ┌──────────────┐ │
│ │ 🤖 AgentEngine │ │ ⚡ ContextMgr │ │ 🧠 Memory │ │
│ │ ReAct Tool Loop │ │ KV Cache Order │ │ RAM + RAG │ │
│ └────────┬────────┘ └───────┬────────┘ └──────┬───────┘ │
│ │ │ │ │
│ └───────────────────┼──────────────────┘ │
│ │ │
│ ┌────────────▼───────────┐ │
│ │ 🛡️ Proposer-Reviewer │ │
│ │ Two-Stage Safety Loop │ │
│ └────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
- 🐍 Backend: Python 3.9+, FastAPI, Uvicorn
- 🎨 Frontend: HTML5 Jinja2 Templates, Modern Dark Glassmorphic CSS3
- 🛠️ Tools: Bojie Li's 16 Pure-Python Tools (
Grep,Read,Write,Edit,LS,Glob,Bash,TodoWrite)
AI Agent Book/
├── official_repo/ # Cloned Bojie Li repository (10 chapters of runnable code)
├── agent_core.py # Core Engine (~130 lines: AgentEngine, ContextManager, DualMemory)
├── app.py # FastAPI Web Server (~40 lines: REST endpoints & Jinja2 UI)
├── templates/
│ └── index.html # Jinja2 Dashboard UI with ReAct trace drawer
├── static/
│ ├── style.css # Dark Glassmorphism Design System
│ └── main.js # Client REST Fetch & Dynamic Rendering
├── output.md # Automatically generated turn execution report
└── README.md # Visual Project Documentation
git clone --depth 1 https://github.com/bojieli/ai-agent-book.git official_repopip install fastapi uvicorn jinja2python app.pyOpen your browser at http://localhost:8000.
Invoke-RestMethod -Uri "http://localhost:8000/api/chat" -Method Post -ContentType "application/json" -Body '{"query": "Use Grep to search code"}'- Import Pure-Python Tools: Import 16 dependency-free tools (
GrepTool,ReadTool,EditTool) directly fromofficial_repo/chapter5/coding-agent. - Optimize KV-Cache: Place static system instructions and tool schemas first in the prompt stack to save 40–60% Time-To-First-Token (TTFT) latency (
ContextManager). - Prevent Context Loss: Use Anthropic-style prefix summaries on text chunks (
DualMemorySystem). - Enforce Safety Audits: Decouple tool generation from safety validation via a Proposer-Reviewer pair (
ProposerReviewerLoop).
- ⚡ KV-Cache Optimization: Measure latency gains by ordering prompt components.
- 🔍 Contextual RAG Search: Retrieve knowledge chunks pre-augmented with document summaries.
- 🛡️ Two-Stage Safety Audits: Intercept dangerous commands or unsafe dynamic code execution.
- 🛠️ Pure-Python Code Agent: Run file system operations without external shell dependencies.
- 📊 Automated Execution Reports: Auto-export turn traces to
output.mdon every interaction.
- 🔌 MCP Server Adapter: Connect to external Model Context Protocol tool servers.
- 🗣️ Real-Time Voice Streaming: Integrate Chapter 9 VAD + TTS audio streaming.
- 🤝 Multi-Agent Swarms: Implement Chapter 10 role handoffs and collaboration.
- 📈 ELO Terminal Benchmark: Evaluate agent coding performance on benchmark tasks.
- 💾 Persisted Memory Store: SQLite persistence for user fact cards across restarts.
Released under Apache 2.0 License. Powered by Bojie Li's AI Agents in Depth.
Tags:
Multi-Agent AI, AI Agents in Depth, Bojie Li, FastAPI, Ollama, Python, AgentEngine, KV-Cache, Contextual RAG, LLM Context