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:
parent
a7aa3ab03f
commit
95779c8cef
1 changed files with 8 additions and 5 deletions
|
|
@ -122,18 +122,21 @@ class LCAgentComponent(Component):
|
||||||
if isinstance(agent, AgentExecutor):
|
if isinstance(agent, AgentExecutor):
|
||||||
runnable = agent
|
runnable = agent
|
||||||
else:
|
else:
|
||||||
if not self.tools:
|
if not hasattr(self, "tools") or not self.tools:
|
||||||
msg = "Tools are required to run the agent."
|
msg = "Tools are required to run the agent."
|
||||||
raise ValueError(msg)
|
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(
|
runnable = AgentExecutor.from_agent_and_tools(
|
||||||
agent=agent,
|
agent=agent,
|
||||||
tools=self.tools,
|
tools=self.tools,
|
||||||
handle_parsing_errors=self.handle_parsing_errors,
|
handle_parsing_errors=handle_parsing_errors,
|
||||||
verbose=self.verbose,
|
verbose=verbose,
|
||||||
max_iterations=self.max_iterations,
|
max_iterations=max_iterations,
|
||||||
)
|
)
|
||||||
input_dict: dict[str, str | list[BaseMessage]] = {"input": self.input_value}
|
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)
|
input_dict["chat_history"] = data_to_messages(self.chat_history)
|
||||||
|
|
||||||
if hasattr(self, "graph"):
|
if hasattr(self, "graph"):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue