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
This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-11-18 10:38:11 -03:00 committed by GitHub
commit 95779c8cef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -122,18 +122,21 @@ class LCAgentComponent(Component):
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"):