Understanding the Agent's State › Components of Agent State

Michael BrenndoerferJuly 7, 20253 min read
AI Agent HandbookAll chapters
Part 7 of 15Agent State and Architecture - Putting It All Together
Chapter 18Understanding the Agent's State › Components of Agent State
Reading section 4 of 12 · Components of Agent State · 3 minSection 4 of 12 · 3 min

Book contents

Section 4 of 12 · 3 min read

Understanding the Agent's State › Components of Agent StateOne section · Sections in this chapter4 / 12 ↓

Let's break down the key components that make up your agent's state.

Current Goal or Query

This is what the user wants right now. It might be a simple question ("What's the weather?") or a complex objective ("Plan my weekend trip"). The agent needs to keep this goal in focus as it works.

In[3]:
Code
class AgentState:
    def __init__(self):
        self.current_goal = None
        self.goal_status = "idle"  # idle, in_progress, completed, failed

When a new request comes in, you update the goal. When the agent completes it, you mark it as done. This simple tracking prevents the agent from forgetting what it's supposed to be doing.

Conversation Context

This is the short-term memory we built in Chapter 6. It's part of the state because it affects how the agent interprets new messages.

In[4]:
Code
class AgentState:
    def __init__(self):
        self.current_goal = None
        self.goal_status = "idle"
        self.conversation_history = []  # Recent messages

If the user says "What about the population?", the agent needs conversation history to understand they're asking about Paris (from a previous exchange).

Knowledge Base

The long-term memory is also part of state. It's what the agent knows about the user and the world, persisted across sessions.

In[5]:
Code
class AgentState:
    def __init__(self):
        self.current_goal = None
        self.goal_status = "idle"
        self.conversation_history = []
        self.knowledge = {}  # Long-term facts

This might include user preferences ("prefers morning flights"), important dates ("birthday is July 20"), or domain knowledge the agent has learned.

Intermediate Results

When working on a task, the agent often needs to remember what it has computed or retrieved. These are temporary results that matter for the current task but might not need long-term storage.

In[6]:
Code
class AgentState:
    def __init__(self):
        self.current_goal = None
        self.goal_status = "idle"
        self.conversation_history = []
        self.knowledge = {}
        self.working_memory = {}  # Temporary results

For example, if the agent searches for flights, it stores the results in working memory. When the user picks one, the agent can reference those results without searching again.

Tool State

Your agent needs to know what tools are available and which ones it has already used for the current task.

In[7]:
Code
class AgentState:
    def __init__(self):
        self.current_goal = None
        self.goal_status = "idle"
        self.conversation_history = []
        self.knowledge = {}
        self.working_memory = {}
        self.available_tools = []  # What the agent can use
        self.tools_used = []  # What it has already tried

This prevents the agent from calling the same tool repeatedly or trying tools that aren't available. It's like keeping track of which drawers you've already checked when looking for something.

Task Progress

For multi-step tasks, the agent needs to track where it is in the sequence.

In[8]:
Code
class AgentState:
    def __init__(self):
        self.current_goal = None
        self.goal_status = "idle"
        self.conversation_history = []
        self.knowledge = {}
        self.working_memory = {}
        self.available_tools = []
        self.tools_used = []
        self.task_plan = []  # Steps to complete
        self.current_step = 0  # Which step we're on

For complex requests, the agent can check "I've completed steps 1 and 2, now I'm on step 3" rather than losing track halfway through.