diff --git a/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py b/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py index 4026ef81f..8b0a3f13a 100644 --- a/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py +++ b/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py @@ -575,7 +575,7 @@ def create_react_agent( _should_bind_tools(model, tool_classes, num_builtin=len(llm_builtin_tools)) # type: ignore[arg-type] and len(tool_classes + llm_builtin_tools) > 0 ): - model = cast(Union[BaseChatModelV0, BaseChatModelV1], model).bind_tools( + model = cast(Union[BaseChatModelV0, BaseChatModelV1], model).bind_tools( # type: ignore[assignment] tool_classes + llm_builtin_tools # type: ignore[operator] ) @@ -681,6 +681,9 @@ def create_react_agent( else: response = cast(AIMessageV1, response) + # Type assertion to help mypy understand the response type + assert isinstance(response, (AIMessageV0, AIMessageV1)) + # add agent name to the AIMessage response.name = name @@ -714,6 +717,9 @@ def create_react_agent( else: response = cast(AIMessageV1, response) + # Type assertion to help mypy understand the response type + assert isinstance(response, (AIMessageV0, AIMessageV1)) + # add agent name to the AIMessage response.name = name if _are_more_steps_needed(state, response):