LangGraphLangGraph 1.2 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
38 small wins to finish your pathNext lesson →

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

Example
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

python
from typing_extensions import TypedDict

class State(TypedDict):
    ticket: str
    category: str

A 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

TypedDictPydantic BaseModel
ValidationNone at runtimeValidates values on input
SpeedFastestSlower
Use whenMost graphsYou 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.
Watch out. The state is your program's memory. If a node works something out and does not return it, it is gone when the function ends.
Try it yourself
  • Add a reply key to State.
  • Make greet return two keys and print the result.

You understood something today that you didn't yesterday.