Skip to content

Commit

Permalink
Update tool_condition to match default ToolNode name
Browse files Browse the repository at this point in the history
  • Loading branch information
nfcampos committed May 14, 2024
1 parent f335105 commit 63586d8
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions langgraph/prebuilt/tool_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async def run_one(call: ToolCall):

def tools_condition(
state: Union[list[AnyMessage], dict[str, Any]],
) -> Literal["action", "__end__"]:
) -> Literal["tools", "__end__"]:
"""Use in the conditional_edge to route to the ToolNode if the last message
has tool calls. Otherwise, route to the end.
Expand Down Expand Up @@ -134,15 +134,7 @@ def tools_condition(
>>> graph_builder.add_node("chatbot", llm.bind_tools(tools))
>>> graph_builder.add_edge("tools", "chatbot")
>>> graph_builder.add_conditional_edges(
>>> "chatbot",
>>> # highlight-next-line
>>> tools_condition,
>>> {
>>> # If it returns 'action', route to the 'tools' node
>>> "action": "tools",
>>> # If it returns '__end__', route to the end
>>> "__end__": "__end__",
>>> },
>>> "chatbot", tools_condition
>>> )
>>> graph_builder.set_entry_point("chatbot")
>>> graph = graph_builder.compile()
Expand All @@ -156,5 +148,5 @@ def tools_condition(
else:
raise ValueError(f"No messages found in input state to tool_edge: {state}")
if hasattr(ai_message, "tool_calls") and len(ai_message.tool_calls) > 0:
return "action"
return "tools"
return "__end__"

0 comments on commit 63586d8

Please sign in to comment.