What Is Agent State?
Quick Definition#
Agent state is the structured data an AI agent maintains and updates across its reasoning steps — including conversation history, intermediate results, task progress, and working memory. State is what transforms a sequence of independent LLM calls into a coherent agent that can complete multi-step tasks without losing context between steps.
Browse all AI agent terms in the AI Agent Glossary. For how agents use state in execution, see Agent Loop and AI Agent Memory.
Why Agent State Matters#
Without state, each call to an LLM is stateless — the model has no memory of what happened before. For simple question-answering, this is fine. For any multi-step task, it is a fundamental problem:
- How does the agent know what tools it has already called?
- How does it know what information it has gathered so far?
- How does it avoid re-doing steps it has already completed?
- How does it track which subtasks are done and which remain?
Agent state solves this by providing a structured data container that persists across the agent's execution loop. Each reasoning step reads the current state, decides on an action, executes that action, and writes the updated state. The next step picks up from where the previous one left off.
Components of Agent State#
Conversation History#
The sequence of messages between user and assistant — the foundation of all LLM context. The agent needs conversation history to understand what has been asked and what has been answered.
Working Memory / Intermediate Results#
The outputs of tool calls and sub-tasks stored temporarily. A research agent might store: "Found the CEO is Jane Smith (web search result), annual revenue is $5.2B (database query result), main competitors are X, Y, Z (analysis result)." This information is held in state until the final answer is generated.
Task Progress / Status#
Tracking which steps in a multi-step workflow have been completed. An invoice processing agent might track: "Step 1: extract data — done. Step 2: validate totals — in progress. Step 3: submit to ERP — pending."
Control Variables#
Operational variables like retry counts, iteration numbers, error flags, and timeouts. These prevent infinite loops and enable graceful error handling without requiring all this logic in the agent prompt.
Accumulated Context#
Facts, entities, and knowledge discovered during execution that feed into future reasoning. As the agent explores a problem, it builds up a picture of the situation that informs later decisions.
Agent State in LangGraph#
LangGraph makes state explicit through typed state schemas:
from langgraph.graph import StateGraph, END
from typing import TypedDict, List, Annotated
import operator
# Define the state schema — exactly what data persists across nodes
class ResearchState(TypedDict):
question: str # Original user question (immutable)
search_queries: List[str] # Search queries generated so far
search_results: List[str] # Results from web searches
draft_answer: str # Work-in-progress answer
sources: List[str] # Cited sources
iterations: int # How many search rounds completed
is_complete: bool # Stop condition
# Each node receives the full state and returns partial updates
def generate_queries(state: ResearchState) -> dict:
"""Generate search queries from the question."""
queries = query_generator.invoke(state["question"])
return {
"search_queries": queries,
"iterations": state["iterations"] + 1
}
def search_web(state: ResearchState) -> dict:
"""Execute searches and store results."""
results = []
for query in state["search_queries"]:
result = web_search(query)
results.append(result)
return {"search_results": results}
def synthesize(state: ResearchState) -> dict:
"""Combine results into a draft answer."""
answer = synthesizer.invoke({
"question": state["question"],
"context": "\n".join(state["search_results"])
})
return {
"draft_answer": answer,
"is_complete": True
}
# Build the graph
graph = StateGraph(ResearchState)
graph.add_node("generate_queries", generate_queries)
graph.add_node("search", search_web)
graph.add_node("synthesize", synthesize)
# ... add edges
The key insight: each node gets the complete state as input and returns only the fields it updates. LangGraph merges these updates to produce the next state.
State Persistence#
Agent state can be ephemeral (exists only for the current run) or persistent (saved between runs):
Ephemeral state lives in memory for the duration of a task. When the agent completes or crashes, the state is gone. Suitable for short-lived tasks.
Persistent state is saved to a database (Redis, PostgreSQL, SQLite) at checkpoints. Enables:
- Resuming a paused long-running task
- Human-in-the-loop interruptions where a human reviews state before continuing
- Auditing what the agent did by replaying state transitions
# LangGraph with SQLite persistence
from langgraph.checkpoint.sqlite import SqliteSaver
with SqliteSaver.from_conn_string(":memory:") as checkpointer:
graph = workflow.compile(checkpointer=checkpointer)
# Run 1: Start a task with a thread ID
config = {"configurable": {"thread_id": "task-001"}}
result = graph.invoke({"question": "Research AI trends"}, config)
# Run 2: Resume the same task (state is loaded from SQLite)
result = graph.invoke({"user_feedback": "Focus on healthcare AI"}, config)
Common Misconceptions#
Misconception: Agent state is just the conversation history State includes conversation history, but also tool results, task progress, control variables, and any other data the agent needs to reason effectively. Equating state with history misses the working memory aspect that enables complex multi-step tasks.
Misconception: More state is always better Large state objects consume context window tokens, increase LLM inference cost, and can confuse the model with too much irrelevant information. Good state management means keeping only what is currently relevant — pruning old tool results when they are no longer needed.
Misconception: State management is only relevant for complex agents Even simple agents benefit from explicit state. Defining what data flows through your agent makes it easier to debug, test, and reason about behavior. Implicit state (buried in prompt strings) is harder to inspect and maintain.
Related Terms#
- Agent Loop — The execution cycle that reads and updates state
- AI Agent Memory — Long-term persistence of agent knowledge
- Agent Planning — How agents use state to decide next actions
- Context Window — The limit on how much state can fit in one LLM call
- Agentic Workflow — Multi-step workflows where state management is critical
- Understanding AI Agent Architecture — Tutorial covering state management patterns
- LangGraph Multi-Agent Tutorial — LangGraph's stateful graph approach in practice
Frequently Asked Questions#
What is agent state in AI?#
Agent state is the structured data an AI agent maintains across reasoning steps — conversation history, tool call results, task progress, and working memory. It transforms isolated LLM calls into a coherent agent that can complete multi-step tasks without losing context.
What types of data does agent state contain?#
Agent state typically includes: conversation messages, working memory (intermediate tool results), task status (which steps are complete), accumulated context (discovered facts), and control variables (iteration counts, error flags).
How is agent state different from agent memory?#
State is the active data for the current task execution — ephemeral and operational. Memory is information persisted across tasks and sessions. State feeds directly into current reasoning; memory is retrieved and injected into state when relevant.
How do frameworks manage agent state?#
LangGraph uses explicit TypedDict schemas passed through graph nodes. OpenAI Agents SDK passes context as function parameters. CrewAI flows task outputs between crew members. AutoGen manages conversation objects. All frameworks provide structure that makes state explicit and inspectable.