From 83133cddbfd203b92ea5b2eacf1077c124452484 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 18 Nov 2024 10:38:11 -0300 Subject: [PATCH] fix: Ensure attribute existence before accessing in AgentExecutor initialization (#4667) * Add attribute check for 'chat_history' before accessing it in agent.py * Ensure attribute existence before accessing in AgentExecutor initialization --- src/backend/base/langflow/base/agents/agent.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/backend/base/langflow/base/agents/agent.py b/src/backend/base/langflow/base/agents/agent.py index 77ffe1980e60..ee174c959c4a 100644 --- a/src/backend/base/langflow/base/agents/agent.py +++ b/src/backend/base/langflow/base/agents/agent.py @@ -122,18 +122,21 @@ async def run_agent( if isinstance(agent, AgentExecutor): runnable = agent else: - if not self.tools: + if not hasattr(self, "tools") or not self.tools: msg = "Tools are required to run the agent." raise ValueError(msg) + handle_parsing_errors = hasattr(self, "handle_parsing_errors") and self.handle_parsing_errors + verbose = hasattr(self, "verbose") and self.verbose + max_iterations = hasattr(self, "max_iterations") and self.max_iterations runnable = AgentExecutor.from_agent_and_tools( agent=agent, tools=self.tools, - handle_parsing_errors=self.handle_parsing_errors, - verbose=self.verbose, - max_iterations=self.max_iterations, + handle_parsing_errors=handle_parsing_errors, + verbose=verbose, + max_iterations=max_iterations, ) input_dict: dict[str, str | list[BaseMessage]] = {"input": self.input_value} - if self.chat_history: + if hasattr(self, "chat_history") and self.chat_history: input_dict["chat_history"] = data_to_messages(self.chat_history) if hasattr(self, "graph"):