Lesson 1 of 9 · Components
Core Components of an Agent
The building blocks of every AI agent: the model, tools, memory, the control loop and a policy layer, and how they fit together in a small Python agent.
- 5 min read
- Intermediate
- Reviewed
- Name the core components of an agent and what each does
- Explain why a policy layer sits between the model and the tools
- Build a small agent from separate, swappable components
- Decide where new behaviour belongs in an agent's design
An agent is a system, not a model
The Introduction to AI Agents course showed the agent loop. Real agents organise that loop into components, each with one job, so they can be tested, swapped and improved separately.
| Component | Responsibility | Examples |
|---|---|---|
| Model | Decide the next step from the goal and what's known | An LLM, sometimes several (a large one to plan, a small one for simple steps) |
| Tools | Act on the world and fetch information | APIs, databases, code execution, MCP servers |
| Memory | Hold what the agent knows: history, notes, retrieved facts | The message history, a scratchpad, a vector store |
| Control loop | Run steps, enforce limits, decide when to stop | Step limits, budgets, error handling |
| Policy | Decide what is allowed and what needs a person | Approval rules, permissions, spending limits |
A small agent, built from components
This banking agent keeps each component separate: a scripted stand-in for the model (so the page runs without an API key), two tools, a policy function and a loop inside an Agent class:
from dataclasses import dataclass, field
# ---- Component 1: the model (a scripted stand-in for an LLM) ----
def scripted_model(goal, memory, tool_names):
if not any(m.startswith("get_balance") for m in memory):
return {"tool": "get_balance", "args": {"account": "savings"}}
if not any(m.startswith("transfer") for m in memory):
return {"tool": "transfer", "args": {"amount": 200, "to": "current"}}
return {"answer": "Moved 200 euros from savings to your current account."}
# ---- Component 2: tools ----
BALANCES = {"savings": 1500, "current": 80}
def get_balance(account):
return BALANCES[account]
def transfer(amount, to):
BALANCES["savings"] -= amount
BALANCES[to] += amount
return f"ok, current balance {BALANCES[to]}"
TOOLS = {"get_balance": get_balance, "transfer": transfer}
# ---- Component 3: a policy that decides what needs a human ----
def needs_approval(tool, args):
return tool == "transfer" and args["amount"] > 100
@dataclass
class Agent:
model: object
tools: dict
policy: object
memory: list = field(default_factory=list) # ---- Component 4: memory ----
max_steps: int = 5
def run(self, goal, approve):
for step in range(1, self.max_steps + 1): # ---- Component 5: the loop ----
decision = self.model(goal, self.memory, list(self.tools))
if "answer" in decision:
return decision["answer"]
tool, args = decision["tool"], decision["args"]
if self.policy(tool, args) and not approve(tool, args):
return f"Stopped: {tool} was not approved."
result = self.tools[tool](**args)
self.memory.append(f"{tool}({args}) -> {result}")
print(f"step {step}: {self.memory[-1]}")
return "Stopped: step limit."
agent = Agent(model=scripted_model, tools=TOOLS, policy=needs_approval)
print(agent.run("Move 200 euros to my current account", approve=lambda tool, args: True))
print(BALANCES)
print("\nSame request, but the person says no:")
cautious = Agent(model=scripted_model, tools=TOOLS, policy=needs_approval)
print(cautious.run("Move 200 euros to my current account", approve=lambda tool, args: False))The same goal ran twice. The first time, the person approved the transfer. The second time, the policy flagged the 200-euro transfer as needing approval, the person said no, and the agent stopped before any money moved. The model didn't need to know anything about the rule: the policy enforced it.
Where does new behaviour go?
When you want an agent to do something new, decide which component owns it:
- “It should look up exchange rates” → a new tool.
- “It should remember the user's preferred airline” → memory.
- “It should never spend more than 500 euros” → the policy (never only the prompt).
- “It should give up after 10 minutes” → the control loop.
- “It should explain its plan first” → the model's instructions.
Common mistakes
Write the agent's policy component: which actions need a person's approval before they run.
def needs_approval(tool, args):
# A person must approve: any transfer over 100, and any tool whose name starts with "delete_".
return False
print(needs_approval("get_balance", {"account": "savings"}))
print(needs_approval("transfer", {"amount": 50, "to": "current"}))
print(needs_approval("transfer", {"amount": 500, "to": "current"}))
print(needs_approval("delete_payee", {"name": "Old Landlord"}))
An agent must never pay invoices over 1,000 euros without a manager's approval. Where should this rule live?
Summary
- An agent combines a model, tools, memory, a control loop and a policy layer.
- Keeping components separate makes them testable and swappable.
- The policy enforces rules and approvals in code, independent of the model.
- Put new behaviour in the component that owns it.
Next: the control loop in depth.
Finished reading? Tick it off to track your progress.