How to Fork and Modify the AI Agent Book for Custom Research and Teaching
To fork and modify the AI agent book, clone the repository from bojieli/ai-agent-book, customize the SystemHintAgent in chapter2/system-hint/agent.py, add new chapters to the book/ directory, and rebuild the PDF using book/build_pdf.sh.
The AI Agents in Depth repository is an open-source technical book bundled with runnable experiments, allowing you to fork and modify the AI agent book for your own curriculum, research, or product development. Each chapter combines markdown source files in book/ with standalone experiment packages in chapter*/ directories that demonstrate the concepts in practice. The modular architecture lets you extend the core SystemHintAgent framework or add entirely new chapters without disrupting existing content.
Forking and Local Setup
Begin by creating your own copy of the repository and preparing the build environment.
-
Fork the repository on GitHub to create
https://github.com/<your-user>/ai-agent-book. -
Clone locally:
git clone https://github.com/<your-user>/ai-agent-book.git
cd ai-agent-book
- Install build dependencies. The project requires
pandocandxelatexfor PDF generation, plus Python dependencies referenced in the documentation. The build scriptbook/build_pdf.shorchestrates the compilation process using theElegantBookLaTeX class to produceAI-Agents-in-Depth-en.pdf.
Understanding the Repository Structure
The repository separates content from code to support both reading and experimentation.
-
book/– Contains the markdown source files for the book text (e.g.,chapter1.md,chapter2.md). -
chapter*/– Each chapter has a corresponding directory containing runnable experiments. For example,chapter2/system-hint/holds the core agent implementation, whilechapter5/coding-agent/contains coding-specific demonstrations. -
chapter2/system-hint/agent.py– Houses the centralSystemHintAgentclass used across multiple experiments. This fully-featured agent supports tool calling, TODO-list management, timestamps, and trajectory logging according to the source code inbojieli/ai-agent-book. -
README.en.md– The landing page at the repository root (lines 49-62) contains the Table of Contents that you must update when adding new chapters.
Customizing the Core SystemHintAgent
The SystemHintAgent serves as the foundation for most experiments in the book. You can modify its behavior by adjusting the SystemHintConfig dataclass or extending its tool set.
Modifying Configuration
The SystemHintConfig dataclass (defined around line 74 in agent.py) toggles features via boolean flags:
from chapter2.system_hint.agent import SystemHintAgent, SystemHintConfig
my_config = SystemHintConfig(
enable_timestamps=False, # Disable timestamp injection
enable_tool_counter=True, # Track tool usage statistics
enable_todo_list=True, # Enable task management
enable_detailed_errors=True, # Verbose error reporting
)
agent = SystemHintAgent(
api_key="YOUR_API_KEY",
provider="openrouter",
model="gpt-4o-mini",
config=my_config,
)
Adding Custom Tools
To extend functionality, modify the _get_tools_description method (lines 73-94) to append new tool definitions to the list returned to the LLM. Then implement the corresponding handler method using the _tool_<name> pattern:
# In _get_tools_description, add:
{
"type": "function",
"function": {
"name": "search_web",
"description": "Perform a quick web search",
"parameters": {
"type": "object",
"properties": {
"query": {"type": "string", "description": "Search query"}
},
"required": ["query"]
}
}
}
# Then implement the handler:
def _tool_search_web(self, query: str) -> Dict[str, Any]:
import requests, bs4
resp = requests.get(f"https://html.duckduckgo.com/html/?q={requests.utils.quote(query)}")
soup = bs4.BeautifulSoup(resp.text, "html.parser")
first = soup.select_one(".result__title a")
return {
"success": bool(first),
"title": first.text if first else None,
"url": first["href"] if first else None
}
The agent automatically exposes new tools to the LLM and writes execution details to trajectory.json by default, enabling reproducible research and debugging.
Adding New Chapters
When you fork and modify the AI agent book, you typically add new content by following the established chapter pattern:
-
Create the markdown source in
book/chapter11.md(or your next available number). -
Create the experiment directory at
chapter11/with aREADME.en.mdthat lists companion projects and implementation details. -
Update the Table of Contents in the root
README.en.mdto include your new chapter in the overview table. -
Add runnable experiments in subdirectories like
chapter11/prompt2code/demo.py. Each experiment typically imports fromchapter2/system_hint.agentand sets up environment variables (such asOPENAI_API_KEY) viadotenvbefore execution.
For example, to run the coding agent experiment from Chapter 5 after modification:
export OPENAI_API_KEY="your-key-here"
python chapter5/coding-agent/demo.py
Building the PDF and EPUB
After modifying markdown sources or adding chapters, regenerate the book artifacts:
cd book
bash build_pdf.sh
This script invokes pandoc with xelatex to compile the markdown into AI-Agents-in-Depth-en.pdf. For multilingual EPUB editions, refer to the instructions in EPUB.md at the repository root.
Summary
- Fork the
bojieli/ai-agent-bookrepository and installpandoc/xelatexto enable PDF builds. - Customize the
SystemHintAgentviaSystemHintConfigor by adding tools to_get_tools_descriptioninchapter2/system-hint/agent.py. - Extend by creating new markdown files in
book/and corresponding experiment folders inchapter*/, updatingREADME.en.mdwith new entries. - Build using
book/build_pdf.shafter modifications to generate the final PDF.
Frequently Asked Questions
What dependencies are required to build the book locally?
You need pandoc and xelatex installed on your system to execute book/build_pdf.sh. Python dependencies for running the experiments vary by chapter but typically require openai or compatible SDKs, plus python-dotenv for environment management. Each experiment directory may contain its own requirements.txt or installation instructions.
Can I use the SystemHintAgent for commercial projects?
The repository is open-source, allowing you to fork and modify the AI agent book for research, teaching, or product development. Check the repository's license file (typically MIT or similar in bojieli/ai-agent-book) for specific commercial use terms, though the modular design explicitly supports standalone usage of the agent framework.
How do I debug agent behavior when adding new tools?
The SystemHintAgent automatically writes trajectory.json after each iteration, capturing the full conversation history, tool calls, and responses. Examine this file to trace execution paths. You can also enable enable_detailed_errors=True in your SystemHintConfig to surface more verbose error messages during development.
Why does my PDF build fail with font errors?
The build_pdf.sh script uses the ElegantBook LaTeX class, which requires specific Chinese and mathematical fonts. Ensure you have a complete TeX Live distribution with CJK (Chinese, Japanese, Korean) support installed, or modify the LaTeX template in book/ to use standard fonts if you only need English output.
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 →