Chapter 3 β Anatomy of an Agent
βAn agent is just an LLM that runs in a loop, using tools, and checking its work.β β Harrison Chase, creator of LangChain
The Four Pillars
Every modern AI agent is built from four core components. Think of it like the human analogy: a brain, hands, memory, and a plan.
Pillar 1: The LLM (Brain)
The LLM is the reasoning engine. It:
- Understands the userβs goal from natural language
- Decides what to do next at each step
- Generates tool calls, code, or natural language responses
- Evaluates whether results are satisfactory
Which LLM for Agents?
Not all LLMs are equal for agent tasks. Key requirements:
| Capability | Why It Matters |
|---|---|
| Function calling | Must reliably output structured JSON for tool invocations |
| Instruction following | Must follow system prompts precisely β agents live or die by this |
| Long context | Must handle growing conversation + tool results (32K+ tokens) |
| Reasoning quality | Multi-step problems require strong logical reasoning |
Best choices for agents (2026): GPT-4o, Claude 3.5/4, Gemini 2.0, Llama 3.3 (local), Qwen 2.5
The System Prompt Is Everything
For agents, the system prompt defines the agentβs identity, capabilities, and constraints:
You are a research assistant agent. You have access to the following tools:
- web_search: Search the internet for current information
- read_file: Read contents of a local file
- write_file: Write content to a local file
RULES:
1. Always search before answering factual questions
2. Never modify files without user confirmation
3. If unsure, ask the user for clarification
4. Cite your sources
Pillar 2: Tools (Hands)
Tools give agents the ability to interact with the world. Without tools, an agent is just a chatbot.
A tool is defined as a function schema that tells the LLM what it can do:
tools = [{
"type": "function",
"function": {
"name": "web_search",
"description": "Search the web for current information on a topic",
"parameters": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "The search query"
}
},
"required": ["query"]
}
}
}]
Deep dive: Chapter 5 β Tools & Function Calling
Pillar 3: Memory
Agents need memory to maintain context, learn from past interactions, and access knowledge.
The key challenge is context window management β as the conversation grows, you run out of space. Solutions:
- Summarization: Condense older messages into a summary
- Sliding window: Keep only the last N messages
- RAG: Store everything in a vector DB, retrieve only whatβs relevant
- Hybrid: Summarize old context + retrieve specific facts on demand
Deep dive: Chapter 6 β Memory Systems
Pillar 4: Planning
Planning is how agents break complex goals into manageable steps.
Plan-and-Execute Pattern
# Simplified plan-and-execute
plan = agent.create_plan("Write a blog post about quantum computing")
# plan = ["1. Research recent quantum computing breakthroughs",
# "2. Outline the blog structure",
# "3. Write the draft",
# "4. Review and edit"]
for step in plan:
result = agent.execute(step)
if not agent.evaluate(result):
plan = agent.replan(result, remaining_steps)
Deep dive: Chapter 7 β Planning & Reasoning
How It All Fits Together
Real-World Example: A Coding Agent
Letβs trace how GitHub Copilot Workspace (a real agent) handles βAdd dark mode to my appβ:
- Planning: Reads codebase β identifies relevant files β creates a multi-step plan
- LLM reasoning: βI need to modify the CSS variables and add a toggle componentβ
- Tool use: Reads files, writes new code, runs the linter
- Memory: Keeps track of which files were changed, what errors occurred
- Self-correction: Linter reports an error β agent reads the error β fixes the code β reruns
This is the anatomy in action. Every agent, from a simple chatbot with search to a multi-agent coding system, builds on these four pillars.
Whatβs Next
Now letβs look at the engine that drives all this β the agent loop. How does an agent decide when to think, when to act, and when to stop?
Next: Chapter 4 β The Agent Loop β
β Previous: Chapter 2 β History & Evolution Β· Next: Chapter 4 β The Agent Loop β
Last updated: April 2026