From 45e710145792d82f578ad4022da619f7d3ab5c5d Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Mon, 14 Oct 2024 16:57:25 -0700 Subject: [PATCH] Backwards compat --- .../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 7f6a50de0..37ce9c9f5 100644 --- a/libs/langgraph/langgraph/prebuilt/chat_agent_executor.py +++ b/libs/langgraph/langgraph/prebuilt/chat_agent_executor.py @@ -537,8 +537,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": [