Sub topic 2
What an AI agent is and how it differs from a chatbot
Prerequisites
This chapter assumes you know what a large language model (LLM) is and can read basic Python. It also assumes you are comfortable with JSON and with metrics such as clicks, spend and conversions.
The working model
An AI agent is a program that uses an LLM to decide what to do next. It acts through tools, reads the results, and repeats until a stop condition is met. It has three parts:
- Model: chooses the next step.
- Tools: functions that fetch data or calculate results.
- Loop: your code, which runs the tools and decides when to stop.
A chatbot has none of the last two. You send one prompt and get one reply. Its knowledge is whatever the model learned in training plus whatever you paste into the conversation.
| Feature | Chatbot | Agent |
|---|---|---|
| Steps per task | One reply | Several, chosen at run time |
| Data access | What you paste in | Tools that query live sources |
| Arithmetic | Done by the model | Done by deterministic code |
| Stops when | The reply is sent | A final answer or a step limit |
A concrete example
Suppose you ask, "How did the spring campaign perform this month?" A chatbot has no access to your ad account. It will either ask you to paste numbers or invent plausible ones. An agent asks for a data-fetching tool, then a metrics tool, and writes its answer from the values those tools return.
The model never runs code itself. It emits a structured request, and your program executes the function:
def total_spend(rows):
return round(sum(r["spend"] for r in rows), 2)
tools = {"total_spend": total_spend}
# What a model reply asking for a tool might look like
reply = {"tool": "total_spend", "args": {"rows": [{"spend": 150.0}, {"spend": 60.0}]}}
result = tools[reply["tool"]](**reply["args"])
print(result)This prints 210.0. The model chose the tool and the arguments, but the sum came from Python.
Common errors
- Calling a fixed script an agent. If the steps never change, you have a pipeline. That is fine, and often cheaper and more predictable. Use an agent when the next step depends on what the last one returned.
- Letting the model do the math. Models can produce wrong figures that look right. Put calculations in tools.
- No step limit. Without a cap, a confused agent can loop and spend money. Always set a maximum number of steps.
- Too many tools. A long list of overlapping tools makes the model pick the wrong one. Give each tool one clear job and a precise description.
- Treating tool access as correctness. An agent can pull the wrong date range or misread a result.
Where this fits in the workflow
Agents suit stages that are repetitive and have clear inputs, such as pulling weekly numbers and drafting a summary. They suit judgment-heavy stages less, such as choosing next quarter's strategy. Later chapters cover the loop, tools and checks in detail.
Exercise
A teammate says their tool is an agent. It always pulls last week's data, computes click-through rate, and fills a fixed template. Is it an agent? What one change would make it closer to one?
Show answer
It is a fixed pipeline, because the steps never depend on intermediate results. It becomes closer to an agent if a model decides which tool to call next from what it has seen so far. For example, it could fetch extra data when a metric looks unusual. The loop would also need a step limit and a stop condition.