Understanding the Agent's State › State Is Dynamic

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

Book contents

Section 7 of 12 · 1 min read

Understanding the Agent's State › State Is DynamicOne section · Sections in this chapter7 / 12 ↓

Here's an important point: state isn't static. It changes constantly as the agent works.

When the user sends a message, the state updates:

In[2]:
Code
## New message arrives
state["conversation_history"].append({"role": "user", "content": message})

When the agent calls a tool, the state updates:

In[4]:
Code
## Tool call completes
state["tools_used"].append("flight_search")
state["working_memory"]["flight_results"] = results

When the agent completes a step, the state updates:

In[10]:
Code
## Step complete
state["current_step"] += 1

The agent is constantly reading from state (to decide what to do) and writing to state (to record what it has done). This read-update-act cycle is the heartbeat of an AI agent.