Node name of the agent graph which is created by prebuilt.create_react_agent

Hi, this is Yoo.
I’ve been used prebuilt.create_react_agent to make agents for making multi-agent system.

It’s super cool but the thing happened when I tried to stream the output of agents. I used stream function with paramter stream_mode=messages to stream LLM tokens generated by model. And I checked that langgraph_node of chunk’s metadata of all agents are the same as ‘agent’. Below is the example of standard output of chunk → metadata → next chunk → next metadata sequentially.

content='\n' additional_kwargs={} response_metadata={} id='run--f567f474-6ee8-493f-b533-0a89269187a7'
{'thread_id': '975250e8-36a9-47af-afc5-0fb7420fa0db', 'langgraph_step': 3, 'langgraph_node': 'agent', 'langgraph_triggers': ('branch:to:agent',), 'langgraph_path': ('__pregel_pull', 'agent'), 'langgraph_checkpoint_ns': 'research_agent:f9beb20b-4112-7f3e-227a-5392c6a11448|agent:1bc3291f-4200-e125-bc8f-906557617fa0', 'checkpoint_ns': 'research_agent:f9beb20b-4112-7f3e-227a-5392c6a11448', 'ls_provider': 'openai', 'ls_model_name': 'gpt-4o-mini', 'ls_model_type': 'chat', 'ls_temperature': 0.5}
content='-' additional_kwargs={} response_metadata={} id='run--f567f474-6ee8-493f-b533-0a89269187a7'
{'thread_id': '975250e8-36a9-47af-afc5-0fb7420fa0db', 'langgraph_step': 3, 'langgraph_node': 'agent', 'langgraph_triggers': ('branch:to:agent',), 'langgraph_path': ('__pregel_pull', 'agent'), 'langgraph_checkpoint_ns': 'research_agent:f9beb20b-4112-7f3e-227a-5392c6a11448|agent:1bc3291f-4200-e125-bc8f-906557617fa0', 'checkpoint_ns': 'research_agent:f9beb20b-4112-7f3e-227a-5392c6a11448', 'ls_provider': 'openai', 'ls_model_name': 'gpt-4o-mini', 'ls_model_type': 'chat', 'ls_temperature': 0.5}

So I was not able to distinguish which chunk came from which agents. This is because the name of LLM calling node is hardcoded as ‘agent’ in the prebuilt.create_react_agent. Since there is name parameter in the create_react_agent function, it’s for graph-level, not node-level. So what I did was modifying node name as given ‘name’ parameter temporarily in the function.

For my example, I wanted to only stream output of supevisor agent which is created by create_supervisor function from langgraph-supervisor which also uses create_react_agent internally.

Since I don’t know langgraph that deeply, I wonder if there is some fancy way to handle this.

However, I still think that If this function could optionally receive parameters from the user and dynamically modify the LLM node name, it would make the distinction clearer and allow for more flexible handling of different situations. If this is considered to make sense, I really hope to make a PR for this, receive feedbacks, and contributes this amazing frameworks!!!:smiley:

I ask for maintainer’s help.

Best Regards,

You’re correct that create_react_agent hardcodes the node name as “agent”, making it difficult to distinguish between multiple agents in a multi agent system when streaming. The name parameter only affects the graph name, not the internal node names.

Your approach of modifying the node name based on the name parameter makes perfect sense and would be a valuable contribution. Currently, there’s no built in way to customize internal node names in prebuilt agents. A potential solution would be to modify create_react_agent to accept an optional node_name parameter that defaults to “agent” but allows customization.

For your immediate use case, you could create a custom version of create_react_agent that accepts a node_name parameter, or wrap the existing function to modify node names post-creation. This would definitely be a useful PR. The ability to distinguish between agents in multi agent streaming scenarios is a common need. I’d recommend proposing this enhancement on the LangGraph GitHub repository.

1 Like

I really appreciate your response which empowers my opinion, AbdulBasit :grinning_face_with_smiling_eyes: