Separating State, Message and Custom Events in a LangGraph Stream
A checklist for stream modes, v2 chunk shapes and frontend output when consuming a graph stream.
Prerequisites and input · Engineering checks · 1. List the output types the frontend needs
At a glance
When an application consumes a graph stream, the common mistake is handling state updates, model tokens and custom progress in one undifferentiated path. This procedure follows the stream-mode interface in the supplied LangGraph streaming documentation and lists steps for mode choice, chunk shape and frontend output. The page also says event streaming is recommended for new applications; this text covers only the stream-mode part.
Runtime and applicability
- Article type
- Engineering practice
- Verified
- Applies to
- LangGraph Separating State, Message and Custom Events in a LangGraph Stream
Execution locations and responsibilities
- LangGraph graph runtime and application host Use the workflow below to distinguish responsibilities of the caller, runtime, and external actions.
Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.
When to use
- The documented modes are
values,updates,messages,custom,checkpoints,tasksanddebug.valuesgives full state after each step,updatesgives each node's changes with its name,messagesgives two-item tuples from model output, andcustomcarries data written from nodes. Withversion="v2", every chunk is a dictionary withtype,nsanddata, so code can branch ontype.
When not to use
messagescarries tokens only from LangChain-integrated models; for a model outside that interface, the documentation suggests writing throughcustomyourselfnostreamonly omits tokens frommessages; the call still executes and returns its result, and content written to state can still reach the frontend throughvaluesandupdatescheckpointsandtasksare unavailable without a checkpointer- This text does not cover the
stream_eventsinterface of v1.2 event streaming, which is a separate projection-based API
Prerequisites and input
- You know what the frontend must show, such as state, incremental text, progress or debug data
- You can confirm the LangGraph version meets the documented requirement for the v2 format
Engineering checks
Modes and chunk shape — The documented modes are values, updates, messages, custom, checkpoints, tasks and debug. values gives full state after each step, updates gives each node's changes with its name, messages gives two-item tuples from model output, and custom carries data written from nodes. With version="v2", every chunk is a dictionary with type, ns and data, so code can branch on type.
Filtering and origin — Metadata on messages chunks supports filtering: model tags distinguish invocations and langgraph_node distinguishes nodes. Invocations tagged nostream still run and produce output; only their tokens are left out of messages, and if their result is written to state it can still appear in values and updates. To see subgraph output from a parent graph, set subgraphs=True; an empty ns means the root graph and a non-empty one is a subgraph path.
Preconditions and compatibility — checkpoints and tasks need a checkpointer; custom must appear in the mode list to receive custom data; v2 needs LangGraph 1.1 or later. v1 is the default and differs: a single mode returns raw data and several modes return tuples. Async code on Python below 3.11 must pass RunnableConfig manually and cannot use get_stream_writer in async nodes, so a writer argument is passed instead.
1. List the output types the frontend needs
Where: the stream-consuming code in the application host and the frontend contract. Input: what the interface displays. Action: sort items into full state, node updates, model tokens, custom progress, checkpoint and task information, and debug information. Completion check: each item maps to one mode. Stop condition: record any need without a matching mode as a gap rather than assuming a mode exists.
2. Fix the stream_mode list and format version
Where: the stream or astream call. Input: the mapping from step one and the LangGraph version. Action: put the needed modes in the stream_mode list and pass version="v2" explicitly. Completion check: one chunk format covers single mode, multiple modes and subgraphs. Stop condition: if the version does not support v2, write v1 branches separately: raw data for a single mode, mode/data tuples for multiple modes, and the documented namespace tuple or triple when subgraphs are enabled or upgrade first.
3. Branch on type and verify the data shape
Where: the chunk-handling loop. Input: chunk dictionaries. Action: for values read the full state, for updates iterate node names and updates, for messages unpack the message chunk and metadata, for custom read whatever was written. Completion check: each branch reads only its own mode's data shape. Stop condition: if an unhandled type appears, log it and add a branch instead of silently dropping it.
4. Add origin filters and subgraph visibility
Where: the messages branch and the stream call arguments. Input: model tags, node names, whether subagents are involved, and which state keys or custom fields count as internal. Action: filter by tag or langgraph_node in the metadata; add the nostream tag to internal-only model calls, which only keeps that call's tokens out of messages; if internal content must not reach the frontend, that is an application design requirement, so filter by field in the handling code for values, updates, custom and debug-style channels instead of relying on nostream alone; set subgraphs=True and read ns when subgraph output is needed. Completion check: messages carries no tokens from nostream calls, no other enabled channel passes internal fields to the frontend, and no subagent tokens are missing. Stop condition: do not ship while values, updates, custom or debug is enabled without field filtering for internal content; if messages goes quiet after an agent is wrapped as a node, check for a missing subgraphs=True first.
5. Agree on the custom event structure
Where: nodes or tools that use get_stream_writer, and the frontend custom branch. Input: progress data or chunks from an external streaming client. Action: agree on the dictionary keys written, such as status text or a progress type, and make sure stream_mode includes custom. Completion check: the keys the frontend reads match the keys nodes write. Stop condition: in async code on Python below 3.11, do not use get_stream_writer; pass the writer argument as the documentation describes.
6. Check checkpointer-dependent modes and interrupts
Where: graph compile step and invocation configuration. Input: whether checkpoints, tasks or debug are enabled. Action: confirm a checkpointer is configured for modes that need one; v2 invoke in its default values mode returns GraphOutput with .value and .interrupts; non-values modes return list[StreamPart], handled as a part list without accessing GraphOutput properties. Completion check: state and interrupt metadata are no longer mixed in one dictionary. Stop condition: if checkpoint events are required but no checkpointer exists, stop and add the configuration.
Task example
This is a hand-made hypothetical walkthrough, not actual output. Suppose a graph has two nodes, and the frontend must show node progress plus the answer as it is generated. You set stream_mode to updates, messages and custom, and pass version="v2". Expected: a chunk with type equal to updates when each node finishes; messages chunks while the model generates, whose data unpacks into a chunk and metadata; and node-written progress arriving as custom chunks. These are expectations inferred from the documented shapes and must be confirmed in your own runtime.
Completion checks
- Each frontend item maps to a stream mode, and
version="v2"is passed explicitly - Branches depend only on
type, and each reads the data shape its mode describes - Internal model calls carry
nostream, other enabled channels filter internal fields, andsubgraphs=Trueis set where subgraph output is needed - The
customkey convention, checkpointer precondition and Python version limit are recorded
Verification scope
This text is based on reading the supplied LangGraph streaming documentation only. Installation, login, API execution and output were not tested. Model names and LangSmith links in the source are outside this topic, and event streaming is mentioned in the source but not expanded here.
Sources
All links are official pages; verification dates are listed per source, and links point to the version checked.