Lesson 2 of 7 · What Is an Agent?
LLM vs AI Agent
What changes when an LLM becomes an agent: from one answer to a loop of tool calls, results and decisions. See a real tool call's messages and who does what.
- 5 min read
- Beginner
- Reviewed
- Explain the difference between an LLM call and an agent
- Describe a tool call and a tool result in a conversation
- Explain which parts the model does and which parts your code does
- Read an agent's message history
Same model, different job
A large language model on its own takes text in and gives text out. One request, one response. On its own, it can't look anything up, run code or change anything outside the conversation.
An agent wraps that same model in a program that lets it act:
| Plain LLM call | AI agent | |
|---|---|---|
| Interaction | One request, one response | A loop of many model calls |
| Knowledge | Only its training and the prompt | Can fetch fresh information with tools |
| Actions | Writes text | Calls tools: search, run code, update records |
| Who decides the steps | You, in your code | The model, step by step |
| Typical use | Answer, summarise, rewrite | Multi-step tasks with unknown steps |
The model never runs anything itself
This is the key point. The model can't call your functions. Instead, it writes a request to call one, in a structured format, and your code runs it:
Here's one complete round trip, written out as the message history:
import json
def percentage(amount, percent): # a tool: ordinary Python code
return round(amount * percent / 100, 2)
# An agent's memory of a task is simply the list of messages so far.
messages = [{"role": "user", "content": "What's 18% of 2,450 euros? I need it for an invoice."}]
# 1. The model replies with a TOOL CALL instead of an answer
messages.append({"role": "assistant", "tool_call": {"name": "percentage", "input": {"amount": 2450, "percent": 18}}})
# 2. Our code runs the tool and adds the RESULT to the conversation
call = messages[-1]["tool_call"]
result = percentage(**call["input"])
messages.append({"role": "tool", "content": str(result)})
# 3. The model reads the result and writes the final answer
messages.append({"role": "assistant", "content": f"18% of 2,450 euros is {result:,.2f} euros."})
for m in messages:
body = m.get("content") or json.dumps(m["tool_call"])
print(f"{m['role']:>9}: {body}")Read the four messages from top to bottom:
- The user asks a question.
- The model replies with a tool call instead of an answer: it wants
percentagerun with 2450 and 18. - Your code runs the function and adds the result as a message.
- The model reads the result and writes the final answer.
The message list is the agent's working memory: each model call sees everything that happened so far.
Common mistakes
Do your code's part of a tool round trip: run the requested tool and add its result to the conversation.
messages = [
{"role": "user", "content": "Convert 50 USD to euros"},
{"role": "assistant", "tool_call": {"name": "convert", "input": {"amount": 50, "rate": 0.92}}},
]
def convert(amount, rate):
return round(amount * rate, 2)
# Run the tool the model asked for, append {"role": "tool", "content": <result as text>},
# then print how many messages there are and the last one's content:
# 3
# 46.0
In an agent, who actually runs a tool when the model asks for it?
Summary
- A plain LLM call is one request and one response; an agent runs the model in a loop with tools.
- The model writes tool calls; your code runs them and returns tool results.
- The message history is the agent's memory of the task.
- Running tools in your own code is what lets you check and control what an agent does.
Next: the agent loop in detail.
Finished reading? Tick it off to track your progress.