From 5cef85c643b7ec146279fbf7525e0cfe6a56e2ce Mon Sep 17 00:00:00 2001 From: lorenzejay Date: Fri, 9 Jan 2026 18:27:07 -0800 Subject: [PATCH] refactor: streamline AgentExecutor initialization by removing redundant parameters Updated the Agent class to simplify the initialization of the AgentExecutor by removing unnecessary task and crew parameters in standalone mode. This change enhances code clarity and maintains backward compatibility by ensuring that the executor is correctly configured without redundant assignments. --- lib/crewai/src/crewai/agent/core.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/crewai/src/crewai/agent/core.py b/lib/crewai/src/crewai/agent/core.py index 8464eea66..da5287957 100644 --- a/lib/crewai/src/crewai/agent/core.py +++ b/lib/crewai/src/crewai/agent/core.py @@ -1642,6 +1642,8 @@ class Agent(BaseAgent): # Create the executor for standalone mode (no crew, no task) executor = AgentExecutor( + task=None, + crew=None, llm=cast(BaseLLM, self.llm), agent=self, prompt=prompt, @@ -1651,8 +1653,6 @@ class Agent(BaseAgent): stop_words=stop_words, tools_description=render_text_description_and_args(parsed_tools), tools_handler=self.tools_handler, - task=None, # Standalone mode - crew=None, # Standalone mode original_tools=raw_tools, step_callback=self.step_callback, function_calling_llm=self.function_calling_llm, @@ -1663,7 +1663,6 @@ class Agent(BaseAgent): i18n=self.i18n, ) - # Format messages for the executor if isinstance(messages, str): formatted_messages = messages else: @@ -1693,7 +1692,6 @@ class Agent(BaseAgent): # Execute and build output output = self._execute_and_build_output(executor, inputs, response_format) - # Process guardrail if configured if self.guardrail is not None: output = self._process_kickoff_guardrail( output=output, @@ -1702,7 +1700,6 @@ class Agent(BaseAgent): response_format=response_format, ) - # Emit completed event for backward compatibility with LiteAgent listeners crewai_event_bus.emit( self, event=LiteAgentExecutionCompletedEvent( @@ -1714,7 +1711,6 @@ class Agent(BaseAgent): return output except Exception as e: - # Emit error event for backward compatibility with LiteAgent listeners crewai_event_bus.emit( self, event=LiteAgentExecutionErrorEvent(