From chatbot to agent
“A program that decides its own next step is a program you have to trust more than you would like.”
Objective
Establish the technical difference between a chatbot and an agent, define the vocabulary used throughout the book — loop, harness, tool, skill, protocol — and present the construction itinerary to be followed, chapter by chapter.
1.1 Where the previous volume stopped
In the book Construindo Chatbots (Silva Neo and Silva Neo 2026), the reader ends up with a system that receives a message and returns a message. It may be a fine-tuned large language model, a BERT for intent classification, or a LLaMA running locally. The pattern is always the same: text in, text out.
This pattern has an informal name in practice: request–response. The program asks the model a question, receives an answer and presents it. Control of the flow lives entirely in your code. You wrote the if that decides whether the answer is good, the for that walks through a list of customers, the sequence of calls that makes up a larger task.
An agent breaks this premise. It does not receive just a question; it receives a goal and the tools with which to pursue it. It then decides, on its own, which tools to use, in what order, how many times, and when to stop.
The difference sounds philosophical, but it is technical and has concrete engineering consequences:
-
The path is unpredictable. Two runs of the same agent with the same question may take different routes. You do not test the path; you test properties of the behavior.
-
Error is normal. An agent that never makes mistakes is an agent that is not doing anything interesting. The system must tolerate, detect and correct errors, not assume they do not happen.
-
Cost is variable. Each step is a model call, which costs money and time. A loop without a limit is a bill without a limit.
-
The attack surface grows. If the agent can execute commands, it can execute the wrong command. If it reads web content, that content can try to instruct it.
1.2 An operational definition
There are many definitions of “agent” in the literature, from philosophy to software engineering. In this book we use an operational definition, chosen because it translates directly into code:
An agent is a loop that converses with a model, executes the actions the model requests, returns the results to the model and repeats until the model declares it is done — or until an external limit interrupts it.
Notice what this definition does not say. It does not say the agent is autonomous in the strong sense; it does not say it learns; it does not say it has consciousness or symbolic planning. It only says that there is a loop, that the model is inside it, and that there is a limit.
Everything else in this book — memory, skills, protocols, orchestration — consists of extensions to this core. If you understood the sentence above, you understood the backbone of the whole book.
The word “agent” is used today for very different things. A “customer service agent” on a commercial website is usually a decision tree. An “autonomous agent” in the press is usually a system with dozens of nested loops. The definition in this book covers the minimal and common technical case: a loop with a model and tools. Nothing more is needed to start building, and nothing less is enough to understand what is being built.
1.3 Three layers that are often confused
It is common to see “agent”, “harness” and “framework” used as synonyms. They are not, and the confusion is expensive when it is time to debug. Table 1.1 settles the vocabulary.
| Layer | What it is | Who writes it |
|---|---|---|
| Loop (agent loop) | The cycle model action observation model | You, in about 80 lines |
| Harness | Everything around the loop: tools, policies, budget, tracing, context | You, in a few hundred lines |
| Framework | A library that ships with a ready-made loop and harness | Someone else |
Table 1.1. The three layers of an agent.
The framework does not replace an understanding of the two layers below it. It only packages them. When something goes wrong — and it will —, you will need to open the package. That is exactly what the first part of this book teaches you to do.
1.4 What the reader will build
The book is an itinerary, not an anthology. Order matters because each piece is verifiable without the next one, and building in the wrong order means debugging infrastructure problems and behavior problems at the same time.
-
The loop, with a scripted model (Chapter 2). No network, no key, no cost. It confirms that the message format is correct.
-
Tools with a contract (Chapter 3). Argument validation, errors that do not kill the process.
-
The harness (Chapter 4). Policies, budget, tracing.
-
Context management (Chapter 5). Quadratic cost and how to contain it.
-
Skills (Chapter 6). Procedural knowledge on demand.
-
MCP (Chapter 7). The protocol that separates agent, tool and process.
-
Orchestration (Chapter 8). Agents that call agents.
-
Security (Chapter 9). Injection, exfiltration, destructive actions.
-
Evaluation (Chapter 10). What to test when behavior varies.
-
Cost and performance (Chapter 11). Where the money goes and how to contain it.
Each chapter ends with exercises in the same format as the previous volume, and the answers are at the end of the book.
1.5 Thinking with the right metaphor
There are two bad metaphors and one good one for thinking about agents.
The first bad metaphor is the assistant. An assistant suggests someone who understands what you want and takes care of it. An agent does not understand; it completes patterns and chooses among alternatives. Treating it as an assistant leads to trusting it too much.
The second bad metaphor is the program. A program suggests determinism. An agent is not deterministic; the same input can produce different paths. Treating it as a program leads to writing tests that break for no reason.
The good metaphor is the quick apprentice with little supervision. It knows many subjects, does well at tasks it has seen before and fails in ways you did not foresee. You do not leave it alone with the safe open, but you do not watch every step either. You design the environment so that mistakes are cheap and success is verifiable.
That is the spirit of the book: design the environment, do not program the behavior.
Common pitfall
A frequent mistake with a first agent is to start with the framework. The temptation is real: in five minutes you have an “agent” answering. The problem is that when it behaves strangely — and the first time comes early —, you do not know whether the problem is in your prompt, in your tool, in the framework’s retry policy or in the model. Building the loop by hand first costs one day and saves weeks.