LangGraph Streaming Outputs
Author: hong-seongmin
Peer Review:
Proofread : Chaeyoon Kim
This is a part of LangChain OpenTutorial
Overview
LangGraph Streaming Outputs explores the step-by-step streaming capabilities within LangGraph.
This approach allows developers to observe and interact with each graph processing stage in real-time, offering insights into the internal workings and progress of graph computations.
Step-by-Step Streaming The streaming functionality breaks down the graph execution into individual steps, providing detailed outputs at each stage. This makes it easier to debug and understand how data flows through the graph, as well as how decisions are made along the way.
Real-Time Feedback By leveraging streaming outputs, users receive immediate feedback from the system. This real-time interaction can greatly enhance the debugging process and the ability to fine-tune graph configurations on the fly.
Enhanced Transparency and Control Streaming outputs offer greater transparency into the execution of LangGraph pipelines. Users can monitor each transformation or computation, enabling more precise control over the process and facilitating a deeper comprehension of complex graph-based workflows.
Table of Contents
References
Environment Setup
Set up the environment. You may refer to Environment Setup for more details.
[Note]
langchain-opentutorialis a package that provides a set of easy-to-use environment setup, useful functions and utilities for tutorials.You can checkout the
langchain-opentutorialfor more details.
Alternatively, environment variables can also be set using a .env file.
[Note]
This is not necessary if you've already set the environment variables in the previous step.
Step-by-step Streaming Output with LangGraph
This time, we'll take a closer look at the stream() output function in LangGraph.
LangGraph's streaming output function provides the ability to stream each step of the graph.
Note: The LangGraph example below is identical to the example from the previous section.

The stream Method of StateGraph
The stream method provides the ability to stream graph steps for a single input.
Parameters
input(Union[dict[str, Any], Any]) : Input to the graphconfig(Optional[RunnableConfig]) : Execution configurationstream_mode(Optional[Union[StreamMode, list[StreamMode]]]) : Output streaming modeoutput_keys(Optional[Union[str, Sequence[str]]]) : Keys to streaminterrupt_before(Optional[Union[All, Sequence[str]]]) : Nodes to interrupt before executioninterrupt_after(Optional[Union[All, Sequence[str]]]) : Nodes to interrupt after executiondebug(Optional[bool]) : Whether to output debug informationsubgraphs(bool) : Whether to stream subgraphs
Returns
Iterator[Union[dict[str, Any], Any]]: Outputs from each step of the graph. The output format depends onstream_mode.
Key Features
Processes graph execution in a streaming manner according to the given configuration
Supports various streaming modes (
values,updates,debug)Manages callbacks and error handling
Handles recursion limits and interruption conditions
Streaming Modes
values: Outputs the current state values at each stepupdates: Outputs only state updates at each stepdebug: Outputs debug events at each step
We set up the config and proceed with streaming output.
Advanced Streaming Options
Advanced streaming options in LangGraph allow for more fine-grained control over how graph execution outputs are handled. By configuring parameters like output_keys, stream_mode, interrupt_before, and interrupt_after, users can tailor the streaming behavior to their specific debugging and monitoring needs.
The output_keys Option
The output_keys option is used to specify which keys to stream.
You can specify it in list format, and it must be one of the keys defined in channels.
Tip
If a large number of State keys is output at each step, this is useful when you only want to stream some of them.
The stream_mode Option
The stream_mode option is used to specify the streaming output mode.
values: Outputs the current state values at each stepupdates: Outputs only state updates at each step (default)
stream_mode = "values"
In values mode, the current state values of each step are output.
Note
event.items()
key: Key of the Statevalue: The value corresponding to the key of the State
stream_mode = "updates"
In updates mode, only the updated State for each step is output.
The output is a dictionary whose key is the node name, and values are the updated outputs.
Note
event.items()
key: The node namevalue: The output of that node in dictionary form (it can have multiple key-value pairs).
The interrupt_before and interrupt_after Options
The interrupt_before and interrupt_after options are used to specify when to interrupt streaming.
interrupt_before: Interrupt streaming before the specified nodeinterrupt_after: Interrupt streaming after the specified node
Last updated