From 965849823a3e87b1405b2dd9839c3bcef499d77b Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Mon, 14 Oct 2024 17:03:53 -0700 Subject: [PATCH] Fix --- .../langgraph/prebuilt/chat_agent_executor.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/libs/langgraph/langgraph/prebuilt/chat_agent_executor.py b/libs/langgraph/langgraph/prebuilt/chat_agent_executor.py index 37ce9c9f5..5f739c0a6 100644 --- a/libs/langgraph/langgraph/prebuilt/chat_agent_executor.py +++ b/libs/langgraph/langgraph/prebuilt/chat_agent_executor.py @@ -573,8 +573,22 @@ def create_react_agent( if isinstance(response, AIMessage) else False ) - if (state["remaining_steps"] < 1 and all_tools_return_direct) or ( - state["remaining_steps"] < 2 and has_tool_calls + if ( + ( + "remaining_steps" not in state + and state["is_last_step"] + and has_tool_calls + ) + or ( + "remaining_steps" in state + and state["remaining_steps"] < 1 + and all_tools_return_direct + ) + or ( + "remaining_steps" in state + and state["remaining_steps"] < 2 + and has_tool_calls + ) ): return { "messages": [