From dc3ae9396daebddd300a312d5cf5609f3844618b Mon Sep 17 00:00:00 2001 From: lorenzejay Date: Fri, 9 Jan 2026 18:07:37 -0800 Subject: [PATCH] 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. --- lib/crewai/src/crewai/experimental/agent_executor.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/crewai/src/crewai/experimental/agent_executor.py b/lib/crewai/src/crewai/experimental/agent_executor.py index ee8a14595..2743fff1b 100644 --- a/lib/crewai/src/crewai/experimental/agent_executor.py +++ b/lib/crewai/src/crewai/experimental/agent_executor.py @@ -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)), ),