From 08295ecadb030a0ef46c7e822be56c69996e0a94 Mon Sep 17 00:00:00 2001 From: Mohammad Mohtashim <45242107+keenborder786@users.noreply.github.com> Date: Thu, 31 Jul 2025 23:00:12 +0500 Subject: [PATCH] chore(prebuilt): add supported input types for model in create_react_agent (#5748) - **Description:** Update the type annotations in create_react_agent to allow one to provide a callable for the model that uses bind_tools and returns a Runnable[LanguageModelInput, BaseMessage] - **Issue:** #5739 --------- Co-authored-by: Eugene Yurtsev --- .../prebuilt/langgraph/prebuilt/chat_agent_executor.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py b/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py index 6c3f0a4c0..0f71a981f 100644 --- a/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py +++ b/libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py @@ -254,6 +254,13 @@ def create_react_agent( LanguageModelLike, Callable[[StateSchema, Runtime[ContextT]], BaseChatModel], Callable[[StateSchema, Runtime[ContextT]], Awaitable[BaseChatModel]], + Callable[ + [StateSchema, Runtime[ContextT]], Runnable[LanguageModelInput, BaseMessage] + ], + Callable[ + [StateSchema, Runtime[ContextT]], + Awaitable[Runnable[LanguageModelInput, BaseMessage]], + ], ], tools: Union[Sequence[Union[BaseTool, Callable, dict[str, Any]]], ToolNode], *, @@ -287,6 +294,9 @@ def create_react_agent( - **Dynamic model**: A callable with signature `(state, runtime) -> BaseChatModel` that returns different models based on runtime context + If the model has tools bound via `.bind_tools()` or other configurations, + the return type should be a Runnable[LanguageModelInput, BaseMessage] + Coroutines are also supported, allowing for asynchronous model selection. Dynamic functions receive graph state and runtime, enabling context-dependent model selection. Must return a `BaseChatModel`