Node name of the agent graph created by prebuilt.create_react_agent #832

Closed
opened 2026-02-20 17:41:59 -05:00 by yindo · 10 comments
Owner

Originally created by @richpin on GitHub (Jul 23, 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

import asyncio
from typing import Annotated
from langchain_core.tools import InjectedToolCallId, tool
from langchain_openai import ChatOpenAI
from langchain_tavily import TavilySearch
from langgraph.graph import MessagesState, StateGraph, START, END
from langgraph.prebuilt import InjectedState, create_react_agent
from langchain_core.messages import HumanMessage
from langgraph.types import Command

# ---- tools ----
@tool
def add(x: int, y: int) -> int:
    """Adds two integers and returns the result."""
    return x + y

# ---- llm & agents ----
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0, streaming=True)

search_agent  = create_react_agent(llm, [TavilySearch(max_results=3, topic="general")], name="search_agent")
math_agent   = create_react_agent(llm, [add],  name="math_agent")

# ---- handoff tool -----
def create_handoff_tool(*, agent_name: str, description: str | None = None):
    name = f"transfer_to_{agent_name}"
    description = description or f"Ask {agent_name} for help."

    @tool(name, description=description)
    def handoff_tool(
        state: Annotated[MessagesState, InjectedState],
        tool_call_id: Annotated[str, InjectedToolCallId],
    ) -> Command:
        tool_message = {
            "role": "tool",
            "content": f"Successfully transferred to {agent_name}",
            "name": name,
            "tool_call_id": tool_call_id,
        }

        return Command(
            goto=agent_name, 
            update={**state, "messages": state["messages"] + [tool_message]},  # (2)!
            graph=Command.PARENT, 
        )

    return handoff_tool

# ---- supervisor agent ----
supervisor_agent = create_react_agent(
    model=llm,
    tools=[
        create_handoff_tool(agent_name="search_agent"),
        create_handoff_tool(agent_name="math_agent"),
    ],
     prompt=(
        "You are a supervisor managing two agents:\n"
        "- a search agent. Assign search-related tasks to this agent\n"
        "- a math agent. Assign math-related tasks to this agent\n"
        "Assign work to one agent at a time, do not call agents in parallel.\n"
        "Do not do any work yourself."
    ),
    name="supervisor"
)

# ---- mulit-agent graph -----
graph = (
    StateGraph(MessagesState)
    .add_node(supervisor_agent, destinations=("search_agent", "math_agent", END))
    .add_node(search_agent)
    .add_node(math_agent)
    .add_edge(START, "supervisor")
    .add_edge("search_agent", "supervisor")
    .add_edge("math_agent", "supervisor")
    .compile()
)

# ---- streaming run ----
async def streaming(payload):
    async for event in graph.astream_events(payload, stream_mode="messages"):
        if(event["event"] == "on_chat_model_stream"):
            print(event["data"])
            print(event["metadata"])
            print()

asyncio.run(streaming({"messages":[HumanMessage(content="Find the distances from Seoul to Busan and Seoul to Incheon, and calculate the total distance.")]}))

Error Message and Stack Trace (if applicable)

{'chunk': AIMessageChunk(content=' ', additional_kwargs={}, response_metadata={}, id='run--e171be32-610d-483d-9ed1-adba4dcd2e87')}
{'langgraph_step': 1, 'langgraph_node': 'agent', 'langgraph_triggers': ('branch:to:agent',), 'langgraph_path': ('__pregel_pull', 'agent'), 'langgraph_checkpoint_ns': 'supervisor:4aa19ce2-999c-fc11-7546-bfd1f675e211|agent:19b8dfec-e2e8-234d-4b86-f2f9a1168bf2', 'checkpoint_ns': 'supervisor:4aa19ce2-999c-fc11-7546-bfd1f675e211', 'ls_provider': 'openai', 'ls_model_name': 'gpt-3.5-turbo', 'ls_model_type': 'chat', 'ls_temperature': 0.0}

{'chunk': AIMessageChunk(content='352', additional_kwargs={}, response_metadata={}, id='run--e171be32-610d-483d-9ed1-adba4dcd2e87')}
{'langgraph_step': 1, 'langgraph_node': 'agent', 'langgraph_triggers': ('branch:to:agent',), 'langgraph_path': ('__pregel_pull', 'agent'), 'langgraph_checkpoint_ns': 'supervisor:4aa19ce2-999c-fc11-7546-bfd1f675e211|agent:19b8dfec-e2e8-234d-4b86-f2f9a1168bf2', 'checkpoint_ns': 'supervisor:4aa19ce2-999c-fc11-7546-bfd1f675e211', 'ls_provider': 'openai', 'ls_model_name': 'gpt-3.5-turbo', 'ls_model_type': 'chat', 'ls_temperature': 0.0}

{'chunk': AIMessageChunk(content=' kilometers', additional_kwargs={}, response_metadata={}, id='run--e171be32-610d-483d-9ed1-adba4dcd2e87')}
{'langgraph_step': 1, 'langgraph_node': 'agent', 'langgraph_triggers': ('branch:to:agent',), 'langgraph_path': ('__pregel_pull', 'agent'), 'langgraph_checkpoint_ns': 'supervisor:4aa19ce2-999c-fc11-7546-bfd1f675e211|agent:19b8dfec-e2e8-234d-4b86-f2f9a1168bf2', 'checkpoint_ns': 'supervisor:4aa19ce2-999c-fc11-7546-bfd1f675e211', 'ls_provider': 'openai', 'ls_model_name': 'gpt-3.5-turbo', 'ls_model_type': 'chat', 'ls_temperature': 0.0}

Description

I'm trying to build multi-agent graph(system) using create_react_agent() and stream them by LLM tokens(chunks) for minimum response latency to users. (I've used stream() function with stream_mode=messages and also astream_events() as example code)

I expect that I can distinguish which chunk is from which agent (I mean, the LLM node) so that I can stream only the output from a specific agent (such as the supervisor agent, for example).

However, the langgraph_node field in the metadata are the same ('agent') for all chunks. Therefore, as you can see from the example output, 'Error Message and Stack Trace (if applicable)', I can’t easily pick out only the chunks from a specific agent.

When outputting or streaming as a Message object rather than a Chunk object, the name field is present, and the value of the langgraph_node field corresponds to the {name} provided as a parameter.

Proposed Solution

After inspecting the create_react_agent function, I found that the name of the LLM node inside the agent is hardcoded as "agent". This should instead be replaced with the name value provided as a parameter. I confirmed that with this kind of customization, it behaves as intended. If I receive approval from the maintainer, I’d like to submit a PR based on this and have the rewarding experience of contributing, even in a small way, to this fantastic framework.

+++ This issue naturally extends to langgraph-supervisor-py as well, since create_supervisor() is also implemented using create_react_agent().

FYI)

System Info

System Information

OS: Darwin
OS Version: Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:34 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T8103
Python Version: 3.11.6 (main, Jun 6 2025, 16:20:29) [Clang 12.0.5 (clang-1205.0.22.9)]

Package Information

langchain_core: 0.3.70
langchain: 0.3.26
langchain_community: 0.3.25
langsmith: 0.3.45
langchain_anthropic: 0.3.15
langchain_openai: 0.3.28
langchain_tavily: 0.2.1
langchain_text_splitters: 0.3.8
langgraph_sdk: 0.1.70
langgraph_supervisor: 0.0.27

Optional packages not installed

langserve

Other Dependencies

aiohttp: 3.12.12
aiohttp<4.0.0,>=3.8.3: Installed. No version info available.
anthropic<1,>=0.52.0: Installed. No version info available.
async-timeout<5.0.0,>=4.0.0;: Installed. No version info available.
dataclasses-json<0.7,>=0.5.7: Installed. No version info available.
httpx: 0.28.1
httpx-sse<1.0.0,>=0.4.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.
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.63: Installed. No version info available.
langchain-core<1.0.0,>=0.3.65: Installed. No version info available.
langchain-core<1.0.0,>=0.3.66: Installed. No version info available.
langchain-core<1.0.0,>=0.3.68: Installed. No version info available.
langchain-core>=0.3.40: 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.25: Installed. No version info available.
langgraph-prebuilt>=0.1.7: Installed. No version info available.
langgraph>=0.3.5: Installed. No version info available.
langsmith-pyo3: Installed. No version info available.
langsmith<0.4,>=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.
mypy: 1.16.0
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.
packaging: 24.2
packaging>=23.2: Installed. No version info available.
pydantic: 2.11.5
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.
pytest: 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.
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.
tiktoken<1,>=0.7: Installed. No version info available.
typing-extensions>=4.7: Installed. No version info available.
zstandard: 0.23.0

Originally created by @richpin on GitHub (Jul 23, 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 import asyncio from typing import Annotated from langchain_core.tools import InjectedToolCallId, tool from langchain_openai import ChatOpenAI from langchain_tavily import TavilySearch from langgraph.graph import MessagesState, StateGraph, START, END from langgraph.prebuilt import InjectedState, create_react_agent from langchain_core.messages import HumanMessage from langgraph.types import Command # ---- tools ---- @tool def add(x: int, y: int) -> int: """Adds two integers and returns the result.""" return x + y # ---- llm & agents ---- llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0, streaming=True) search_agent = create_react_agent(llm, [TavilySearch(max_results=3, topic="general")], name="search_agent") math_agent = create_react_agent(llm, [add], name="math_agent") # ---- handoff tool ----- def create_handoff_tool(*, agent_name: str, description: str | None = None): name = f"transfer_to_{agent_name}" description = description or f"Ask {agent_name} for help." @tool(name, description=description) def handoff_tool( state: Annotated[MessagesState, InjectedState], tool_call_id: Annotated[str, InjectedToolCallId], ) -> Command: tool_message = { "role": "tool", "content": f"Successfully transferred to {agent_name}", "name": name, "tool_call_id": tool_call_id, } return Command( goto=agent_name, update={**state, "messages": state["messages"] + [tool_message]}, # (2)! graph=Command.PARENT, ) return handoff_tool # ---- supervisor agent ---- supervisor_agent = create_react_agent( model=llm, tools=[ create_handoff_tool(agent_name="search_agent"), create_handoff_tool(agent_name="math_agent"), ], prompt=( "You are a supervisor managing two agents:\n" "- a search agent. Assign search-related tasks to this agent\n" "- a math agent. Assign math-related tasks to this agent\n" "Assign work to one agent at a time, do not call agents in parallel.\n" "Do not do any work yourself." ), name="supervisor" ) # ---- mulit-agent graph ----- graph = ( StateGraph(MessagesState) .add_node(supervisor_agent, destinations=("search_agent", "math_agent", END)) .add_node(search_agent) .add_node(math_agent) .add_edge(START, "supervisor") .add_edge("search_agent", "supervisor") .add_edge("math_agent", "supervisor") .compile() ) # ---- streaming run ---- async def streaming(payload): async for event in graph.astream_events(payload, stream_mode="messages"): if(event["event"] == "on_chat_model_stream"): print(event["data"]) print(event["metadata"]) print() asyncio.run(streaming({"messages":[HumanMessage(content="Find the distances from Seoul to Busan and Seoul to Incheon, and calculate the total distance.")]})) ``` ### Error Message and Stack Trace (if applicable) ```shell {'chunk': AIMessageChunk(content=' ', additional_kwargs={}, response_metadata={}, id='run--e171be32-610d-483d-9ed1-adba4dcd2e87')} {'langgraph_step': 1, 'langgraph_node': 'agent', 'langgraph_triggers': ('branch:to:agent',), 'langgraph_path': ('__pregel_pull', 'agent'), 'langgraph_checkpoint_ns': 'supervisor:4aa19ce2-999c-fc11-7546-bfd1f675e211|agent:19b8dfec-e2e8-234d-4b86-f2f9a1168bf2', 'checkpoint_ns': 'supervisor:4aa19ce2-999c-fc11-7546-bfd1f675e211', 'ls_provider': 'openai', 'ls_model_name': 'gpt-3.5-turbo', 'ls_model_type': 'chat', 'ls_temperature': 0.0} {'chunk': AIMessageChunk(content='352', additional_kwargs={}, response_metadata={}, id='run--e171be32-610d-483d-9ed1-adba4dcd2e87')} {'langgraph_step': 1, 'langgraph_node': 'agent', 'langgraph_triggers': ('branch:to:agent',), 'langgraph_path': ('__pregel_pull', 'agent'), 'langgraph_checkpoint_ns': 'supervisor:4aa19ce2-999c-fc11-7546-bfd1f675e211|agent:19b8dfec-e2e8-234d-4b86-f2f9a1168bf2', 'checkpoint_ns': 'supervisor:4aa19ce2-999c-fc11-7546-bfd1f675e211', 'ls_provider': 'openai', 'ls_model_name': 'gpt-3.5-turbo', 'ls_model_type': 'chat', 'ls_temperature': 0.0} {'chunk': AIMessageChunk(content=' kilometers', additional_kwargs={}, response_metadata={}, id='run--e171be32-610d-483d-9ed1-adba4dcd2e87')} {'langgraph_step': 1, 'langgraph_node': 'agent', 'langgraph_triggers': ('branch:to:agent',), 'langgraph_path': ('__pregel_pull', 'agent'), 'langgraph_checkpoint_ns': 'supervisor:4aa19ce2-999c-fc11-7546-bfd1f675e211|agent:19b8dfec-e2e8-234d-4b86-f2f9a1168bf2', 'checkpoint_ns': 'supervisor:4aa19ce2-999c-fc11-7546-bfd1f675e211', 'ls_provider': 'openai', 'ls_model_name': 'gpt-3.5-turbo', 'ls_model_type': 'chat', 'ls_temperature': 0.0} ``` ### Description I'm trying to build multi-agent graph(system) using **create_react_agent()** and stream them by LLM **tokens(chunks)** for minimum response latency to users. (I've used `stream()` function with `stream_mode=messages` and also `astream_events()` as example code) I expect that I can distinguish which chunk is from which agent (I mean, the LLM node) so that I can stream only the output from a specific agent (such as the supervisor agent, for example). However, the `langgraph_node` field in the metadata are the same (**'agent'**) for all chunks. Therefore, as you can see from the example output, 'Error Message and Stack Trace (if applicable)', I can’t easily pick out only the chunks from a specific agent. When outputting or streaming as a Message object rather than a Chunk object, the `name` field is present, and the value of the `langgraph_node` field corresponds to the `{name}` provided as a parameter. #### Proposed Solution After inspecting the create_react_agent function, I found that the name of the LLM node inside the agent is hardcoded as **"agent"**. This should instead be replaced with the name value provided as a parameter. I confirmed that with this kind of customization, it behaves as intended. If I receive approval from the maintainer, I’d like to submit a PR based on this and have the rewarding experience of contributing, even in a small way, to this fantastic framework. +++ This issue naturally extends to `langgraph-supervisor-py` as well, since `create_supervisor()` is also implemented using `create_react_agent()`. FYI) * I've created topic in Langchain Forum here: https://forum.langchain.com/t/node-name-of-the-agent-graph-which-is-created-by-prebuilt-create-react-agent/577 * The reference I used for this example code: https://github.com/langchain-ai/langgraph/blob/main/docs/docs/tutorials/multi_agent/agent_supervisor.md ### System Info System Information ------------------ > OS: Darwin > OS Version: Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:34 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T8103 > Python Version: 3.11.6 (main, Jun 6 2025, 16:20:29) [Clang 12.0.5 (clang-1205.0.22.9)] Package Information ------------------- > langchain_core: 0.3.70 > langchain: 0.3.26 > langchain_community: 0.3.25 > langsmith: 0.3.45 > langchain_anthropic: 0.3.15 > langchain_openai: 0.3.28 > langchain_tavily: 0.2.1 > langchain_text_splitters: 0.3.8 > langgraph_sdk: 0.1.70 > langgraph_supervisor: 0.0.27 Optional packages not installed ------------------------------- > langserve Other Dependencies ------------------ > aiohttp: 3.12.12 > aiohttp<4.0.0,>=3.8.3: Installed. No version info available. > anthropic<1,>=0.52.0: Installed. No version info available. > async-timeout<5.0.0,>=4.0.0;: Installed. No version info available. > dataclasses-json<0.7,>=0.5.7: Installed. No version info available. > httpx: 0.28.1 > httpx-sse<1.0.0,>=0.4.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. > 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.63: Installed. No version info available. > langchain-core<1.0.0,>=0.3.65: Installed. No version info available. > langchain-core<1.0.0,>=0.3.66: Installed. No version info available. > langchain-core<1.0.0,>=0.3.68: Installed. No version info available. > langchain-core>=0.3.40: 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.25: Installed. No version info available. > langgraph-prebuilt>=0.1.7: Installed. No version info available. > langgraph>=0.3.5: Installed. No version info available. > langsmith-pyo3: Installed. No version info available. > langsmith<0.4,>=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. > mypy: 1.16.0 > 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. > packaging: 24.2 > packaging>=23.2: Installed. No version info available. > pydantic: 2.11.5 > 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. > pytest: 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. > 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. > tiktoken<1,>=0.7: Installed. No version info available. > typing-extensions>=4.7: Installed. No version info available. > zstandard: 0.23.0
yindo added the enhancement label 2026-02-20 17:41:59 -05:00
yindo closed this issue 2026-02-20 17:41:59 -05:00
Author
Owner

@sydney-runkle commented on GitHub (Jul 23, 2025):

Good call, this is definitely something we should support. Thanks for the report.

@sydney-runkle commented on GitHub (Jul 23, 2025): Good call, this is definitely something we should support. Thanks for the report.
Author
Owner

@richpin commented on GitHub (Aug 2, 2025):

Good call, this is definitely something we should support. Thanks for the report.

Please assign me after discussion about this enhancement, Sydney. Thanks! : )

@richpin commented on GitHub (Aug 2, 2025): > Good call, this is definitely something we should support. Thanks for the report. Please assign me after discussion about this enhancement, Sydney. Thanks! : )
Author
Owner

@ambideXtrous9 commented on GitHub (Aug 2, 2025):

Faced same issue..!! I handled it this way :

In Node :

llm = ChatOpenAI(model="gpt-4o", 
                temperature=0.0, 
                openai_api_key=api_key, 
                tags=["RegExpert"])  # use this tag in stream

ddg_search = DuckDuckGoSearchResults()

llm_reason_agent = create_react_agent(
        model=llm,
        tools=[ddg_search],
         prompt=("Ensure your answer is concise, compliant, and grounded in regulatory defensibility."))

def reason_llm(state):
        print("Node : reason_llm")
        start = time.perf_counter()

        user_msg = {"role": "user", "content": f"Research on this topic in detail: {state['llm_input']}"}

        ai_content = ""
        llm_response = llm_reason_agent.invoke({"messages": [user_msg]})
        assistant_msg = llm_response["messages"][-1]
        if isinstance(assistant_msg, AIMessage):
            ai_content = assistant_msg.content

        state["llm_output"] = ai_content

        return state

While streaming :

events = graph.astream_events(input=inputs, config=config, version="v2")
async for event in events:
    if event["event"] == "on_chat_model_stream" and len(event["tags"]) > 1 and event["tags"][1] == "RegExpert":
        chunk = event["data"]["chunk"].content
        print(chunk, end="", flush=True)

@ambideXtrous9 commented on GitHub (Aug 2, 2025): Faced same issue..!! I handled it this way : In Node : ``` llm = ChatOpenAI(model="gpt-4o", temperature=0.0, openai_api_key=api_key, tags=["RegExpert"]) # use this tag in stream ddg_search = DuckDuckGoSearchResults() llm_reason_agent = create_react_agent( model=llm, tools=[ddg_search], prompt=("Ensure your answer is concise, compliant, and grounded in regulatory defensibility.")) def reason_llm(state): print("Node : reason_llm") start = time.perf_counter() user_msg = {"role": "user", "content": f"Research on this topic in detail: {state['llm_input']}"} ai_content = "" llm_response = llm_reason_agent.invoke({"messages": [user_msg]}) assistant_msg = llm_response["messages"][-1] if isinstance(assistant_msg, AIMessage): ai_content = assistant_msg.content state["llm_output"] = ai_content return state ``` While streaming : ``` events = graph.astream_events(input=inputs, config=config, version="v2") async for event in events: if event["event"] == "on_chat_model_stream" and len(event["tags"]) > 1 and event["tags"][1] == "RegExpert": chunk = event["data"]["chunk"].content print(chunk, end="", flush=True) ```
Author
Owner

@richpin commented on GitHub (Aug 3, 2025):

Thank you for cool idea @ambideXtrous9!!! But it looks...

When we build multi-agent by applying same LLM instance to each agent (for reusability),
we are still not able to distinguish each agent using tags as above...🥲

@richpin commented on GitHub (Aug 3, 2025): Thank you for cool idea @ambideXtrous9!!! But it looks... When we build multi-agent by applying same LLM instance to each agent (for reusability), we are still not able to distinguish each agent using tags as above...🥲
Author
Owner

@cantbreath123 commented on GitHub (Sep 26, 2025):

+1 I have met the same problem

@cantbreath123 commented on GitHub (Sep 26, 2025): +1 I have met the same problem
Author
Owner

@dinuka-rp commented on GitHub (Oct 10, 2025):

This is kinda annoying in a multi-agentic scenario when using the Langgraph-supervisor.
Can't we include agent_name as a metadata tag/ metadata whenever a message gets streamed from any node of a prebuilt agent?

@dinuka-rp commented on GitHub (Oct 10, 2025): This is kinda annoying in a multi-agentic scenario when using the Langgraph-supervisor. Can't we include `agent_name` as a metadata tag/ metadata whenever a message gets streamed from any node of a prebuilt agent?
Author
Owner

@richpin commented on GitHub (Oct 10, 2025):

This is kinda annoying in a multi-agentic scenario when using the Langgraph-supervisor. Can't we include agent_name as a metadata tag/ metadata whenever a message gets streamed from any node of a prebuilt agent?

It seems the best solution so far is to differentiate the LLMs within each agent by inserting different tags, as suggested in the answer by ambideXtrous9.

@richpin commented on GitHub (Oct 10, 2025): > This is kinda annoying in a multi-agentic scenario when using the Langgraph-supervisor. Can't we include `agent_name` as a metadata tag/ metadata whenever a message gets streamed from any node of a prebuilt agent? It seems the best solution so far is to differentiate the LLMs within each agent by inserting different `tags`, as suggested in the answer by **ambideXtrous9**.
Author
Owner

@dinuka-rp commented on GitHub (Oct 15, 2025):

I figured out a fix for this. When subgraphs: true can be passed to the stream() function. This will return the stream with the namespace used. The namespace contains the agent's name. Hope this helps :)

Ref: https://docs.langchain.com/oss/python/langgraph/streaming#extended-example-streaming-from-subgraphs

@dinuka-rp commented on GitHub (Oct 15, 2025): I figured out a fix for this. When `subgraphs: true` can be passed to the stream() function. This will return the stream with the namespace used. The namespace contains the agent's name. Hope this helps :) Ref: https://docs.langchain.com/oss/python/langgraph/streaming#extended-example-streaming-from-subgraphs
Author
Owner

@richpin commented on GitHub (Oct 19, 2025):

I figured out a fix for this. When subgraphs: true can be passed to the stream() function. This will return the stream with the namespace used. The namespace contains the agent's name. Hope this helps :)

Ref: https://docs.langchain.com/oss/python/langgraph/streaming#extended-example-streaming-from-subgraphs

Thank you for your help!!! But from the example, it streams with the mode updates which does not stream chunks from LLM.

@richpin commented on GitHub (Oct 19, 2025): > I figured out a fix for this. When `subgraphs: true` can be passed to the stream() function. This will return the stream with the namespace used. The namespace contains the agent's name. Hope this helps :) > > Ref: https://docs.langchain.com/oss/python/langgraph/streaming#extended-example-streaming-from-subgraphs Thank you for your help!!! But from the example, it streams with the mode `updates` which does not stream chunks from LLM.
Author
Owner

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

We have support for a name arg in LangChain's new create_agent primitive. We generally recommend calling subagents via tools, so that should resolve the issue.

We're also looking to add an AgentRuntime construct that would have this metadata readily available, will track that over in LC.

@sydney-runkle commented on GitHub (Nov 7, 2025): We have support for a `name` arg in LangChain's new `create_agent` primitive. We generally recommend calling subagents via tools, so that should resolve the issue. We're also looking to add an `AgentRuntime` construct that would have this metadata readily available, will track that over in LC.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#832