bojieli/ai-agent-book

《深入理解 AI Agent:设计原理与工程实践》(李博杰 著)开源主仓库:全书正文、编译版 PDF 与按章配套代码

📚 What is AI‑Agents‑in‑Depth?

A free, open‑source textbook that walks readers from the fundamentals of AI agents to production‑grade engineering. The book is built around the simple formula Agent = LLM + Context + Tools and is split into ten chapters covering:

Chapter Core topic
1 Agent basics and why engineering matters
2 Context engineering (prompting, KV‑cache, compression)
3 User memory & Retrieval‑Augmented Generation
4 Tool use (perception, execution, collaboration, async)
5 Coding agents and general‑purpose agents
6 Expanding observation/action spaces (voice, computer use, robotics)
7 Evaluation methods and metrics
8 Post‑training (SFT, RL) for agents
9 Continuous evolution from runtime traces
10 Multi‑agent collaboration

Each chapter ships one or more runnable experiments (95 in total) that demonstrate the concepts with real code.


📖 How to read

  • Offline – download the PDF or EPUB (the latest build is always in the Releases page). The PDF is generated with Pandoc + XeLaTeX and the ElegantBook class for a clean layout.
  • Online – the site https://bojieli.github.io/ai-agent-book/ lets you switch between 13 languages, collapse sections, and search the full text. Every push to main automatically rebuilds the site.
  • Source – the Chinese source lives in book/; translations live in book‑en/, book‑es/, … etc.

💻 Running the companion code

The repository contains a Python‑only experiment suite (Python 3.11‑3.13). Install a chapter’s dependencies with the modern package manager uv:

# install chapter 1 (replace ch1 with ch2 … ch10 as needed)
uv sync --locked --extra ch1
# or with pip if you prefer
python -m pip install -e "[ch1]"

Experiments are launched from the repository root, e.g.:

uv run python chapter1/context/main.py
# or simply: python chapter1/context/main.py

Most experiments need an LLM API key. Create a .env from .env.example and add a key for any of the supported providers (Kimi, GLM, Siliconflow, DeepSeek, Krill AI, OpenRouter, …). When an experiment explicitly mentions --provider ollama, you can run a local Ollama server.


🛠️ What’s inside the code?

  • Ready‑to‑run notebooks / scripts for context compression, RAG pipelines, tool‑calling protocols, async agents, coding assistants, robot simulators, evaluation harnesses, and more.
  • Extra repositories – the book references 22 external projects (e.g., Claude quickstarts, browser‑use, XLeRobot, GAIA benchmark). A one‑click script in the README clones them at fixed commits, so you can reproduce the experiments without hunting down versions.
  • Training helpers – lightweight forks of MiniMind, AdaptThink, SFTvsRL, etc., used in Chapter 8 to illustrate fine‑tuning and RL‑from‑human‑feedback for agents.

🎯 Who should use this?

  • Students & self‑learners who want a structured, hands‑on path from theory to practice.
  • Engineers building production agents who need concrete guidance on context management, tool integration, evaluation, and continuous improvement.
  • Researchers looking for a curated set of reproducible experiments and benchmark links.

📦 Quick start checklist

  1. Clone the repo.
  2. Install uv (or use pip).
  3. Pick a chapter and run uv sync --locked --extra chX.
  4. Add an API key in .env (or set OPENAI_API_KEY, KIMI_API_KEY, etc.).
  5. Run the example script for that chapter.
  6. Read the accompanying markdown (book/chapterX.md) to understand the design decisions.

📜 License

The book and all original code are released under the Apache License 2.0. Individual external projects keep their own licenses, which are noted in each sub‑directory.


🙏 Contributing

The project welcomes:

  • Corrections or expansions to the text.
  • Bug fixes or usability improvements to the experiments.
  • New practical projects that illustrate a concept.
  • Translations into additional languages.

Before submitting a PR, run the relevant experiment(s) to ensure reproducibility.


Bottom line: AI‑Agents‑in‑Depth is a fully‑fledged, multilingual textbook paired with a rich set of open‑source experiments, making it a practical learning platform for anyone interested in modern LLM‑powered agents.

Related

  • Project
  • Project
  • Project
  • Project
  • Project