Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Agent Book Engine Harness

Python FastAPI License Book

💡 A Python harness demonstrating how to leverage Bojie Li's open-source book repo (bojieli/ai-agent-book) into production AI applications.


⚙️ Core Architecture & Concept

Every AI Agent is built on one core equation:

$$\Large\text{Agent} = \text{LLM} + \text{Context} + \text{Tools}$$

 ┌─────────────────────────────────────────────────────────────┐
 │                 DEEPAGENT ENGINE HARNESS                    │
 │                                                             │
 │  ┌─────────────────┐  ┌────────────────┐  ┌──────────────┐  │
 │  │ 🤖 AgentEngine  │  │ ⚡ ContextMgr  │  │ 🧠 Memory    │  │
 │  │ ReAct Tool Loop │  │ KV Cache Order │  │ RAM + RAG    │  │
 │  └────────┬────────┘  └───────┬────────┘  └──────┬───────┘  │
 │           │                   │                  │          │
 │           └───────────────────┼──────────────────┘          │
 │                               │                             │
 │                  ┌────────────▼───────────┐                 │
 │                  │ 🛡️ Proposer-Reviewer   │                 │
 │                  │ Two-Stage Safety Loop  │                 │
 │                  └────────────────────────┘                 │
 └─────────────────────────────────────────────────────────────┘

🛠️ Tech Stack

  • 🐍 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)

📁 File Structure

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

🚀 Quick Start (Windows PowerShell)

1. Fetch Official Bojie Li Repository

git clone --depth 1 https://github.com/bojieli/ai-agent-book.git official_repo

2. Install Dependencies

pip install fastapi uvicorn jinja2

3. Launch Web Application

python app.py

Open your browser at http://localhost:8000.

4. Test REST API Endpoint

Invoke-RestMethod -Uri "http://localhost:8000/api/chat" -Method Post -ContentType "application/json" -Body '{"query": "Use Grep to search code"}'

📚 How Beginners Can Use the AI Agent Book Repo

  1. Import Pure-Python Tools: Import 16 dependency-free tools (GrepTool, ReadTool, EditTool) directly from official_repo/chapter5/coding-agent.
  2. 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).
  3. Prevent Context Loss: Use Anthropic-style prefix summaries on text chunks (DualMemorySystem).
  4. Enforce Safety Audits: Decouple tool generation from safety validation via a Proposer-Reviewer pair (ProposerReviewerLoop).

💡 5 Key Use Cases

  • 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.md on every interaction.

🔮 5 Future Features

  • 🔌 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.

📜 License

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

About

Multi-Agent AI Book Dropped on Github: Here’s How to Build It Locally - An interactive FastAPI harness implementing KV-Cache, Proposer-Reviewer, and Contextual RAG from Bojie Li's AI Agents in Depth.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages