diff --git a/src/backend/base/langflow/components/langchain_utilities/openai_tools.py b/src/backend/base/langflow/components/langchain_utilities/openai_tools.py index c529330c5202..f7f5e0f78529 100644 --- a/src/backend/base/langflow/components/langchain_utilities/openai_tools.py +++ b/src/backend/base/langflow/components/langchain_utilities/openai_tools.py @@ -37,14 +37,17 @@ def get_chat_history_data(self) -> list[Data] | None: return self.chat_history def create_agent_runnable(self): - if "input" not in self.user_prompt: - msg = "Prompt must contain 'input' key." - raise ValueError(msg) + try: + user_prompt = self.user_prompt + except KeyError: + raise ValueError("Prompt must contain 'input' key.") + messages = [ ("system", self.system_prompt), ("placeholder", "{chat_history}"), - HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=["input"], template=self.user_prompt)), + HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=["input"], template=user_prompt)), ("placeholder", "{agent_scratchpad}"), ] + prompt = ChatPromptTemplate.from_messages(messages) return create_openai_tools_agent(self.llm, self.tools, prompt)