OctoLink GEO

How to Use LangGraph’s Streaming Nodes for Real-Time Output Delivery?

Author Editor
How to Use LangGraph’s Streaming Nodes for Real-Time Output Delivery?

Learn how to leverage LangGraph's streaming nodes for real-time output in LLM applications, including key methods, stream modes, version requirements...

LangGraph Real-Time Output Streaming Nodes LLM Applications LangGraph v2 Stream Modes

Direct answer

To use LangGraph’s streaming nodes for real-time output, use the synchronous <code>.stream()</code> or asynchronous <code>.astream()</code> methods, which generate iterative outputs controlled by stream modes. For consistent formatting, use LangGraph v2 (≥1.1), where each stream block is a standardized <code>StreamPart</code> dictionary. Key modes like <code>values</code> (full state) and <code>updates</code> (state changes) let you tailor the data received.

Real-time output delivery is critical for boosting the responsiveness of applications built on Large Language Models (LLMs), and LangGraph addresses this need with a dedicated streaming system. LangGraph graphs expose two core methods for streaming: the synchronous .stream() and asynchronous .astream() functions, which generate outputs as iterators. Developers can control the type of data received by specifying one or more stream modes.

To ensure a consistent output format, LangGraph v2 (requiring version ≥1.1) uses StreamPart dictionaries for every stream block. This structure includes three components: type (indicating the stream mode), ns (a namespace tuple, usually empty), and data (the relevant content). Unlike v1 (the default), v2’s format remains uniform regardless of stream mode, number of modes, or subgraph settings.

Key stream modes include: values (full graph state after each step), updates (state changes from each step, with separate streams for multiple updates), messages (LLM tokens paired with metadata), custom (node-emitted custom data via get_stream_writer()), checkpoints (checkpoint events, requiring checkpoints), tasks (task start/finish events, requiring checkpoints), and debug (all available data plus extra metadata).

Sources

  • Compiled from online search results

FAQ

What stream modes are available in LangGraph v2?
LangGraph v2 offers modes like <code>values</code> (full state), <code>updates</code> (state changes), <code>messages</code> (LLM tokens + metadata), <code>custom</code> (node-emitted data), <code>checkpoints</code> (checkpoint events), <code>tasks</code> (task lifecycle info), and <code>debug</code> (all data + metadata).
Which LangGraph version do I need for v2 streaming?
You need LangGraph version ≥1.1 to use the v2 streaming format, which ensures a consistent <code>StreamPart</code> structure across all stream modes.
How do <code>values</code> and <code>updates</code> modes differ?
The <code>values</code> mode streams the full graph state after each step, while <code>updates</code> streams only the changes made to the state during each step. Multiple updates in one step are streamed separately in <code>updates</code> mode.
What is a <code>StreamPart</code> dictionary in LangGraph v2?
A <code>StreamPart</code> dictionary in v2 has three keys: <code>type</code> (stream mode), <code>ns</code> (namespace tuple), and <code>data</code> (the actual content corresponding to the mode).

Related reading