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: