AI School · Level 4 · Agents · 1 of 4

What an AI agent actually is

Léelo en español →

Reading time: about 20 minutes

"AI agent" has turned into a phrase that means nothing, and that is a practical problem: if you do not know exactly what one is, you cannot know when you need it — which is rarely — or why it is dangerous — which is any time it writes something. This lesson contains no code at all. It is the one that makes the next three make sense.

An agent is a model in a loop, with tools and a stopping rule. That is all there is to it. And three things follow from that sentence: it acts, it decides how many times to act, and it can be wrong by doing, not just by saying.

What you will understand by the end

  1. What an agent is, and how it differs from a chat and from a script
  2. The four pieces, one at a time
  3. Why the loop is both the expensive part and the risky part
  4. When an agent is the wrong tool (most of the time)
  5. Where the human goes, and why not where everyone puts them
  6. What can go wrong, with names

1. Chat, script and agent: three different things

All three use the same model. What changes is who decides what happens next, and that changes everything.

ChatScriptAgent
Who decides the next step You, by typing again Whoever wrote it, in advance The model, as it goes
Can it touch anything No. It returns text Yes, whatever it was told Yes, and it picks what
Number of model calls One per message Zero, or a fixed number Not known in advance
Same result twice? Nearly Always Not necessarily
Cost of one run Known Zero A range
When it fails You see it and rewrite It throws an error It may carry on
Look at the last row, which is the one nobody looks at. A script that fails stops, and you know. An agent that fails mid-loop can keep going: it reads the error as information, changes plan and finishes "successfully" having done something you did not want. No exception, no red trace, and a beautifully worded summary at the end.

2. The loop, which is the whole idea

The job "Draft my order" The model reads the job and decides what to do now Does it need a tool? It runs and returns a result Answer and the loop ends YES NO back to the model The context everything it has seen so far
The whole loop. The only thing separating an agent from a chat is the arrow coming back: the tool result goes into the model again, and the model decides again. That loop repeats until the model answers without asking for anything else — or until you stop it. Every turn is one model call, and every call costs money.

Read it again slowly, because it is literally 90% of what there is to know:

  1. You give it a job and a list of tools it may use.
  2. The model looks at the job and decides: can I answer now, or do I need something?
  3. If it needs something, it does not do it itself: it asks for a tool to be run, with specific arguments.
  4. Your code actually runs it and hands back the result.
  5. That result goes into the context and you go back to step 2.
  6. When the model answers without asking for anything, the loop ends.
The model never runs anything. This is the hardest part to internalise and the most reassuring once it lands: the model can only ask. What actually happens is done by your code, on your terms. An agent is not dangerous because the model can do things — it is dangerous because you wrote it a tool that can.

3. The four pieces

Every agent, from the dumbest to the most elaborate, has exactly these four. If somebody sells you a fifth, that is marketing.

3.1. The instructions

The fixed text that goes in front of everything: what it is, what it may do, what it may not, and what to do when it does not know. It is the same system prompt from the chatbot lesson, and it matters more here, because it gets re-read on every turn of the loop.

And watch this, because it costs real money: the instructions are sent in full on every turn. A 2,000-word system prompt in an agent that runs ten turns is 20,000 words paid for. Keeping it short is not a style preference: it is half the bill.

3.2. The tools

A tool is two things at once: a function you write and a description the model reads. The function does the work; the description decides whether the model uses it well, uses it badly, or never uses it.

This deserves a lesson of its own —and it has one— because nearly every failure of an agent that "does not work" is really a description failure. The model cannot see your code. It sees one sentence.

3.3. The context

Everything the agent has seen so far: the job, what it decided, what it asked for, what it got back. It grows on every turn, and it grows fast — a tool that returns a 200-row table means 200 rows sitting inside the context for every remaining turn.

One design rule falls straight out of this, and it saves a lot of money: a tool returns what is needed to decide, not everything it has. "Give me the 12 products below minimum" and "give me the inventory" are the same database query and two very different bills, because the second one drags 3,000 rows through every remaining turn.

3.4. The stopping rule

When it ends. And there are two of them, not one:

The cap is not an optional safety net: it is mandatory. A confused model can ask for the same tool over and over expecting a different answer, and with no cap that is an infinite loop burning your quota until it runs out. This is not hypothetical — it is the first failure you see when you build an agent, and it happens to everybody. You will see it on your first afternoon.

← Previous: the map of 17 areas Next: build one from scratch →