Streaming multiple modes with "subgraphs = True" set in the .stream from the Parent Graph in LangGraph Subgraphs #923

Closed
opened 2026-02-20 17:42:23 -05:00 by yindo · 2 comments
Owner

Originally created by @ashwinashok-thoughtfocus on GitHub (Aug 18, 2025).

Checked other resources

  • This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
  • I added a clear and detailed title that summarizes the issue.
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.

Example Code

from typing import TypedDict
from langchain_openai import ChatOpenAI
from langchain_core.messages import BaseMessage, HumanMessage
from langgraph.graph import StateGraph, START, END
from langgraph.checkpoint.memory import InMemorySaver

# Child graph
class ChildState(TypedDict):
    messages: list[BaseMessage]

def call_llm_model(state: ChildState) -> ChildState:
    model = ChatOpenAI(
        api_key="", # Place your OPENAI_API_KEY
        model="gpt-4o",
        temperature=0,
    )
    subgraph_input = [HumanMessage(content=state["messages"])]
    subgraph_output = model.invoke(subgraph_input)
    return {"messages": subgraph_output.content}

child = StateGraph(ChildState)
child.add_node("child", call_llm_model)
child.add_edge(START, "child")
child.add_edge("child", END)
child_graph = child.compile()

# Parent graph
class ParentState(TypedDict):
    messages: list[BaseMessage]

parent = StateGraph(ParentState)
parent.add_node("child", child_graph)

parent.add_edge(START, "child")
parent.add_edge("child", END)

checkpointer = InMemorySaver()
parent_graph = parent.compile(checkpointer = checkpointer)

config = {"configurable": {"thread_id": "1"}}

for stream_mode, chunk in parent_graph.stream({"messages": "How many states are there in the United States? Which state is the capital of the United States?"},
                                              stream_mode=["messages", "custom"],
                                              subgraphs=True,
                                              config = config):
        if stream_mode == "messages":
            print(chunk)

Error Message and Stack Trace (if applicable)

for stream_mode, chunk in parent_graph.stream({"messages": "How many states are there in the 
    ^^^^^^^^^^^^^^^^^^
United States? Which state is the capital of the United States?"},

ValueError: too many values to unpack (expected 2)

Description

In LangGraph, Implementing streaming outputs on Subgraphs with multiple stream modes.

With stream_mode = ["messages", "custom"] (multiple stream modes) and subgraphs = True properties set in .stream() method on the parent graph does not stream the output.

Attached the code (streaming_subgraphs.py) below in which the .stream method doesn't return stream_mode along with the chunk, which can be used filter the chunks based on the stream mode.

Getting the error mentioned in the Error Message and Stack Trace section

The stream_mode is available inside the chunk item as one of its values

Need a fix here.

System Info

pip install typing langchain-core langchain-openai langgraph

Originally created by @ashwinashok-thoughtfocus on GitHub (Aug 18, 2025). ### Checked other resources - [x] This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/). - [x] I added a clear and detailed title that summarizes the issue. - [x] I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example). - [x] I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue. ### Example Code ```python from typing import TypedDict from langchain_openai import ChatOpenAI from langchain_core.messages import BaseMessage, HumanMessage from langgraph.graph import StateGraph, START, END from langgraph.checkpoint.memory import InMemorySaver # Child graph class ChildState(TypedDict): messages: list[BaseMessage] def call_llm_model(state: ChildState) -> ChildState: model = ChatOpenAI( api_key="", # Place your OPENAI_API_KEY model="gpt-4o", temperature=0, ) subgraph_input = [HumanMessage(content=state["messages"])] subgraph_output = model.invoke(subgraph_input) return {"messages": subgraph_output.content} child = StateGraph(ChildState) child.add_node("child", call_llm_model) child.add_edge(START, "child") child.add_edge("child", END) child_graph = child.compile() # Parent graph class ParentState(TypedDict): messages: list[BaseMessage] parent = StateGraph(ParentState) parent.add_node("child", child_graph) parent.add_edge(START, "child") parent.add_edge("child", END) checkpointer = InMemorySaver() parent_graph = parent.compile(checkpointer = checkpointer) config = {"configurable": {"thread_id": "1"}} for stream_mode, chunk in parent_graph.stream({"messages": "How many states are there in the United States? Which state is the capital of the United States?"}, stream_mode=["messages", "custom"], subgraphs=True, config = config): if stream_mode == "messages": print(chunk) ``` ### Error Message and Stack Trace (if applicable) ```shell for stream_mode, chunk in parent_graph.stream({"messages": "How many states are there in the ^^^^^^^^^^^^^^^^^^ United States? Which state is the capital of the United States?"}, ValueError: too many values to unpack (expected 2) ``` ### Description In LangGraph, Implementing **streaming outputs** on **Subgraphs** with **multiple stream modes**. With **stream_mode = ["messages", "custom"]** (multiple stream modes) and **subgraphs = True** properties set in **.stream()** method on the parent graph does not stream the output. Attached the code (streaming_subgraphs.py) below in which the **.stream** method **doesn't return stream_mode along with the chunk**, which can be used filter the chunks based on the stream mode. Getting the error mentioned in the **Error Message and Stack Trace** section The stream_mode is available inside the chunk item as one of its values Need a fix here. ### System Info pip install typing langchain-core langchain-openai langgraph
yindo added the question label 2026-02-20 17:42:23 -05:00
yindo closed this issue 2026-02-20 17:42:23 -05:00
Author
Owner

@rennard commented on GitHub (Aug 18, 2025):

I believe this isn't a bug and is due to you using both stream_mode=['custom', 'messages'] and subgraphs=True, when both of these are set parentgraph.stream() returns a tuple of the shape '(namespace, mode, data)' as per here whereas your code is trying to unpack to 2 values

  subgraphs: Whether to stream events from inside subgraphs, defaults to False.
      If True, the events will be emitted as tuples `(namespace, data)`,
      or `(namespace, mode, data)` if `stream_mode` is a list,
      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>")`.

      See [LangGraph streaming guide](https://langchain-ai.github.io/langgraph/how-tos/streaming/) for more details.
@rennard commented on GitHub (Aug 18, 2025): I believe this isn't a bug and is due to you using both `stream_mode=['custom', 'messages']` and `subgraphs=True`, when both of these are set `parentgraph.stream()` returns a tuple of the shape '(namespace, mode, data)' as per [here](https://github.com/langchain-ai/langgraph/blob/c0b29a6df50a7ffde4b95121930a0417d1024ac9/libs/langgraph/langgraph/pregel/main.py#L2465 ) whereas your code is trying to unpack to 2 values ``` subgraphs: Whether to stream events from inside subgraphs, defaults to False. If True, the events will be emitted as tuples `(namespace, data)`, or `(namespace, mode, data)` if `stream_mode` is a list, 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>")`. See [LangGraph streaming guide](https://langchain-ai.github.io/langgraph/how-tos/streaming/) for more details. ```
Author
Owner

@sydney-runkle commented on GitHub (Sep 10, 2025):

^^ the above contains the solution for the fix here, you'll need to unpack 3 values :)

@sydney-runkle commented on GitHub (Sep 10, 2025): ^^ the above contains the solution for the fix here, you'll need to unpack 3 values :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#923