06. Node's step-by-step streaming output
This time LangGrpah stream() Proceed with a little more detailed explanation of the output function.
LangGraph's streaming output function provides the ability to stream each step of the graph.
Note: The LangGraph example below is the same as the example in the previous section.
Copy
# Configuration file for managing API keys as environment variables
from dotenv import load_dotenv
# Load API key information
load_dotenv()Copy
True Copy
# Set up LangSmith tracking. https://smith.langchain.com
# !pip install -qU langchain-teddynote
from langchain_teddynote import logging
# Enter a project name.
logging.langsmith("CH17-LangGraph-Modules")Copy
Copy

StateGraph stream method
stream methodstream The method provides the ability to stream graph steps for a single input.
parameter
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]]]): Key to streaminterrupt_before(Optional[Union[All, Sequence[str]]]): Nodes to stop before runninginterrupt_after(Optional[Union[All, Sequence[str]]]): Nodes to stop after executiondebug(Optional[bool]): Whether debug information is outputsubgraphs(bool): Whether subgraph streaming
return value
Iterator[Union[dict[str, Any], Any]]: Output of each step of the graph. Output form
stream_modeDepends on
Main features
Stream graph execution according to entered settings
Support for various streaming modes (
values,updates,debug)Callback management and error handling
Treatment of recursive restrictions and suspension conditions
Streaming mode
values: Output the current state value for each stepupdates: Output only status updates for each stepdebug: Output of debug events at each stage
Copy
config Set up and proceed to streaming output.
Copy
Copy
output_keys option
output_keys The option is used to specify the key to stream.
can be specified in list format, One of the keys defined in the channels Should be.
Tip
This is useful if you have a lot of State key outputs every step, and you only want to stream some.
Copy
Copy
Copy
Copy
Copy
Copy
stream_mode option
stream_mode The option is used to specify the streaming output mode.
values: Output the current state value for each stepupdates: Output only status updates for each step (default)
stream_mode = "values"
values Mode outputs the current state value for each step.
Reference
event.items()
key: State key valuevalue: Value for State's key
Copy
Copy
stream_mode = "updates"
updates Mode only exports updated State for each step.
The output is the node name as key, and the updated value is values
dictionaryis.
Reference
event.items()
key: Name of Nodevalue: Output value (dictionary) at that node stage. That is, it is a dictionary with multiple key-value pairs.
Copy
Copy
interrupt_before Wow interrupt_after option
interrupt_before Wow interrupt_after Options are used to specify when streaming stops.
interrupt_before: Stop streaming before the specified nodeinterrupt_after: Stop streaming after the specified node
Copy
Copy
Copy
Copy
Last updated