Nodes, Edges and State
Define a TypedDict state, write node functions that mutate it, and connect them with directed edges.
The State Object
Every LangGraph agent has a typed state — usually a TypedDict:
from typing import TypedDict
from typing_extensions import Annotated
import operator
class AgentState(TypedDict):
messages: Annotated[list, operator.add] # appends instead of replaces
plan: str
answer: strHow State Updates Work
Each node returns a partial dict. LangGraph:
- Reads current state
- Calls the node with it
- Merges the returned partial dict back
For list fields with operator.add, new items append instead of overwriting.