[PR #3126] langgraph[patch]: allow ToolNode to accept ToolCalls #3098

Closed
opened 2026-02-20 17:48:04 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langchain-ai/langgraph/pull/3126

State: closed
Merged: Yes


Alternative to https://github.com/langchain-ai/langgraph/pull/3124

Currently if a tool interrupts, the entire tool node executes again after resuming. So tools can get executed twice if parallel tool calls are generated. Here we allow ToolNode to accept tool calls, so we can use the Send API to distribute the tool calls to multiple instances of the tool node.

from langchain_anthropic import ChatAnthropic
from langchain_core.tools import tool
from langgraph.checkpoint.memory import MemorySaver
from langgraph.prebuilt import create_react_agent
from langgraph.types import Command, Send, interrupt


@tool
def human_assistance(query: str) -> str:
    """Request assistance from a human."""
    human_response = interrupt({"query": query})
    return human_response["data"]


@tool
def get_weather(location: str) -> str:
    """Use this tool to get the weather."""
    return "It's sunny!"


tools = [get_weather, human_assistance]
llm = ChatAnthropic(model="claude-3-5-sonnet-20240620")

agent = create_react_agent(
    llm,
    tools,
    checkpointer=MemorySaver(),
    tool_call_parallelism="parallel_tool_nodes",
)


user_input = (
    "Could you please (1) request assistance for building an AI agent "
    "from a human, and (2) search for the weather in Boston, MA? "
    "Generate two tool calls at once."
)

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

for event in agent.stream(
    {"messages": [{"role": "user", "content": user_input}]},
    config,
    stream_mode="values",
):
    event["messages"][-1].pretty_print()
...
human_response = "You should check out LangGraph to build your agent."
human_command = Command(resume={"data": human_response})

for event in agent.stream(human_command, config, stream_mode="values"):
    event["messages"][-1].pretty_print()
**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/3126 **State:** closed **Merged:** Yes --- Alternative to https://github.com/langchain-ai/langgraph/pull/3124 Currently if a tool interrupts, the entire tool node executes again after resuming. So tools can get executed twice if parallel tool calls are generated. Here we allow ToolNode to accept tool calls, so we can use the `Send` API to distribute the tool calls to multiple instances of the tool node. ```python from langchain_anthropic import ChatAnthropic from langchain_core.tools import tool from langgraph.checkpoint.memory import MemorySaver from langgraph.prebuilt import create_react_agent from langgraph.types import Command, Send, interrupt @tool def human_assistance(query: str) -> str: """Request assistance from a human.""" human_response = interrupt({"query": query}) return human_response["data"] @tool def get_weather(location: str) -> str: """Use this tool to get the weather.""" return "It's sunny!" tools = [get_weather, human_assistance] llm = ChatAnthropic(model="claude-3-5-sonnet-20240620") agent = create_react_agent( llm, tools, checkpointer=MemorySaver(), tool_call_parallelism="parallel_tool_nodes", ) user_input = ( "Could you please (1) request assistance for building an AI agent " "from a human, and (2) search for the weather in Boston, MA? " "Generate two tool calls at once." ) config = {"configurable": {"thread_id": "1"}} for event in agent.stream( {"messages": [{"role": "user", "content": user_input}]}, config, stream_mode="values", ): event["messages"][-1].pretty_print() ``` ``` ... ``` ```python human_response = "You should check out LangGraph to build your agent." human_command = Command(resume={"data": human_response}) for event in agent.stream(human_command, config, stream_mode="values"): event["messages"][-1].pretty_print() ```
yindo added the pull-request label 2026-02-20 17:48:04 -05:00
yindo closed this issue 2026-02-20 17:48:04 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#3098