From 39891526cacd4e251345a42bfec9a7afcb3fb953 Mon Sep 17 00:00:00 2001 From: William Fu-Hinthorn <13333726+hinthornw@users.noreply.github.com> Date: Mon, 31 Mar 2025 06:31:50 -0700 Subject: [PATCH] Handle edge case --- libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py b/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py index 0ca0d42b1..136fb5ae7 100644 --- a/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py +++ b/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py @@ -772,6 +772,8 @@ def create_react_agent( # Define the function that determines whether to continue or not def should_continue(state: StateSchema) -> Union[str, list]: messages = _get_state_value(state, "messages") + if not messages: + return END last_message = messages[-1] # If there is no function call, then we finish if not isinstance(last_message, AIMessage) or not last_message.tool_calls: