Streaming from ReAct agents added as tools to a ReAct agent does not work #807

Open
opened 2026-02-20 17:41:52 -05:00 by yindo · 9 comments
Owner

Originally created by @vivek100 on GitHub (Jul 16, 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 langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
from typing import Annotated
from langgraph.prebuilt import InjectedState

def book_hotel(hotel_name: str):
    """Book a hotel"""
    return f"Successfully booked a stay at {hotel_name}."

def book_flight(from_airport: str, to_airport: str):
    """Book a flight"""
    return f"Successfully booked a flight from {from_airport} to {to_airport}."

flight_assistant = create_react_agent(
    model="openai:gpt-4.1-nano",
    tools=[book_flight],
    prompt="You are a flight booking assistant",
    name="flight_assistant"
)

hotel_assistant = create_react_agent(
    model="openai:gpt-4.1-nano",
    tools=[book_hotel],
    prompt="You are a hotel booking assistant",
    name="hotel_assistant"
)

def give_instructions(instructions: str, state: Annotated[dict, InjectedState]):
    """Give instructions to the assistant"""
    llm = ChatOpenAI(model="gpt-4.1-nano")
    response = llm.invoke(instructions)
    return response.content

def flight_assistant_tool(instructions: str, state: Annotated[dict, InjectedState]):
    """Book a flight"""
    response = flight_assistant.invoke({"messages": [{"role": "user", "content": instructions}]})
    return response["messages"][-1].content

def hotel_assistant_tool(instructions: str, state: Annotated[dict, InjectedState]):
    """Book a hotel"""
    response = hotel_assistant.invoke({"messages": [{"role": "user", "content": instructions}]})
    return response["messages"][-1].content

test_supervisor = create_react_agent(
    tools=[give_instructions, flight_assistant_tool, hotel_assistant_tool],
    model=ChatOpenAI(model="gpt-4.1-nano"),
    prompt=(
        "You manage a hotel booking assistant and a"
        "flight booking assistant. Assign work to them."
    )
)

Error Message and Stack Trace (if applicable)


Description

When I run this agent using "langgraoh dev" and use the studio to stream or even in my app using langgraph react sdk. The tool calls thinking texts of the react agents added as tools is not streamed.

Although llm stream from the generate recommendations tool is streamed, which a simple llm call wrapped as a tool, even thought this stream is not saved in final messages array.

But the llm streaming and tool calls of the react agent added as tool is not streamed, this leads to long wait times on screen with nothing happening and app feels very slow.

Tried this with supervisor agent, tool handoff , same behavior the output of sub react agents are not streaming sub react agent info

System Info

System Information

OS: Windows
OS Version: 10.0.26100
Python Version: 3.12.3 (tags/v3.12.3:f6650f9, Apr 9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)]

Package Information

langchain_core: 0.3.68
langchain: 0.3.26
langchain_community: 0.3.27
langsmith: 0.4.4
langchain_openai: 0.3.27
langchain_text_splitters: 0.3.8
langgraph_api: 0.2.78
langgraph_cli: 0.3.4
langgraph_license: Installed. No version info available.
langgraph_runtime: Installed. No version info available.
langgraph_runtime_inmem: 0.3.4
langgraph_sdk: 0.1.72
langgraph_supervisor: 0.0.27
langserve: 0.3.1

Other Dependencies

aiohttp<4.0.0,>=3.8.3: Installed. No version info available.
async-timeout<5.0.0,>=4.0.0;: Installed. No version info available.
blockbuster<2.0.0,>=1.5.24: Installed. No version info available.
click>=8.1.7: Installed. No version info available.
cloudpickle>=3.0.0: Installed. No version info available.
cryptography<45.0,>=42.0.0: Installed. No version info available.
dataclasses-json<0.7,>=0.5.7: Installed. No version info available.
fastapi: 0.116.0
httpx: 0.28.1
httpx-sse<1.0.0,>=0.4.0: Installed. No version info available.
httpx>=0.25.0: Installed. No version info available.
httpx>=0.25.2: Installed. No version info available.
jsonpatch<2.0,>=1.33: Installed. No version info available.
jsonschema-rs<0.30,>=0.20.0: Installed. No version info available.
langchain-anthropic;: Installed. No version info available.
langchain-aws;: Installed. No version info available.
langchain-azure-ai;: Installed. No version info available.
langchain-cohere;: Installed. No version info available.
langchain-community;: Installed. No version info available.
langchain-core<1.0.0,>=0.3.51: Installed. No version info available.
langchain-core<1.0.0,>=0.3.66: Installed. No version info available.
langchain-core>=0.3.40: Installed. No version info available.
langchain-core>=0.3.64: Installed. No version info available.
langchain-deepseek;: Installed. No version info available.
langchain-fireworks;: Installed. No version info available.
langchain-google-genai;: Installed. No version info available.
langchain-google-vertexai;: Installed. No version info available.
langchain-groq;: Installed. No version info available.
langchain-huggingface;: Installed. No version info available.
langchain-mistralai;: Installed. No version info available.
langchain-ollama;: Installed. No version info available.
langchain-openai;: Installed. No version info available.
langchain-perplexity;: Installed. No version info available.
langchain-text-splitters<1.0.0,>=0.3.8: Installed. No version info available.
langchain-together;: Installed. No version info available.
langchain-xai;: Installed. No version info available.
langchain<1.0.0,>=0.3.26: Installed. No version info available.
langgraph-api<0.3.0,>=0.2.67;: Installed. No version info available.
langgraph-checkpoint>=2.0.23: Installed. No version info available.
langgraph-checkpoint>=2.0.25: Installed. No version info available.
langgraph-prebuilt>=0.1.7: Installed. No version info available.
langgraph-runtime-inmem<0.4,>=0.3.0: Installed. No version info available.
langgraph-runtime-inmem<0.4.0,>=0.3.0;: Installed. No version info available.
langgraph-sdk>=0.1.0;: Installed. No version info available.
langgraph-sdk>=0.1.71: Installed. No version info available.
langgraph>=0.2: Installed. No version info available.
langgraph>=0.3.27: Installed. No version info available.
langgraph>=0.3.5: Installed. No version info available.
langsmith-pyo3: Installed. No version info available.
langsmith>=0.1.125: Installed. No version info available.
langsmith>=0.1.17: Installed. No version info available.
langsmith>=0.3.45: Installed. No version info available.
numpy>=1.26.2;: Installed. No version info available.
numpy>=2.1.0;: Installed. No version info available.
openai-agents: Installed. No version info available.
openai<2.0.0,>=1.86.0: Installed. No version info available.
opentelemetry-api: Installed. No version info available.
opentelemetry-exporter-otlp-proto-http: Installed. No version info available.
opentelemetry-sdk: Installed. No version info available.
orjson: 3.10.18
orjson>=3.10.1: Installed. No version info available.
orjson>=3.9.7: Installed. No version info available.
packaging: 24.2
packaging<25,>=23.2: Installed. No version info available.
pydantic: 2.11.7
pydantic-settings<3.0.0,>=2.4.0: Installed. No version info available.
pydantic<3.0.0,>=2.7.4: Installed. No version info available.
pydantic>=2.7.4: Installed. No version info available.
pyjwt>=2.9.0: Installed. No version info available.
pytest: 8.4.1
python-dotenv>=0.8.0;: Installed. No version info available.
PyYAML>=5.3: Installed. No version info available.
requests: 2.32.4
requests-toolbelt: 1.0.0
requests<3,>=2: Installed. No version info available.
rich: Installed. No version info available.
SQLAlchemy<3,>=1.4: Installed. No version info available.
sse-starlette: 2.1.3
sse-starlette<2.2.0,>=2.1.0: Installed. No version info available.
sse-starlette>=2: Installed. No version info available.
starlette>=0.37: Installed. No version info available.
starlette>=0.38.6: Installed. No version info available.
structlog<26,>=24.1.0: Installed. No version info available.
structlog>23: Installed. No version info available.
tenacity!=8.4.0,<10,>=8.1.0: Installed. No version info available.
tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available.
tenacity>=8.0.0: Installed. No version info available.
tiktoken<1,>=0.7: Installed. No version info available.
truststore>=0.1: Installed. No version info available.
typing-extensions>=4.7: Installed. No version info available.
uvicorn>=0.26.0: Installed. No version info available.
watchfiles>=0.13: Installed. No version info available.
zstandard: 0.23.0

Originally created by @vivek100 on GitHub (Jul 16, 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 langchain_openai import ChatOpenAI from langgraph.prebuilt import create_react_agent from typing import Annotated from langgraph.prebuilt import InjectedState def book_hotel(hotel_name: str): """Book a hotel""" return f"Successfully booked a stay at {hotel_name}." def book_flight(from_airport: str, to_airport: str): """Book a flight""" return f"Successfully booked a flight from {from_airport} to {to_airport}." flight_assistant = create_react_agent( model="openai:gpt-4.1-nano", tools=[book_flight], prompt="You are a flight booking assistant", name="flight_assistant" ) hotel_assistant = create_react_agent( model="openai:gpt-4.1-nano", tools=[book_hotel], prompt="You are a hotel booking assistant", name="hotel_assistant" ) def give_instructions(instructions: str, state: Annotated[dict, InjectedState]): """Give instructions to the assistant""" llm = ChatOpenAI(model="gpt-4.1-nano") response = llm.invoke(instructions) return response.content def flight_assistant_tool(instructions: str, state: Annotated[dict, InjectedState]): """Book a flight""" response = flight_assistant.invoke({"messages": [{"role": "user", "content": instructions}]}) return response["messages"][-1].content def hotel_assistant_tool(instructions: str, state: Annotated[dict, InjectedState]): """Book a hotel""" response = hotel_assistant.invoke({"messages": [{"role": "user", "content": instructions}]}) return response["messages"][-1].content test_supervisor = create_react_agent( tools=[give_instructions, flight_assistant_tool, hotel_assistant_tool], model=ChatOpenAI(model="gpt-4.1-nano"), prompt=( "You manage a hotel booking assistant and a" "flight booking assistant. Assign work to them." ) ) ``` ### Error Message and Stack Trace (if applicable) ```shell ``` ### Description When I run this agent using "langgraoh dev" and use the studio to stream or even in my app using langgraph react sdk. The tool calls thinking texts of the react agents added as tools is not streamed. Although llm stream from the generate recommendations tool is streamed, which a simple llm call wrapped as a tool, even thought this stream is not saved in final messages array. But the llm streaming and tool calls of the react agent added as tool is not streamed, this leads to long wait times on screen with nothing happening and app feels very slow. Tried this with supervisor agent, tool handoff , same behavior the output of sub react agents are not streaming sub react agent info ### System Info System Information ------------------ > OS: Windows > OS Version: 10.0.26100 > Python Version: 3.12.3 (tags/v3.12.3:f6650f9, Apr 9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)] Package Information ------------------- > langchain_core: 0.3.68 > langchain: 0.3.26 > langchain_community: 0.3.27 > langsmith: 0.4.4 > langchain_openai: 0.3.27 > langchain_text_splitters: 0.3.8 > langgraph_api: 0.2.78 > langgraph_cli: 0.3.4 > langgraph_license: Installed. No version info available. > langgraph_runtime: Installed. No version info available. > langgraph_runtime_inmem: 0.3.4 > langgraph_sdk: 0.1.72 > langgraph_supervisor: 0.0.27 > langserve: 0.3.1 Other Dependencies ------------------ > aiohttp<4.0.0,>=3.8.3: Installed. No version info available. > async-timeout<5.0.0,>=4.0.0;: Installed. No version info available. > blockbuster<2.0.0,>=1.5.24: Installed. No version info available. > click>=8.1.7: Installed. No version info available. > cloudpickle>=3.0.0: Installed. No version info available. > cryptography<45.0,>=42.0.0: Installed. No version info available. > dataclasses-json<0.7,>=0.5.7: Installed. No version info available. > fastapi: 0.116.0 > httpx: 0.28.1 > httpx-sse<1.0.0,>=0.4.0: Installed. No version info available. > httpx>=0.25.0: Installed. No version info available. > httpx>=0.25.2: Installed. No version info available. > jsonpatch<2.0,>=1.33: Installed. No version info available. > jsonschema-rs<0.30,>=0.20.0: Installed. No version info available. > langchain-anthropic;: Installed. No version info available. > langchain-aws;: Installed. No version info available. > langchain-azure-ai;: Installed. No version info available. > langchain-cohere;: Installed. No version info available. > langchain-community;: Installed. No version info available. > langchain-core<1.0.0,>=0.3.51: Installed. No version info available. > langchain-core<1.0.0,>=0.3.66: Installed. No version info available. > langchain-core>=0.3.40: Installed. No version info available. > langchain-core>=0.3.64: Installed. No version info available. > langchain-deepseek;: Installed. No version info available. > langchain-fireworks;: Installed. No version info available. > langchain-google-genai;: Installed. No version info available. > langchain-google-vertexai;: Installed. No version info available. > langchain-groq;: Installed. No version info available. > langchain-huggingface;: Installed. No version info available. > langchain-mistralai;: Installed. No version info available. > langchain-ollama;: Installed. No version info available. > langchain-openai;: Installed. No version info available. > langchain-perplexity;: Installed. No version info available. > langchain-text-splitters<1.0.0,>=0.3.8: Installed. No version info available. > langchain-together;: Installed. No version info available. > langchain-xai;: Installed. No version info available. > langchain<1.0.0,>=0.3.26: Installed. No version info available. > langgraph-api<0.3.0,>=0.2.67;: Installed. No version info available. > langgraph-checkpoint>=2.0.23: Installed. No version info available. > langgraph-checkpoint>=2.0.25: Installed. No version info available. > langgraph-prebuilt>=0.1.7: Installed. No version info available. > langgraph-runtime-inmem<0.4,>=0.3.0: Installed. No version info available. > langgraph-runtime-inmem<0.4.0,>=0.3.0;: Installed. No version info available. > langgraph-sdk>=0.1.0;: Installed. No version info available. > langgraph-sdk>=0.1.71: Installed. No version info available. > langgraph>=0.2: Installed. No version info available. > langgraph>=0.3.27: Installed. No version info available. > langgraph>=0.3.5: Installed. No version info available. > langsmith-pyo3: Installed. No version info available. > langsmith>=0.1.125: Installed. No version info available. > langsmith>=0.1.17: Installed. No version info available. > langsmith>=0.3.45: Installed. No version info available. > numpy>=1.26.2;: Installed. No version info available. > numpy>=2.1.0;: Installed. No version info available. > openai-agents: Installed. No version info available. > openai<2.0.0,>=1.86.0: Installed. No version info available. > opentelemetry-api: Installed. No version info available. > opentelemetry-exporter-otlp-proto-http: Installed. No version info available. > opentelemetry-sdk: Installed. No version info available. > orjson: 3.10.18 > orjson>=3.10.1: Installed. No version info available. > orjson>=3.9.7: Installed. No version info available. > packaging: 24.2 > packaging<25,>=23.2: Installed. No version info available. > pydantic: 2.11.7 > pydantic-settings<3.0.0,>=2.4.0: Installed. No version info available. > pydantic<3.0.0,>=2.7.4: Installed. No version info available. > pydantic>=2.7.4: Installed. No version info available. > pyjwt>=2.9.0: Installed. No version info available. > pytest: 8.4.1 > python-dotenv>=0.8.0;: Installed. No version info available. > PyYAML>=5.3: Installed. No version info available. > requests: 2.32.4 > requests-toolbelt: 1.0.0 > requests<3,>=2: Installed. No version info available. > rich: Installed. No version info available. > SQLAlchemy<3,>=1.4: Installed. No version info available. > sse-starlette: 2.1.3 > sse-starlette<2.2.0,>=2.1.0: Installed. No version info available. > sse-starlette>=2: Installed. No version info available. > starlette>=0.37: Installed. No version info available. > starlette>=0.38.6: Installed. No version info available. > structlog<26,>=24.1.0: Installed. No version info available. > structlog>23: Installed. No version info available. > tenacity!=8.4.0,<10,>=8.1.0: Installed. No version info available. > tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available. > tenacity>=8.0.0: Installed. No version info available. > tiktoken<1,>=0.7: Installed. No version info available. > truststore>=0.1: Installed. No version info available. > typing-extensions>=4.7: Installed. No version info available. > uvicorn>=0.26.0: Installed. No version info available. > watchfiles>=0.13: Installed. No version info available. > zstandard: 0.23.0
yindo added the bugpending labels 2026-02-20 17:41:52 -05:00
Author
Owner

@asvishnyakov commented on GitHub (Jul 25, 2025):

@vivek100 @samecrowder @sydney-runkle @phvash @hinthornw @eyurtsev

This issue makes streaming broken in langgraph >= 0.5.0 + langgraph-swarm compatible versions. I think it should be prioritized

@asvishnyakov commented on GitHub (Jul 25, 2025): @vivek100 @samecrowder @sydney-runkle @phvash @hinthornw @eyurtsev This issue makes streaming broken in `langgraph` >= 0.5.0 + `langgraph-swarm` compatible versions. I think it should be prioritized
Author
Owner

@asvishnyakov commented on GitHub (Jul 29, 2025):

@vivek100 @samecrowder @sydney-runkle @phvash @hinthornw @eyurtsev Still broken in v0.6.0!

@asvishnyakov commented on GitHub (Jul 29, 2025): @vivek100 @samecrowder @sydney-runkle @phvash @hinthornw @eyurtsev Still broken in v0.6.0!
Author
Owner

@asvishnyakov commented on GitHub (Jul 29, 2025):

@vivek100 Did you found any workaround by any chance?

@asvishnyakov commented on GitHub (Jul 29, 2025): @vivek100 Did you found any workaround by any chance?
Author
Owner

@vivek100 commented on GitHub (Jul 29, 2025):

I tried a few options:-

  1. Was to take control of streaming but then i couldn't use the react sdk and would have to create my own complex logic.
  2. what i actually did was, i just added a nice animation in frontend which waits for the sub agent to respond. And then anything i want to save in context I make sure the tool call which wraps the create react agent returns necessary info to save in context and to generate response for the user.
@vivek100 commented on GitHub (Jul 29, 2025): I tried a few options:- 1. Was to take control of streaming but then i couldn't use the react sdk and would have to create my own complex logic. 2. what i actually did was, i just added a nice animation in frontend which waits for the sub agent to respond. And then anything i want to save in context I make sure the tool call which wraps the create react agent returns necessary info to save in context and to generate response for the user.
Author
Owner

@asvishnyakov commented on GitHub (Jul 29, 2025):

@vivek100 @nfcampos @sydney-runkle #4843 causes this issue

@asvishnyakov commented on GitHub (Jul 29, 2025): @vivek100 @nfcampos @sydney-runkle #4843 causes this issue
Author
Owner

@asvishnyakov commented on GitHub (Jul 29, 2025):

Also this issue seeems to be duplcate of #5249

@asvishnyakov commented on GitHub (Jul 29, 2025): Also this issue seeems to be duplcate of #5249
Author
Owner

@jerson-censys commented on GitHub (Sep 15, 2025):

Any updates on this, I having the same issue:

I’m trying to stream a graph that contains React agents equipped with tools. I followed the documentation and specified that I want different types of stream mode: stream_mode=["messages", "updates", "custom"]. For some reason, nothing gets streamed from “messages”. I’m only able to capture events of type “Updates”. Here is my implementation:

 async for stream_mode, chunk in self.graph.astream(
                initial_state.model_dump(),
                config=config,
                stream_mode=["messages", "updates", "custom"],
            ):
                if stream_mode == "messages":
                    # chunk is a tuple (message_chunk, metadata) for messages mode
                    message_chunk, metadata = chunk
                    logger.info(f"Messages stream event - message_chunk: {message_chunk}, metadata: {metadata}")

                    # Start content block if not already started
                    if not content_started:
                        current_content_block_id = str(uuid.uuid4())
                        content_start_event = ContentBlockStartEvent(
                            block_id=current_content_block_id,
                            content_type="text",
                        )
                        yield self._format_sse_event(content_start_event)
                        content_started = True

                    # Stream text content tokens
                    if hasattr(message_chunk, "content") and message_chunk.content:
                        content_delta_event = ContentBlockDeltaEvent(
                            block_id=current_content_block_id,
                            delta=message_chunk.content,
                        )
                        yield self._format_sse_event(content_delta_event)

                        # Save content to database
                        if initial_state.current_message_id:
                            await self._save_streaming_text_content(
                                message_id=initial_state.current_message_id,
                                text_chunk=message_chunk.content,
                            )

                # Handle graph node completions and responses
                elif stream_mode == "updates":
                    logger.info(f"Node completed with output keys: {chunk}")

                # Handle custom streaming data from tools/nodes
                elif stream_mode == "custom":
                    logger.debug(f"Custom stream event: {chunk}")

Graph:

class Graph:
    def __init__(self) -> None:
        self.graph_builder = StateGraph(ChatState)
        self._setup_nodes()
        self._setup_edges()

        memory = MemorySaver()
        self.graph = self.graph_builder.compile(checkpointer=memory)

    def _setup_nodes(self) -> None:
        """Set up the nodes for the graph."""
        from project.agents.x_agent.agent import x_agent
        from project.agents.a_agent.agent import a_agent
        from project.agents.y_agent.agent import y_agent

        self.graph_builder.add_node("x_agent", x_agent)
        self.graph_builder.add_node("a_agent", a_agent)
        self.graph_builder.add_node("y_agent", y_agent)

    def _setup_edges(self) -> None:
        """Set up the edges for the graph according to the new workflow."""
        # Start with supervisor for routing
        self.graph_builder.add_edge(START, "a_agent")

        self.graph_builder.add_conditional_edges(
            "a_agent",
            self._route_to_agent,
            {
                "other": "y_agent",
                "general": "x_agent",
                "error": END,
            },
        )

        # Both specialized agents go to END
        self.graph_builder.add_edge("y_agent", END)
        self.graph_builder.add_edge("x_agent", END)

    def _route_to_agent(self, state: ChatState) -> str:
        """Route to the appropriate agent based on supervisor decision."""
        if state.errors:
            return "error"

        if state.selected_agent == "y_agent":
            return "y_agent"

        if state.selected_agent == "x_agent":
            return "x_agent"

        return "x_agent"


def get_graph():  # noqa: ANN201
    """Get the graph instance."""
    return Graph().graph

x_agent and y_agent are defined the same way:

from langchain_core.messages import HumanMessage, SystemMessage
from langchain_core.runnables import RunnableConfig
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent

MODEL_NAME = "x-model"


@traceable(
    run_type="llm",
    metadata={
        "agent": "x_agent",
        "ls_model_name": MODEL_NAME,
        "ls_provider": "x-provider",
    },
)
async def x_agent(state: ChatState, config: RunnableConfig) -> ChatState:
    try:
        mcp_tools = await get_tools(state.id)

        llm = ChatOpenAI(
            model=MODEL_NAME,
            base_url=settings.BASE_LLM_ENDPOINT,
            api_key=SecretStr(settings.BASE_LLM_API_KEY),
            streaming=True,  # Enable streaming
            temperature=0.1,
        )

        agent = create_react_agent(
            model=llm,
            tools=mcp_tools,
        )

        messages = []
        messages.append(SystemMessage(content=system_prompt))

        for hist_msg in state.conversation_history:
            if hist_msg["role"] == "user":
                messages.append(HumanMessage(content=hist_msg["content"]))
            elif hist_msg["role"] == "assistant":
                from langchain_core.messages import AIMessage

                ai_msg = AIMessage(content=hist_msg.get("content", ""))

                if "tool_calls" in hist_msg:
                    ai_msg.tool_calls = hist_msg["tool_calls"]

                messages.append(ai_msg)

        current_user_message = user_prompt.format(user_question=state.user_prompt)
        messages.append(HumanMessage(content=current_user_message))

        llm_response = await agent.ainvoke({"messages": messages}, config=config)

        return state.model_copy(
            update={
                "agent_response": llm_response,
                "agent_data": {
                    "agent_type": "x_agent",
                    "tools_available": len(mcp_tools),
                    "streaming_enabled": True,
                },
            },
        )

    except (ValueError, ConnectionError, RuntimeError) as e:
        error_message = f"x_agent failed with error: {e}"
        logger.error(error_message, exc_info=True)

        return state.model_copy(update={"errors": [*state.errors, error_message]})

When I run this I only get two SSE events streamed:

data: {"type": "message_start", "timestamp": "2025-09-15T10:21:08.691839", "message_id": "uuid-x", "conversation_id": "uuid-x"}

data: {"type": "message_stop", "timestamp": "2025-09-15T10:21:14.778332", "message_id": "uuid-x", "stop_reason": "complete", "usage": {"input_tokens": 0, "output_tokens": 0, "total_tokens": 0}}

In my terminal I get:

2025-09-15 10:21:14.777 | INFO     | _stream_graph_execution:349 - Node completed with output keys: 
{
    "state": {
        "user_prompt": "hello!",
        "conversation_history": [{"role": "user", "content": "hello!"}],
        "next_task": None,
        "selected_agent": "x_agent",
        "agent_response": {
            "messages": [
                SystemMessage(
                    ...(system_prompt),
                ),
                HumanMessage(
                    content="hello!",
                    additional_kwargs={},
                    response_metadata={},
                    id="uuid_1",
                ),
                HumanMessage(
                    content='\nAnalyze this question',
                    additional_kwargs={},
                    response_metadata={},
                    id="uuid_2",
                ),
                AIMessage(
                    content="Hello! how can I help you?",
                    additional_kwargs={},
                    response_metadata={
                        "finish_reason": "stop",
                        "model_name": "x-model",
                        "system_fingerprint": "xxxx",
                    },
                    id="uuid_3",
                    usage_metadata={
                        "input_tokens": 6741,
                        "output_tokens": 127,
                        "total_tokens": 6868,
                        "input_token_details": {"audio": 0, "cache_read": 0},
                        "output_token_details": {"audio": 0, "reasoning": 0},
                    },
                ),
            ]
        },
        "agent_data": {
            "agent_type": "x_agent",
            "tools_available": 10,
            "streaming_enabled": True,
        },
        "response_content": "",
        "tool_calls": [],
        "citations": [],
        "token_usage": None,
        "errors": [],
        "created_at": datetime.datetime(
            2025, 9, 15, 17, 21, 9, 156410, tzinfo=datetime.timezone.utc
        ),
        "updated_at": None,
    }
}

What am I doing wrong? Is this related to this issue: https://github.com/langchain-ai/langgraph/issues/5249

My langgraph and python version are:

    "langgraph>=0.6.7",

python 3.13.5

@jerson-censys commented on GitHub (Sep 15, 2025): Any updates on this, I having the same issue: I’m trying to stream a graph that contains React agents equipped with tools. I followed the documentation and specified that I want different types of stream mode: `stream_mode=["messages", "updates", "custom"]`. For some reason, nothing gets streamed from `“messages”`. I’m only able to capture events of type `“Updates”`. Here is my implementation: ```python async for stream_mode, chunk in self.graph.astream( initial_state.model_dump(), config=config, stream_mode=["messages", "updates", "custom"], ): if stream_mode == "messages": # chunk is a tuple (message_chunk, metadata) for messages mode message_chunk, metadata = chunk logger.info(f"Messages stream event - message_chunk: {message_chunk}, metadata: {metadata}") # Start content block if not already started if not content_started: current_content_block_id = str(uuid.uuid4()) content_start_event = ContentBlockStartEvent( block_id=current_content_block_id, content_type="text", ) yield self._format_sse_event(content_start_event) content_started = True # Stream text content tokens if hasattr(message_chunk, "content") and message_chunk.content: content_delta_event = ContentBlockDeltaEvent( block_id=current_content_block_id, delta=message_chunk.content, ) yield self._format_sse_event(content_delta_event) # Save content to database if initial_state.current_message_id: await self._save_streaming_text_content( message_id=initial_state.current_message_id, text_chunk=message_chunk.content, ) # Handle graph node completions and responses elif stream_mode == "updates": logger.info(f"Node completed with output keys: {chunk}") # Handle custom streaming data from tools/nodes elif stream_mode == "custom": logger.debug(f"Custom stream event: {chunk}") ``` Graph: ```python class Graph: def __init__(self) -> None: self.graph_builder = StateGraph(ChatState) self._setup_nodes() self._setup_edges() memory = MemorySaver() self.graph = self.graph_builder.compile(checkpointer=memory) def _setup_nodes(self) -> None: """Set up the nodes for the graph.""" from project.agents.x_agent.agent import x_agent from project.agents.a_agent.agent import a_agent from project.agents.y_agent.agent import y_agent self.graph_builder.add_node("x_agent", x_agent) self.graph_builder.add_node("a_agent", a_agent) self.graph_builder.add_node("y_agent", y_agent) def _setup_edges(self) -> None: """Set up the edges for the graph according to the new workflow.""" # Start with supervisor for routing self.graph_builder.add_edge(START, "a_agent") self.graph_builder.add_conditional_edges( "a_agent", self._route_to_agent, { "other": "y_agent", "general": "x_agent", "error": END, }, ) # Both specialized agents go to END self.graph_builder.add_edge("y_agent", END) self.graph_builder.add_edge("x_agent", END) def _route_to_agent(self, state: ChatState) -> str: """Route to the appropriate agent based on supervisor decision.""" if state.errors: return "error" if state.selected_agent == "y_agent": return "y_agent" if state.selected_agent == "x_agent": return "x_agent" return "x_agent" def get_graph(): # noqa: ANN201 """Get the graph instance.""" return Graph().graph ``` x_agent and y_agent are defined the same way: ```python from langchain_core.messages import HumanMessage, SystemMessage from langchain_core.runnables import RunnableConfig from langchain_openai import ChatOpenAI from langgraph.prebuilt import create_react_agent MODEL_NAME = "x-model" @traceable( run_type="llm", metadata={ "agent": "x_agent", "ls_model_name": MODEL_NAME, "ls_provider": "x-provider", }, ) async def x_agent(state: ChatState, config: RunnableConfig) -> ChatState: try: mcp_tools = await get_tools(state.id) llm = ChatOpenAI( model=MODEL_NAME, base_url=settings.BASE_LLM_ENDPOINT, api_key=SecretStr(settings.BASE_LLM_API_KEY), streaming=True, # Enable streaming temperature=0.1, ) agent = create_react_agent( model=llm, tools=mcp_tools, ) messages = [] messages.append(SystemMessage(content=system_prompt)) for hist_msg in state.conversation_history: if hist_msg["role"] == "user": messages.append(HumanMessage(content=hist_msg["content"])) elif hist_msg["role"] == "assistant": from langchain_core.messages import AIMessage ai_msg = AIMessage(content=hist_msg.get("content", "")) if "tool_calls" in hist_msg: ai_msg.tool_calls = hist_msg["tool_calls"] messages.append(ai_msg) current_user_message = user_prompt.format(user_question=state.user_prompt) messages.append(HumanMessage(content=current_user_message)) llm_response = await agent.ainvoke({"messages": messages}, config=config) return state.model_copy( update={ "agent_response": llm_response, "agent_data": { "agent_type": "x_agent", "tools_available": len(mcp_tools), "streaming_enabled": True, }, }, ) except (ValueError, ConnectionError, RuntimeError) as e: error_message = f"x_agent failed with error: {e}" logger.error(error_message, exc_info=True) return state.model_copy(update={"errors": [*state.errors, error_message]}) ``` When I run this I only get two SSE events streamed: ```json data: {"type": "message_start", "timestamp": "2025-09-15T10:21:08.691839", "message_id": "uuid-x", "conversation_id": "uuid-x"} data: {"type": "message_stop", "timestamp": "2025-09-15T10:21:14.778332", "message_id": "uuid-x", "stop_reason": "complete", "usage": {"input_tokens": 0, "output_tokens": 0, "total_tokens": 0}} ``` In my terminal I get: ```shell 2025-09-15 10:21:14.777 | INFO | _stream_graph_execution:349 - Node completed with output keys: { "state": { "user_prompt": "hello!", "conversation_history": [{"role": "user", "content": "hello!"}], "next_task": None, "selected_agent": "x_agent", "agent_response": { "messages": [ SystemMessage( ...(system_prompt), ), HumanMessage( content="hello!", additional_kwargs={}, response_metadata={}, id="uuid_1", ), HumanMessage( content='\nAnalyze this question', additional_kwargs={}, response_metadata={}, id="uuid_2", ), AIMessage( content="Hello! how can I help you?", additional_kwargs={}, response_metadata={ "finish_reason": "stop", "model_name": "x-model", "system_fingerprint": "xxxx", }, id="uuid_3", usage_metadata={ "input_tokens": 6741, "output_tokens": 127, "total_tokens": 6868, "input_token_details": {"audio": 0, "cache_read": 0}, "output_token_details": {"audio": 0, "reasoning": 0}, }, ), ] }, "agent_data": { "agent_type": "x_agent", "tools_available": 10, "streaming_enabled": True, }, "response_content": "", "tool_calls": [], "citations": [], "token_usage": None, "errors": [], "created_at": datetime.datetime( 2025, 9, 15, 17, 21, 9, 156410, tzinfo=datetime.timezone.utc ), "updated_at": None, } } ``` What am I doing wrong? Is this related to this issue: https://github.com/langchain-ai/langgraph/issues/5249 My langgraph and python version are: ``` "langgraph>=0.6.7", ``` `python 3.13.5`
Author
Owner

@sydney-runkle commented on GitHub (Nov 7, 2025):

What happens if you use subgraphs=True in your call to astream?

@sydney-runkle commented on GitHub (Nov 7, 2025): What happens if you use `subgraphs=True` in your call to `astream`?
Author
Owner

@bgkavinga commented on GitHub (Nov 7, 2025):

langchain.agents.create_agent returns a graph. https://reference.langchain.com/python/langchain/agents/#langchain.agents.create_agent

You have to pass subgraphs=True to make it streaming, as suggested by @sydney-runkle

@bgkavinga commented on GitHub (Nov 7, 2025): langchain.agents.create_agent returns a graph. https://reference.langchain.com/python/langchain/agents/#langchain.agents.create_agent You have to pass subgraphs=True to make it streaming, as suggested by @sydney-runkle
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#807