By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
Every graph declares exactly one state schema, usually a TypedDict. Each node receives the current state and returns a partial update — a plain dict containing only the keys it changed. The runtime merges that update back into the state. Nodes never pass objects to each other and never call each other; if two nodes need to communicate, the fact goes into the schema.
That one rule is what makes a graph debuggable. Every hand-off is a named field you can print, snapshot, assert on and review. Compare it with a chain of function calls passing custom objects: the compiler cannot tell you what a downstream step depends on, and neither can a trace.
The example below is a complete three-node graph. classify writes one key, extract_order writes another, and draft reads both. Notice that no node returns the whole state — each returns the smallest update it is responsible for, and the runtime assembles the final dict.
from typing import TypedDict
from langgraph.graph import END, START, StateGraph
class SupportState(TypedDict):
message: str
intent: str | None
order_id: str | None
reply: str | None
def classify(state: SupportState) -> dict:
if "refund" in state["message"].lower():
return {"intent": "refund"}
return {"intent": "order_status"}
def extract_order(state: SupportState) -> dict:
for word in state["message"].split():
candidate = word.lstrip("#")
if candidate.isdigit():
return {"order_id": candidate}
return {"order_id": None}
def draft(state: SupportState) -> dict:
return {"reply": f"Routed {state['intent']} for order {state['order_id']}."}
builder = StateGraph(SupportState)
builder.add_node("classify", classify)
builder.add_node("extract_order", extract_order)
builder.add_node("draft", draft)
builder.add_edge(START, "classify")
builder.add_edge("classify", "extract_order")
builder.add_edge("extract_order", "draft")
builder.add_edge("draft", END)
graph = builder.compile()
final = graph.invoke(
{
"message": "Please refund order 4521",
"intent": None,
"order_id": None,
"reply": None,
}
)
print(final["intent"], final["order_id"])
print(final["reply"])Internally, each key in the schema is a channel. An input, or a node's returned dict, writes to channels; the runtime applies the channel's reducer to combine writes. By default a channel holds one value and the newest write wins. Annotating a key with a reducer changes that rule: add_messages appends message-like values (and updates messages by id), operator.add concatenates lists, and a custom function can merge dicts or track the maximum.
| State field | Merge rule | Safe for parallel writers? | Typical use |
|---|---|---|---|
intent: str | None | Newest value replaces | No — two writers in one step is a conflict | Routing facts and decisions |
messages: Annotated[list, add_messages] | Append, or replace by message id | Yes | Conversation history |
findings: Annotated[list[str], add] | Concatenate the lists | Yes | Fan-in results from parallel branches |
attempts: int | Newest value replaces | No — carry a counter in one node | Loop progress and budgets |
Two nodes writing the same plain key in the same superstep is an error, not a race: the runtime raises InvalidUpdateError because it cannot choose a winner. That error is a design signal — either one node should own the key, or the key needs a reducer. Lesson 5 uses reducers deliberately for parallel branches.
order_id, not a serialized order object; fetch the rest in the node that needs it.str | None documents that a value may be absent; it also makes partial updates safe to reason about.reply built from intent and tool data does not need to be in state unless a later edge or a human needs to inspect it.Key takeaways
A graph has one TypedDict state schema; nodes return partial dicts that the runtime merges.
Each state key is a channel: the newest write wins by default, and a reducer can append, concatenate or merge.
Two unwritten-reducer parallel writers to one key is an InvalidUpdateError — fix the design, not the error.
Keep state small, typed and secret-free; ids and routing facts belong here, blobs and secrets do not.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.