Home/Agentic AI/LangGraph/State Management

LangGraph for Workflows

Master stateful, graph-based agent workflows with cycles, branching, and human-in-the-loop patterns

Managing Persistent State

LangGraph maintains a shared state object that flows through every node. Each node can read from and write to this state. The state persists across the entire graph execution, enabling nodes to communicate and build upon each other's work.

Interactive: State Evolution Simulator

Step 0/4
Current State:
{
"messages": [0 items],
"tools_used": [],
"iteration": 0
}
💡 Each node receives the full state, modifies it, and passes it to the next node

🔧 State Schema

Define Your State Structure

Use TypeScript interfaces or Python TypedDict to define state shape:

from typing import TypedDict, List
class AgentState(TypedDict):
messages: List[str]
tools_used: List[str]
iteration: int
final_answer: str

State Reducers

Control how state updates merge (append vs replace):

Append Mode
Add to list: messages.append(new_msg)
Replace Mode
Overwrite: iteration = new_iteration

💡 State Persistence Benefits

Multi-Turn Context: Access full conversation history at any node
Intermediate Results: Store tool outputs for later nodes to use
Debugging: Inspect state at any point to understand workflow execution
Checkpointing: Save state to database, resume workflow later (great for long-running tasks)
Prev