>_ DevTrendsen

Language

Home

Languages

Sections

Frontend Backend Mobile DevOps AI / ML GameDev Blockchain Embedded Security
Python

How to Build a Working AI Agent Without Losing Your Mind

You know that feeling when you read the news about another "breakthrough" AI agent, open the repository, and find three hundred lines of LangChain spaghetti code that crashes at the slightest provocation? I encounter this all the time. In theory, everything sounds simple: give the model access to tools, and it'll do everything on its own. In practice, we get endless hallucination loops and token bills that grow faster than our understanding of how to debug any of it.

Recently I stumbled upon the ai-agent-book repository by Bojie Li. This isn't just another collection of links. The author wrote an entire book on agent design, from theory to hard engineering practice, and released it along with a ton of code. It's as if someone gathered all the experience from building real systems and packaged it into a single guide.

What Is It Anyway

In short — it's a definitive guide for AI agent developers. The project fills a huge gap between "I know how to write prompts" and "I know how to build reliable systems." The author lays out a simple formula: Agent = LLM + Context + Tools. The entire narrative is built around this idea.

There's no fluff about "paradigm shifts" here. Instead, you'll learn why your agent suddenly forgets instructions after five minutes of dialogue and how to work with KV Cache so you don't go bankrupt on inference. The project is in Chinese, but there's an English translation, and the code speaks for itself in the universal language of Python.

Key Features That Will Actually Come in Handy

The author organized the project into chapters, each with working demos. Here are a few things that made me lose track of time diving into the code.

Build Your Own Coding Agent from Scratch

Chapter five contains a full-featured code-writing assistant implementation. Unlike many alternatives, it doesn't require installing a dozen system utilities. All functionality (even a ripgrep equivalent) is written in pure Python. This is convenient: you can run it on any machine and immediately see how the agent reads files, makes edits, and runs linters on its own.

MCP Protocol in Action

The project actively uses the Model Context Protocol (MCP). Chapter four shows how to divide tools into感知 (perception), 执行 (execution), and 协作 (collaboration). There are examples of servers for file system operations, web search, and even browser control. If you've been wondering how to standardize your agents' communication with the outside world, this is the place to look.

Context Engineering

This is probably the most useful part. Instead of just dumping everything into the model, the author teaches you to create "dynamic skills" (Agent Skills). The agent sees only a brief list of abilities, and only when it decides it needs, say, a PPTX generation skill, the system loads the full documentation and code for that tool. This saves tokens and makes the model's behavior more stable.

Self-Evolution Without Fine-Tuning

Chapter eight covers an approach where the agent learns from its own successes. It records successful chains of actions and turns them into new tools or "experiences" that it later retrieves through a vector database. This creates a layer that makes the system smarter with every run without modifying the model's weights.

How It's Structured Under the Hood

All the code is organized into folders chapter1chapter10. The architecture of the examples is quite transparent. It's mostly Python 3.10+ using FastAPI for network stuff and standard libraries for working with LLMs.

It's worth checking out the quality evaluation section (chapter 6). It includes not only standard benchmarks like SWE-bench, but also tools for analyzing task costs and measuring time to first token (TTFT). This is exactly what businesses need when they ask: "So how much will this cost in production?"

Where to Use This

  1. Building internal tools. If you need to automate routine tasks in your company (like log parsing or report generation), take examples from chapters 5 and 10.
  2. Team training. The repository works great as a curriculum. You can go through one chapter per week and discuss it in meetings.
  3. Next-level RAG. Chapter three has a solid explanation of how to move beyond simple text search to knowledge graphs and multi-layered memory.

Who Should Check Out the Repository

First and foremost, those who've already played around with simple chatbots and want to build something autonomous. If you're working on complex RAG systems or trying to bolt AI onto existing software, these examples will save you weeks of duct-tape engineering.

There's no ready-made "Make It Awesome" button here, but there are blueprints for building one. The only downside is that some of the documentation is still better read through a translator, but the code structure is so logical that anyone who's written Python won't get lost in it.

<a href="https://star-history.com/#bojieli/ai-agent-book&Date"> <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/bojieli/ai-agent-book/main/assets/star-history-dark.png" /> <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/bojieli/ai-agent-book/main/assets/star-history-light.png" /> <img alt="Star History Chart" src="https://raw.githubusercontent.com/bojieli/ai-agent-book/main/assets/star-history-light.png" width="720" />

The project already has over five thousand stars, and the community is actively translating the content. Definitely worth bookmarking, even if you're not planning to write a book — the practical value of these resources outweighs any language barriers.

Related projects