fix: handle None task in AgentExecutor to prevent errors

Added a check to ensure that if the task is None, the method returns early without attempting to access task properties. This change improves the robustness of the AgentExecutor by preventing potential errors when the task is not set.
This commit is contained in:
lorenzejay
2026-01-09 18:07:37 -08:00
parent 0029f8193c
commit dc3ae9396d

View File

@@ -587,11 +587,14 @@ class AgentExecutor(Flow[AgentReActState], CrewAgentExecutorMixin):
if self.agent is None:
raise ValueError("Agent cannot be None")
if self.task is None:
return
crewai_event_bus.emit(
self.agent,
AgentLogsStartedEvent(
agent_role=self.agent.role,
task_description=(self.task.description if self.task else "Not Found"),
task_description=self.task.description,
verbose=self.agent.verbose
or (hasattr(self, "crew") and getattr(self.crew, "verbose", False)),
),