AI Agent Book Structure: A Comprehensive 10-Chapter Architecture Guide
The AI Agent book structure follows a ten-chapter narrative built around the central equation Agent = LLM + Context + Tools, progressing from theoretical foundations to advanced multi-agent systems, with each chapter supported by runnable code experiments in dedicated repository directories.
The bojieli/ai-agent-book repository organizes its educational content as a progressive curriculum that teaches AI Agent development through the lens of Agent = LLM + Context + Tools. This architecture-first approach ensures readers understand not just isolated techniques, but how components integrate into production-ready systems backed by Harness and Loop engineering.
Core Architecture Philosophy
The Foundational Equation
Every chapter in the AI Agent book structure revolves around the equation Agent = LLM + Context + Tools. This framework treats the LLM as the "brain," Context as the "eyes" that perceive the environment, and Tools as the "hands" that interact with external systems. The book systematically unpacks each component before demonstrating how they combine into cohesive agent architectures.
Harness and Loop Engineering
Beyond the core triad, the book introduces two critical engineering disciplines. Harness engineering focuses on constraints, verification mechanisms, and correction strategies that keep agents reliable and safe. Loop engineering enables continuous self-improvement through trajectory logging, prompt distillation, and artifact generation, allowing agents to evolve from execution traces.
Chapter-by-Chapter Breakdown
The book's narrative arc moves from basic concepts to multi-agent societies, with each chapter mapped to specific directories in the repository.
Chapter 1: Agent Basics and the ReAct Loop
The foundation introduces the core formula and the ReAct (Reasoning-Acting) loop, establishing how LLMs alternate between internal reasoning and external tool execution. Key concepts include treating the LLM as the agent's cognitive engine and understanding the observation-reasoning-action cycle. Implementation examples reside in [chapter1/README.md](https://github.com/bojieli/ai-agent-book/blob/main/chapter1/README.md).
Chapter 2: Context Engineering
This section details how to feed the right information to the LLM through system prompts, tool definitions, user messages, and tool results. The chapter emphasizes that context quality directly determines agent capability, covering prompt construction strategies found in [chapter2/README.md](https://github.com/bojieli/ai-agent-book/blob/main/chapter2/README.md).
Chapter 3: User Memory and Knowledge Bases
Focusing on persistence, this chapter explores retrieval-augmented generation (RAG) and long-term memory systems. Readers learn to implement user-memory stores, vector databases, and knowledge graphs that allow agents to maintain state across sessions. Code experiments are located in [chapter3/README.md](https://github.com/bojieli/ai-agent-book/blob/main/chapter3/README.md).
Chapter 4: Tools and the MCP Protocol
The book categorizes tools into five families: perception, execution, collaboration, event-trigger, and user-communication. This chapter introduces the MCP protocol, tool schemas, and safety constraints, with seven accompanying projects in [chapter4/README.md](https://github.com/bojieli/ai-agent-book/blob/main/chapter4/README.md) and tool definitions in [chapter4/tool_schema.json](https://github.com/bojieli/ai-agent-book/blob/main/chapter4/tool_schema.json).
Chapter 5: Coding Agents and Code Generation
Treating code as "tools that create tools," this chapter covers code interpreters, sandbox execution, and prompt-driven coding. It demonstrates how agents can write, execute, and debug their own software, with experiments detailed in [chapter5/README.md](https://github.com/bojieli/ai-agent-book/blob/main/chapter5/README.md).
Chapter 6: Agent Evaluation and Benchmarking
Systematic evaluation frameworks including metrics design, statistical significance testing, and benchmark suites are covered here. The chapter provides eleven experiments focused on evaluation environments and GA-based metrics for reproducible agent assessment, found in [chapter6/README.md](https://github.com/bojieli/ai-agent-book/blob/main/chapter6/README.md).
Chapter 7: Model Post-Training
This technical deep-dive compares Supervised Fine-Tuning (SFT) versus Reinforcement Learning (RL) for agent optimization. It covers tool-call internalization and data pipeline construction, showing how to specialize base models for agent tasks. Resources are in [chapter7/README.md](https://github.com/bojieli/ai-agent-book/blob/main/chapter7/README.md).
Chapter 8: Continuous Evolution and Learning
Addressing Loop engineering in practice, this chapter explains trajectory logging, prompt distillation, and strategies for updating artifacts or model weights based on execution traces. The implementation guide resides in [chapter8/README.md](https://github.com/bojieli/ai-agent-book/blob/main/chapter8/README.md).
Chapter 9: Multimodal and Real-Time Interaction
Expanding beyond text, this chapter covers voice interfaces, GUI automation, robotics, and computer-use scenarios. It integrates speech-to-text, visual perception, and robot control loops, with examples in [chapter9/README.md](https://github.com/bojieli/ai-agent-book/blob/main/chapter9/README.md).
Chapter 10: Multi-Agent Collaboration
The final technical chapter explores emergent societies of agents, covering context sharing and isolation, coordination protocols, and the TalkAct framework. It discusses swarm-style coordination and agent-society patterns implemented in [chapter10/README.md](https://github.com/bojieli/ai-agent-book/blob/main/chapter10/README.md).
Afterword: Model-as-Agent and Future Directions
The concluding section in [book/afterword.md](https://github.com/bojieli/ai-agent-book/blob/main/book/afterword.md) reflects on the model-vs-harness trade-offs and presents a long-term roadmap for the field.
Repository Organization and Build System
The AI Agent book structure extends beyond markdown chapters into a complete publishing pipeline. The chapter table in the main README (lines 48-61 of [README.md](https://github.com/bojieli/ai-agent-book/blob/main/README.md)) provides a navigational overview and quantifies the accompanying experiments per chapter.
Build Automation and Figure Generation
The repository includes production scripts that link theory to reproducible artifacts:
- PDF/EPUB generation: [
book/build_pdf.sh](https://github.com/bojieli/ai-agent-book/blob/main/book/build_pdf.sh) automates the compilation of markdown sources into polished document formats - Figure utilities:
book/gen_*_figs.pyscripts generate diagrams and visualizations programmatically - Analytics: [
scripts/gen_star_history.py](https://github.com/bojieli/ai-agent-book/blob/main/scripts/gen_star_history.py) produces repository statistics for documentation badges
Source Text Locations
Core narrative content lives in book/chapter*.md files, while runnable experiments and chapter-specific documentation are housed in parallel chapter*/ directories. This separation maintains a clean distinction between theoretical exposition and executable code.
Hands-On Implementation Examples
The following examples demonstrate the architectural patterns described in the book's early and middle chapters.
ReAct Loop Implementation (Chapter 1)
This Python-style pseudo-code illustrates the fundamental reasoning-acting cycle, showing how an agent iterates between LLM inference and tool execution:
trajectory = [
{"role": "user", "content": "Convert 250 EUR and 300 GBP to USD and sum them."}
]
# 1️⃣ Reason → decide which tools to call
assistant = llm.call(
system_prompt=SYSTEM_PROMPT,
tools=[{"name": "convert_currency", "parameters": {"amount": "float", "from": "string", "to": "string"}}],
messages=trajectory,
)
# assistant returns tool_calls:
# [{name: "convert_currency", args: {amount: 250, from: "EUR", to: "USD"}},
# {name: "convert_currency", args: {amount: 300, from: "GBP", to: "USD"}}]
# 2️⃣ Execute tools and append results
for call in assistant["tool_calls"]:
result = convert_currency(**call["args"])
trajectory.append({"role": "tool", "content": result})
# 3️⃣ Run LLM again with the enriched trajectory
assistant = llm.call(system_prompt=SYSTEM_PROMPT, messages=trajectory)
print(assistant["content"]) # → "TOTAL = $???"
The actual convert_currency implementation referenced here resides in [chapter4/tools/convert_currency.py](https://github.com/bojieli/ai-agent-book/blob/main/chapter4/tools/convert_currency.py).
Tool Schema Definition (Chapter 4)
Tools must be declared in the static context so the LLM can discover and invoke them correctly. This JSON schema example shows the structured definition required:
{
"name": "convert_currency",
"description": "Convert an amount from one currency to another using up-to-date exchange rates.",
"parameters": {
"type": "object",
"properties": {
"amount": {"type": "number", "description": "The numeric amount to convert."},
"from": {"type": "string", "description": "Source currency code, e.g. \"EUR\"."},
"to": {"type": "string", "description": "Target currency code, e.g. \"USD\"."}
},
"required": ["amount", "from", "to"]
}
}
This schema is stored in [chapter4/tool_schema.json](https://github.com/bojieli/ai-agent-book/blob/main/chapter4/tool_schema.json) and loaded by the harness before each LLM invocation.
Summary
- The AI Agent book structure organizes content into ten progressive chapters built around the Agent = LLM + Context + Tools equation.
- Each chapter from 1 through 10 maps to specific README files in dedicated repository directories (e.g., [
chapter1/README.md](https://github.com/bojieli/ai-agent-book/blob/main/chapter1/README.md) through [chapter10/README.md](https://github.com/bojieli/ai-agent-book/blob/main/chapter10/README.md)). - The architecture emphasizes Harness engineering (safety and verification) and Loop engineering (continuous improvement) as essential complements to core agent components.
- The repository provides a complete build pipeline via [
book/build_pdf.sh](https://github.com/bojieli/ai-agent-book/blob/main/book/build_pdf.sh) and figure generation scripts that ensure reproducible documentation. - Practical implementations demonstrate ReAct reasoning loops and MCP-compliant tool definitions that readers can execute directly from the source files.
Frequently Asked Questions
How does the AI Agent book structure progress from beginner to advanced topics?
The book follows a cognitive-to-social progression. Chapters 1-3 establish the mental model and context engineering fundamentals. Chapters 4-6 implement concrete tools and evaluation frameworks. Chapters 7-10 advance into model fine-tuning, autonomous evolution, multimodal interaction, and finally multi-agent societies, ensuring each layer builds upon the previous infrastructure.
Where are the runnable code examples located in the repository?
Each chapter's experiments reside in corresponding directories (e.g., chapter4/ for tool implementations). The main chapter narratives live in book/chapter*.md files, while executable scripts and tool schemas (like [chapter4/tool_schema.json](https://github.com/bojieli/ai-agent-book/blob/main/chapter4/tool_schema.json)) are stored alongside their documentation in the chapter directories.
What is the difference between Harness engineering and Loop engineering in the book's framework?
Harness engineering focuses on static constraints—safety checks, tool validation, and error correction mechanisms that bound agent behavior. Loop engineering handles dynamic improvement—logging execution trajectories, distilling successful prompts, and updating model weights or artifacts to create self-improving systems that learn from operational data.
How is the book compiled into PDF or EPUB formats?
The repository includes automated build scripts, specifically [book/build_pdf.sh](https://github.com/bojieli/ai-agent-book/blob/main/book/build_pdf.sh), which processes the markdown chapters and figure generation utilities (book/gen_*_figs.py) to produce publication-ready formats. This ensures that all diagrams and code examples remain synchronized with the text.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →