GNGiseldo Neo and Alana NeoBooks
Building AI Agents1 / 18

Preface

There is a moment, when you start writing artificial intelligence agents, when the program stops being predictable. You did not write the steps. You wrote the tools and the goal, and the system decided on its own the order in which things happen. It is unsettling the first time and addictive the third.

This book is about that moment.

It is not an introduction to chatbots — that ground was covered in the previous volume of this series, Construindo Chatbots (Building Chatbots, in Portuguese), which goes from ELIZA and AIML to the inner workings of large language models. The starting point here is different. We assume you already know what a language model is, that you have seen tokens, embeddings and attention, and that you want to build the layer that turns a model that answers into a system that acts.

The premise of this book is simple and stubborn: an agent is not a framework. It is a loop, a few contracts and an engineering discipline around them. If you understand those three things, you can read any agent library on the market and know exactly what it is doing for you — and what it is hiding.

That is why all the code here is written from scratch, in Python, without hiding decisions behind decorators. When the model insists on calling the wrong tool, when the bill doubles, when the agent gets stuck in a loop, when a skill is not loaded — the answer is always in one of these fundamental parts that this book builds by hand.

The book assumes you program in Python and have used a language model through an API at least once. It does not assume familiarity with message protocols, harness architecture or context engineering. All of that is built here, step by step, with the code executed and its output printed alongside.

A warning about what this book does not do: it does not promise that your agent will work. It promises that you will understand why it works, or why it does not.

Enjoy the read!