From 005dc2de192f3162a65e6696156c3fa9f8df6029 Mon Sep 17 00:00:00 2001 From: iris-clawd Date: Thu, 7 May 2026 17:44:54 +0000 Subject: [PATCH] feat: deprecate CrewAgentExecutor, default Crew agents to AgentExecutor --- lib/crewai/src/crewai/agent/core.py | 21 ++++++++++++------- lib/crewai/src/crewai/agents/__init__.py | 15 +++++++++++++ .../src/crewai/agents/crew_agent_executor.py | 8 +++++++ 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/lib/crewai/src/crewai/agent/core.py b/lib/crewai/src/crewai/agent/core.py index 74a3e85de..08e5f14d1 100644 --- a/lib/crewai/src/crewai/agent/core.py +++ b/lib/crewai/src/crewai/agent/core.py @@ -40,7 +40,6 @@ from crewai.agent.utils import ( format_task_with_context, get_knowledge_config, handle_knowledge_retrieval, - handle_reasoning, prepare_tools, process_tool_results, save_last_messages, @@ -145,7 +144,17 @@ def _validate_executor_class(value: Any) -> Any: cls = _EXECUTOR_CLASS_MAP.get(value) if cls is None: raise ValueError(f"Unknown executor class: {value}") - return cls + value = cls + import warnings + + if value is CrewAgentExecutor: + warnings.warn( + "CrewAgentExecutor is deprecated and will be removed in a future release. " + "Agents inside Crews now use AgentExecutor by default. " + "Switch to crewai.experimental.AgentExecutor.", + DeprecationWarning, + stacklevel=3, + ) return value @@ -313,8 +322,8 @@ class Agent(BaseAgent): BeforeValidator(_validate_executor_class), PlainSerializer(_serialize_executor_class, return_type=str, when_used="json"), ] = Field( - default=CrewAgentExecutor, - description="Class to use for the agent executor. Defaults to CrewAgentExecutor, can optionally use AgentExecutor.", + default=AgentExecutor, + description="Class to use for the agent executor. Defaults to AgentExecutor, can optionally use CrewAgentExecutor.", ) @model_validator(mode="before") @@ -499,8 +508,6 @@ class Agent(BaseAgent): The task prompt after memory retrieval, ready for knowledge lookup. """ get_env_context() - if self.executor_class is not AgentExecutor: - handle_reasoning(self, task) self._inject_date_to_task(task) @@ -1022,7 +1029,7 @@ class Agent(BaseAgent): raise RuntimeError( "LLM must be resolved before creating agent executor." ) - self.agent_executor = self.executor_class( + self.agent_executor = AgentExecutor( llm=self.llm, task=task, agent=self, diff --git a/lib/crewai/src/crewai/agents/__init__.py b/lib/crewai/src/crewai/agents/__init__.py index ae7c33797..228136710 100644 --- a/lib/crewai/src/crewai/agents/__init__.py +++ b/lib/crewai/src/crewai/agents/__init__.py @@ -1,13 +1,28 @@ +from typing import TYPE_CHECKING, Any + from crewai.agents.cache.cache_handler import CacheHandler from crewai.agents.parser import AgentAction, AgentFinish, OutputParserError, parse from crewai.agents.tools_handler import ToolsHandler +if TYPE_CHECKING: + from crewai.agents.crew_agent_executor import CrewAgentExecutor + + __all__ = [ "AgentAction", "AgentFinish", "CacheHandler", + "CrewAgentExecutor", "OutputParserError", "ToolsHandler", "parse", ] + + +def __getattr__(name: str) -> Any: + if name == "CrewAgentExecutor": + from crewai.agents.crew_agent_executor import CrewAgentExecutor + + return CrewAgentExecutor + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") diff --git a/lib/crewai/src/crewai/agents/crew_agent_executor.py b/lib/crewai/src/crewai/agents/crew_agent_executor.py index 62369bfb9..b5b9204ff 100644 --- a/lib/crewai/src/crewai/agents/crew_agent_executor.py +++ b/lib/crewai/src/crewai/agents/crew_agent_executor.py @@ -14,6 +14,7 @@ import contextvars import inspect import logging from typing import TYPE_CHECKING, Annotated, Any, Literal, cast +import warnings from pydantic import ( AliasChoices, @@ -137,6 +138,13 @@ class CrewAgentExecutor(BaseAgentExecutor): def __init__(self, **kwargs: Any) -> None: super().__init__(**kwargs) + warnings.warn( + "CrewAgentExecutor is deprecated and will be removed in a future release.\n" + "Agents inside Crews now use AgentExecutor (crewai.experimental.AgentExecutor) by default.\n" + "To suppress this warning, migrate to AgentExecutor.", + DeprecationWarning, + stacklevel=2, + ) if not self.before_llm_call_hooks: self.before_llm_call_hooks.extend(get_before_llm_call_hooks()) if not self.after_llm_call_hooks: