
The Four Pillars of Agent Anatomy
Deconstruct the AI agent into its core components. Deep dive into the Reasoning Engine, Planning, Memory, and Tool Use that enable autonomous behavior.
Core Components of an AI Agent
In the previous module, we established a high-level definition of an agent. Now, we must perform a surgical deconstruction. To engineer an agent that doesn't just "chat" but actually "works," you must master the four pillars of agent anatomy.
In this lesson, we will look at how the Brain (LLM), the Plan (Strategy), the Memory (Context), and the Tools (Capabilities) work together in a synchronized dance.
Pillar 1: The Reasoning Engine (The "Brain")
The LLM is the core of the agent, but it is not the whole agent. In this context, we refer to the LLM as the Reasoning Engine. Its job is to take the current state of the world and decide what to do next.
Key Factors in a Reasoning Engine
- Instruction Following: The model must be highly sensitive to system prompts. If a model "drifts" or forgets its persona, the agent will fail.
- Function Calling (Tool Use): Modern models (GPT-4o, Claude 3.5) are fine-tuned to output structured data (JSON) that can be easily parsed by your code to trigger tool execution.
- Reasoning Trace: Models like O1 (OpenAI) or chain-of-thought prompting allow the model to "think about its thoughts" before acting.
Mental Model: The Executive Assistant
Think of the LLM as a highly capable executive assistant who has never seen your office before. They are incredibly smart, but they need clear instructions and access to tools to be effective.
Pillar 2: Planning (The "Strategy")
Planning is the ability of an agent to break down a vague user goal into a sequence of executable steps. There are two primary approaches to planning in Agentic systems:
1. Chain-of-Thought (CoT)
The agent thinks out loud.
- Prompt: "Think step-by-step how to solve this."
- Result: The model generates a textual plan before acting. This significantly reduces logic errors.
2. Multi-Step Planning (ReAct)
The ReAct pattern (Reason + Act) is the industry standard.
- Reason: "I need to find the user's order ID."
- Act: Call
get_order_by_email("user@example.com"). - Observe: Output:
Order ID: 12345. - Reason: "Now I need to check the status of order 12345."
Architectural Flow of Planning
graph TD
Goal[User Goal] --> Plan[Planning Node]
Plan --> Step1[Step 1: Search]
Step1 -->|Result| Eval{Goal Met?}
Eval -- No --> Step2[Step 2: Analysis]
Step2 -->|Result| Eval
Eval -- Yes --> Finish[Final Output]
Pillar 3: Memory (The "Context")
Memory is what allows an agent to maintain consistency over time. Without memory, every turn in a conversation is a "reset."
Types of Agent Memory
-
Short-Term Memory:
- Implementation: The "Chat History" window.
- Constraint: Bound by the model's token limit (e.g., 128k tokens).
- Optimization: We use "Summarizing Memory" to condense old parts of the conversation.
-
Long-Term Memory:
- Implementation: Vector Databases (Chroma, Pinecone).
- User Case: "Remember that I prefer my code in Python, not Javascript." The agent can "retrieve" this preference from its long-term store.
-
Working Memory (State):
- Implementation: The
Stateobject in LangGraph. - Role: Holds temporary data like a variable
order_idoris_authenticated.
- Implementation: The
Pillar 4: Tool Use (The "Hands")
Tools are the interfaces through which an agent interacts with the external world. A tool is essentially a Schema + an Executable.
Anatomy of a Tool
To give an agent a tool, you must provide:
- Name:
get_current_weather - Description: "Use this tool to find the weather for a specific city. Input should be a city name."
- JSON Schema:
{ "city": "string" } - Logic: The actual Python function that calls the Weather API.
The Tool-Loop in LangGraph
sequenceDiagram
participant LLM
participant Orchestrator
participant Tool
Orchestrator->>LLM: Here is the Goal and the Tool List
LLM->>Orchestrator: I want to call 'get_weather(city="NYC")'
Orchestrator->>Tool: Execute get_weather("NYC")
Tool-->>Orchestrator: 72 Degrees, Sunny
Orchestrator->>LLM: Observation: 72 Degrees, Sunny. What's next?
LLM->>Orchestrator: Final Answer: It is a beautiful day in NYC.
Code Highlight: Defining a Tool in LangChain
from langchain_core.tools import tool
@tool
def calculate_mortgage(principal: float, rate: float, years: int) -> float:
"""
Calculates the monthly mortgage payment.
Use this tool whenever a user asks about loan payments.
"""
monthly_rate = rate / 100 / 12
num_payments = years * 12
payment = principal * (monthly_rate * (1 + monthly_rate)**num_payments) / ((1 + monthly_rate)**num_payments - 1)
return round(payment, 2)
# This tool can now be 'bound' to an LLM
model_with_tools = llm.bind_tools([calculate_mortgage])
The Integration: Putting it All Together
In a production system, these four pillars are not isolated.
- The Reasoning Engine reads the Memory.
- It uses its Planning capability to decide which Tool to call.
- The output of the Tool is saved back into Memory.
This cycle repeats until the Planning node determines the goal is reached.
Summary and Mental Model
Think of an agent like a Professional Consultant.
- Reasoning: Their inherent intelligence and education.
- Planning: The project roadmap they create.
- Memory: The notes they take during meetings.
- Tools: The spreadsheets, slide decks, and APIs they use.
If any of these pillars is weak, the consultant (agent) fails. If they have a great brain but no memory, they will ask the same question twice. If they have tools but no planning, they will act randomly.
In the next lesson, we will explore the difference between Stateless and Stateful agents, which is the foundational design choice for every production system.
Exercise: pillar Analysis
- Failure Mode: You ask an agent for a report on AI trends. It searches Google, finds 10 links, but then immediately gives you a 1-sentence answer citing only the last link. Which pillar failed? (Planning? Memory? Tools?)
- Design Task: You are building an agent for a travel agency. Define three tools it would need and what the Short-term memory should store during a 10-minute session.
- Reasoning Engine: Why would you choose a larger, slower model (Claude 3.5 Opus) for the "Planning" step, but a smaller, faster model (Claude 3.5 Haiku) for "Tool Execution"?