Streaming: watch a run happen
graph.stream() yields a run as it happens. stream_mode picks what you see: "updates" for each node's change, "values" for the whole state, "messages" for model tokens.
Last updated: 27 Sep, 2026 · LangGraph 1.2
invoke waits for the whole run and returns the final state. stream hands you each step as it finishes, which is how a UI shows progress and tokens as they arrive.
The graph.stream API
for chunk in graph.stream(inputs, stream_mode="updates"):
print(chunk) # {node_name: what_that_node_changed}The example runs one node and watches its update arrive. Build it in four small steps.
The state
from typing_extensions import TypedDict
from langgraph.graph import StateGraph, START, END
class State(TypedDict):
topic: str # what to joke about
joke: str # the node fills this inThe state has two fields: topic is given at the start, and joke is what the node writes.
The make node
def make(state):
return {"joke": f"a joke about {state['topic']}"} # writes the joke fieldThe make node reads topic and returns a new joke. This is the one change the run produces.
Building the graph
builder = StateGraph(State)
builder.add_node("make", make)
builder.add_edge(START, "make") # START -> make -> END
builder.add_edge("make", END)One node again, running from START to make to END.
Streaming the run
for chunk in builder.compile().stream(
{"topic": "cats", "joke": ""}, stream_mode="updates" # yield each node's change
):
print(chunk)streamhands you each step as it finishes instead of waiting for the whole run.- In
"updates"mode each chunk is{node_name: the_change}. - There is one node, so the loop prints one chunk: the
makenode's newjoke.
Streaming a run end to end
The four steps in one file.
from typing_extensions import TypedDict
from langgraph.graph import StateGraph, START, END
class State(TypedDict):
topic: str
joke: str
def make(state):
return {"joke": f"a joke about {state['topic']}"}
builder = StateGraph(State)
builder.add_node("make", make)
builder.add_edge(START, "make")
builder.add_edge("make", END)
for chunk in builder.compile().stream({"topic": "cats", "joke": ""}, stream_mode="updates"):
print(chunk)What each chunk showed
- In "updates" mode each chunk is
{node_name: the_change}, so you see themakenode's update as it happens. - "values" mode would yield the whole state after each step instead.
- "messages" mode yields model tokens as 2-tuples, which is how a chat streams a reply word by word.
Stream modes
| stream_mode | Yields |
|---|---|
"updates" | Each node's change, keyed by node name |
"values" | The full state after each step |
"messages" | Model tokens as they arrive |
When to stream a run
- Showing progress in a UI while a multi-step run works.
- Streaming a model's reply token by token instead of waiting for the whole answer.
stream_mode=["updates", "messages"], to get both; each chunk then says which mode it came from.Related
- Previous: Review and edit an action before it runs
- Next: Time travel: replay a past run
- Reference: Streaming
- Switch to
stream_mode="values"and compare the chunks. - Add a second node and watch two update chunks arrive.
Slow is fine. Stopping is the only problem.