State is everything the agent needs to remember across iterations of a single task run — the accumulated history of decisions, tool results, and progress toward the goal.
What Typically Lives in State
| State Element | Example |
|---|---|
| Goal | The original task, unchanged throughout the run |
| Action/observation history | Every tool call made so far, and its result |
| Current iteration count | Used to enforce the loop's safety limit |
| Intermediate results | Partial findings the agent has gathered so far |
| Status flags | e.g. "awaiting human approval," "encountered an error" |
Simplified Example
state = {
"goal": "Find the total revenue for Q1 2026",
"history": [
{"action": "run_query", "args": {"month": "Jan"}, "result": 45000},
{"action": "run_query", "args": {"month": "Feb"}, "result": 52000},
],
"iteration": 2,
"status": "in_progress"
}
Each iteration of the agent loop reads from and updates this structure.
State vs Memory — A Common Point of Confusion
State is scoped to the current task run — it typically doesn't need to persist once the task completes. Memory is about information that persists across separate runs or conversations — like remembering a user's preferences from a previous session. See Memory vs Context and Agent Memory for the fuller distinction. Some frameworks blur this line by persisting "state" across sessions, which effectively makes it function as memory — the important thing is being deliberate about which behavior you actually want.
Practical Use Case
If an agent's process crashes mid-task, well-designed state (persisted incrementally, not just held in memory) lets the system resume from the last completed step instead of restarting the entire task from scratch — see State Persistence and State Checkpoints.
Common Mistakes
- Keeping state only in memory (a Python variable, for example) with no persistence — any crash loses all progress on a long-running task
- Letting state grow unbounded across many iterations without any summarization/trimming, eventually exceeding the model's context window
- Conflating state with memory and building a system that "remembers" things across unrelated tasks/users unintentionally
Interview Relevance
"What's the difference between an agent's state and its memory?" is a common conceptual-clarity question — state is per-run and typically transient, memory is what deliberately persists beyond a single run.
Practice Question
Design the state structure (in plain fields, not code) for an agent that processes a multi-page document one page at a time.