Papa Programmer
Lesson 04 of 20

What an agent is made of

7 min read

Optional

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.

  1. The model. It reads the situation and picks the next action. A bigger model reasons better, and a smaller one is faster and cheaper.
  2. 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.
  3. 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.
  4. The memory. This is what the model can see: the goal, the history of steps, and any notes or documents the program adds.
  5. 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.

python
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.

Five parts, five jobsModel, instructions, tools, memory and loop each do one thing.
Diagnose by symptomMatch the failure to the part before you change anything. A rule ignored means fix the instructions.
Smaller is more reliableFewer tools and shorter instructions leave fewer ways for the model to go wrong.

Your reading position is saved

0%

0 of 20 complete

Contents

Learning tools