From a93f17e6249ee44ae6af165d8b9af907b9cf62ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Panella?= Date: Tue, 18 Feb 2025 11:39:46 -0600 Subject: [PATCH] langgraph(prebuilt): allow a PromptTemplate in react agent (#3463) Currently a ChatPromptTemplate cannot be used as a `prompt` for `create_react_agent` without complaints from type checkers, although it is supported by `model` as input. Add the missing types to remove the warning. --------- Co-authored-by: vbarda --- .../langgraph/prebuilt/chat_agent_executor.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libs/langgraph/langgraph/prebuilt/chat_agent_executor.py b/libs/langgraph/langgraph/prebuilt/chat_agent_executor.py index 04d18b1d4..7c21ff987 100644 --- a/libs/langgraph/langgraph/prebuilt/chat_agent_executor.py +++ b/libs/langgraph/langgraph/prebuilt/chat_agent_executor.py @@ -12,7 +12,11 @@ from typing import ( cast, ) -from langchain_core.language_models import BaseChatModel, LanguageModelLike +from langchain_core.language_models import ( + BaseChatModel, + LanguageModelInput, + LanguageModelLike, +) from langchain_core.messages import AIMessage, BaseMessage, SystemMessage, ToolMessage from langchain_core.runnables import ( Runnable, @@ -63,15 +67,15 @@ PROMPT_RUNNABLE_NAME = "Prompt" MessagesModifier = Union[ SystemMessage, str, - Callable[[Sequence[BaseMessage]], Sequence[BaseMessage]], - Runnable[Sequence[BaseMessage], Sequence[BaseMessage]], + Callable[[Sequence[BaseMessage]], LanguageModelInput], + Runnable[Sequence[BaseMessage], LanguageModelInput], ] Prompt = Union[ SystemMessage, str, - Callable[[StateSchema], Sequence[BaseMessage]], - Runnable[StateSchema, Sequence[BaseMessage]], + Callable[[StateSchema], LanguageModelInput], + Runnable[StateSchema, LanguageModelInput], ]