stream()
method:
Mode | Description |
---|---|
values | Streams the full value of the state after each step of the graph. |
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. |
custom | Streams custom data from inside your graph nodes. |
messages | Streams 2-tuples (LLM token, metadata) from any graph nodes where an LLM is invoked. |
debug | Streams as much information as possible throughout the execution of the graph. |
stream()
method with streamMode: "updates"
. This emits an event after every agent step.
For example, if you have an agent that calls a tool once, you should see the following updates:
streamMode: "messages"
:
writer
parameter from the configuration.
writer
parameter to your tool, you won’t be able to invoke the tool outside of a LangGraph execution context without providing a writer function.streamMode: ["updates", "messages", "custom"]
:
.stream()
method to yield streamed outputs as iterators.
Extended example: streaming updates
streamMode: "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.streamMode
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.subgraphs: true
in the .stream()
method of the parent graph. This will stream outputs from both the parent graph and any subgraphs.
The outputs will be streamed as tuples [namespace, data]
, where namespace
is a tuple with the path to the node where a subgraph is invoked, e.g. ["parent_node:<task_id>", "child_node:<task_id>"]
.
subgraphs: true
to stream outputs from subgraphs.Extended example: streaming from subgraphs
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
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
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.
If your LLM is not available as a LangChain integration, you can stream its outputs using custom
mode instead. See use with any LLM for details.
.invoke
rather than .stream
.[messageChunk, metadata]
where messageChunk
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 to filter the streamed tokens by LLM invocation.
streamMode
is set to “messages” to stream LLM tokens. The metadata
contains information about the LLM invocation, including the tags.tags
field in the metadata to only include the tokens from the LLM invocation with the “joke” tag.Extended example: filtering by tags
stream_mode="messages"
and filter the outputs by the langgraph_node
field in the streamed metadata:
[messageChunk, metadata]
where messageChunk
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.langgraph_node
field in the metadata to only include the tokens from the writePoem
node.Extended example: streaming LLM tokens from specific nodes
[messageChunk, metadata]
where messageChunk
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.langgraph_node
field in the metadata to only include the tokens from the writePoem
node.writer
parameter from the LangGraphRunnableConfig
to emit custom data.streamMode: "custom"
when calling .stream()
to get the custom data in the stream. You can combine multiple modes (e.g., ["updates", "custom"]
), but at least one must be "custom"
.streamMode: "custom"
to receive the custom data in the stream.streamMode: "custom"
to stream data from any LLM API — even if that API does not implement the LangChain chat model interface.
This lets you integrate raw LLM clients or external services that provide their own streaming interfaces, making LangGraph highly flexible for custom setups.
streamMode: "custom"
to receive the custom data in the stream.Extended example: streaming arbitrary chat model
streaming: false
when initializing the model.