Abstract
You have talked to a language model. This book is about the next step: making it act.
Building AI Agents is the natural sequel to Construindo Chatbots, but it can be read on its own. Where the previous volume ended — at the model that answers —, this one begins: at the loop that decides, executes, observes and repeats. In three parts, the book builds the complete machinery of an agent from scratch in Python. The first part lays the foundations and assembles the core: the agent loop and the harness around it — tool validation, security policies, step and token budgets, tracing and context management. The second part deals with what gives the agent knowledge and reach: skills loaded on demand, the MCP protocol, and the orchestration of agents that call agents. The third part is about what separates a prototype from a system: security against prompt injection, evaluation based on properties of the trace, and the real economics of agents — why cost grows quadratically and how to contain it.
All the code was executed and its output appears in the book. The examples run offline, without an API key, because the core of an agent does not depend on a specific model: it depends on the format of the conversation and the discipline of the loop. Where a real model is needed, the code is ready and the book tells you what happens when you plug in the key.
Written for those who want to truly understand, not just paste code from a tutorial, the book treats the agent as an engineering object: with explicit contracts, barriers that do not depend on the model’s goodwill, and the conviction that explaining why an agent fails is more valuable than hiding the failure behind one more layer of abstraction.
If you have ever wondered how an AI decides on its own when to stop, what happens between the model’s response and the command that shows up in your terminal, or why your API bill tripled after you changed a prompt — this book was written to answer.