Extended example: streaming updates
client.runs.stream()
method returns an iterator that yields streamed outputs.stream_mode="updates"
to stream only the updates to the graph state after each node. Other stream modes are also available. See supported stream modes for details.Mode | Description | LangGraph Library Method |
---|---|---|
values | Stream the full graph state after each super-step. | .stream() / .astream() with stream_mode="values" |
updates | Streams the updates to the state after each step of the graph. If multiple updates are made in the same step (e.g., multiple nodes are run), those updates are streamed separately. | .stream() / .astream() with stream_mode="updates" |
messages-tuple | Streams LLM tokens and metadata for the graph node where the LLM is invoked (useful for chat apps). | .stream() / .astream() with stream_mode="messages" |
debug | Streams as much information as possible throughout the execution of the graph. | .stream() / .astream() with stream_mode="debug" |
custom | Streams custom data from inside your graph | .stream() / .astream() with stream_mode="custom" |
events | Stream all events (including the state of the graph); mainly useful when migrating large LCEL apps. | .astream_events() |
stream_mode
parameter to stream multiple modes at once.
The streamed outputs will be tuples of (mode, chunk)
where mode
is the name of the stream mode and chunk
is the data streamed by that mode.
updates
and values
to stream the state of the graph as it executes.
updates
streams the updates to the state after each step of the graph.values
streams the full value of the state after each step of the graph.Example graph
None
instead of thread_id
when streaming.updates
values
subgraphs=True
in the .stream()
method of the parent graph. This will stream outputs from both the parent graph and any subgraphs.
stream_subgraphs=True
to stream outputs from subgraphs.Extended example: streaming from subgraphs
stream_subgraphs=True
to stream outputs from subgraphs.debug
streaming mode to stream as much information as possible throughout the execution of the graph. The streamed outputs include the name of the node as well as the full state.
messages-tuple
streaming mode to stream Large Language Model (LLM) outputs token by token from any part of your graph, including nodes, tools, subgraphs, or tasks.
The streamed output from messages-tuple
mode is a tuple (message_chunk, metadata)
where:
message_chunk
: the token or message segment from the LLM.metadata
: a dictionary containing details about the graph node and LLM invocation.Example graph
.invoke
rather than .stream
.(message_chunk, metadata)
where message_chunk
is the token streamed by the LLM and metadata
is a dictionary with information about the graph node where the LLM was called and other information.tags
with LLM invocations.stream_mode="messages"
and filter the outputs by the langgraph_node
field in the streamed metadata.None
instead of a thread_id
UUID.client.runs.join_stream
method:
run_id
of an existing run you want to join..join_stream
, output is not buffered, so any output produced before joining will not be received.