Skip to content

Commit

Permalink
fix: Ensure attribute existence before accessing in AgentExecutor ini…
Browse files Browse the repository at this point in the history
…tialization (langflow-ai#4667)

* Add attribute check for 'chat_history' before accessing it in agent.py

* Ensure attribute existence before accessing in AgentExecutor initialization
  • Loading branch information
ogabrielluiz authored and diogocabral committed Nov 26, 2024
1 parent 967e929 commit 83133cd
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/backend/base/langflow/base/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down

0 comments on commit 83133cd

Please sign in to comment.