State: the dictionary every node shares
The state is the one dictionary that travels between the nodes of a graph. Every node is handed it and returns the keys it wants to change.
Last updated: 27 Sep, 2026 · LangGraph 1.2
Before any graph, a node is only a function that takes a dictionary and returns a dictionary. Start there.
A node reading and returning state
def greet(state):
return {"greeting": "Hello!"}
print(greet({}))Why the argument is called state
It takes one argument and returns a dictionary. Nothing clever yet. The argument is called state because in a graph one dictionary is passed from function to function, and that dictionary is the state.
Describing the shape with TypedDict
from typing_extensions import TypedDict
class State(TypedDict):
ticket: str
category: strA TypedDict says which keys the state has and their types. It is the recommended shape: plain dictionary typing, no runtime cost. LangGraph also accepts a Pydantic model when you want values validated as they come in, at some speed cost.
TypedDict vs Pydantic for state
| TypedDict | Pydantic BaseModel | |
|---|---|---|
| Validation | None at runtime | Validates values on input |
| Speed | Fastest | Slower |
| Use when | Most graphs | You want bad input caught early |
When you declare a state
- Every graph declares a state; it is the first thing you write.
- Anything one node must pass to another goes in the state.
Related
- Previous: Installation and setup
- Next: StateGraph: your first graph
- Reference: Graph API: state
- Add a
replykey toState. - Make
greetreturn two keys and print the result.
You understood something today that you didn't yesterday.