What an agent is made of
7 min read
The five parts
Think of an AI agentA program that uses a language model to work toward a goal. It chooses its own steps, uses tools to act, reads the results and repeats until the goal is met or a limit stops it. as a small team where each part has one job.
- The model. It reads the situation and picks the next action. A bigger model reasons better, and a smaller one is faster and cheaper.
- The instructions. The System promptThe instructions at the start of a prompt that set the model's role, its rules and the format of its answer. It stays the same on every call. tells the model its role, its rules and what a good result looks like.
- The tools. These are the actions the agent can take. A tool can be a search, a file reader, a database query or a call to another service.
- The memory. This is what the model can see: the goal, the history of steps, and any notes or documents the program adds.
- The loop. This is the program that runs the cycle, runs the tools, enforces limits and decides when to stop.
The same parts in code
The shape fits in a few lines. This sketch only describes an agent. It does not run one.
from dataclasses import dataclass, field
@dataclass
class Agent:
instructions: str
tools: dict
max_steps: int = 8
history: list = field(default_factory=list)
support = Agent(
instructions="You help customers with orders. Never promise a delivery date.",
tools={"find_order": lambda order_id: {"id": order_id, "status": "shipped"}},
)
print(sorted(support.tools), support.max_steps)The model is not a field here because it sits behind a function call, and you can swap it without touching the rest. The instructions, tools, max_steps and history fields are the parts you control as a developer.
Fix the right part
When an agent fails, the symptom points to the part. This map saves hours.
- It ignores a rule. The instructions are unclear, too long or buried. Rewrite them first.
- It calls the wrong tool. The tool names or descriptions overlap, or a tool is missing. Fix the tools.
- It forgets something it learned earlier. The history was cut or it is too long. Fix the memory.
- It never stops, or stops too early. The loop lacks a good exit condition. Fix the loop.
- It reasons badly even with clear inputs. Only now consider a stronger model.
Most teams reach for a bigger model first, because it needs no thought. It is the most expensive fix, and it is the right one least often.
Keep each part small
A good agent has a short set of instructions, a handful of tools and a history that holds only what matters. Every extra tool is one more choice the model can get wrong. Every extra paragraph in the instructions competes for attention with the paragraph that matters. Add a part only when a test shows you need it.
Which part do you fix?
The agent keeps ignoring your rule never to promise a delivery date. The rule is one short line in the middle of a long prompt.
A rule ignored points at the instructions. A bigger model is the most expensive fix and the least often right.
Which part do you fix?
The agent keeps calling `search_web` when it should call `search_orders`. The two descriptions both say "find information".
Calling the wrong tool when the descriptions overlap is a tool problem. Say what each tool does and when to use it.
Which part do you fix?
The agent finishes a task, then sends a second, duplicate email because it never recorded that the first one went out.
The agent could not see what it had already done. What the model can see is its memory, so fix that.
Your reading position is saved
0 of 20 complete
Lesson complete
What an agent is made of
Up next