← Back to Table of Contents

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.

The Four Pillars of an AI Agent
🧠
LLM (Brain)
Reasoning engine. Understands language, makes decisions, generates plans.
πŸ”§
Tools (Hands)
Functions the agent can call β€” search, code execution, APIs, databases.
πŸ’Ύ
Memory
Short-term (conversation), long-term (vector store), episodic (past experiences).
πŸ“‹
Planning
Task decomposition, step sequencing, self-correction, goal tracking.

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.

Common Agent Tools
πŸ”
Web Search
Google, Bing, Tavily β€” access to current information
πŸ’»
Code Execution
Python sandbox, shell commands β€” compute and transform data
πŸ“
File I/O
Read, write, edit files on disk β€” persistent output
🌐
API Calls
REST/GraphQL endpoints β€” interact with external services
πŸ—„οΈ
Database Queries
SQL/NoSQL β€” read and write structured data
πŸ–₯️
Computer Use
Click, type, screenshot β€” control GUI applications

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.

Memory Architecture
🧠 Working Memory Current context window β€” the LLM's "attention span" (32K–1M tokens)
πŸ’¬ Short-Term Memory Conversation history β€” what's happened in this session
πŸ“š Long-Term Memory Vector database β€” persistent knowledge, past experiences, user preferences
🌍 External Knowledge RAG β€” search over documents, APIs, databases at retrieval time

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

Plan-and-Execute Pattern
πŸ“‹ Create plan from user goal
▢️ Execute step 1
▢️ Execute step 2
πŸ” Evaluate: on track?
πŸ”„ Replan if needed
βœ… Goal achieved
# 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

Complete Agent Architecture
πŸ‘€ User sends a goal
πŸ“‹ Planning: decompose into steps
🧠 LLM: reason about next action
πŸ”§ Tools: execute the action
πŸ’Ύ Memory: store result, update context
πŸ”„ Loop back to LLM or return result to user

Real-World Example: A Coding Agent

Let’s trace how GitHub Copilot Workspace (a real agent) handles β€œAdd dark mode to my app”:

  1. Planning: Reads codebase β†’ identifies relevant files β†’ creates a multi-step plan
  2. LLM reasoning: β€œI need to modify the CSS variables and add a toggle component”
  3. Tool use: Reads files, writes new code, runs the linter
  4. Memory: Keeps track of which files were changed, what errors occurred
  5. 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