Understanding the Agent's State › Components of Agent State
AI Agent HandbookAll chapters 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.
class AgentState:
def __init__(self):
self.current_goal = None
self.goal_status = "idle" # idle, in_progress, completed, failedWhen 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.
class AgentState:
def __init__(self):
self.current_goal = None
self.goal_status = "idle"
self.conversation_history = [] # Recent messagesIf 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.
class AgentState:
def __init__(self):
self.current_goal = None
self.goal_status = "idle"
self.conversation_history = []
self.knowledge = {} # Long-term factsThis 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.
class AgentState:
def __init__(self):
self.current_goal = None
self.goal_status = "idle"
self.conversation_history = []
self.knowledge = {}
self.working_memory = {} # Temporary resultsFor 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.
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 triedThis 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.
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 onFor 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.