diff --git a/src/crewai/project/annotations.py b/src/crewai/project/annotations.py index 79407c943..9a14500e6 100644 --- a/src/crewai/project/annotations.py +++ b/src/crewai/project/annotations.py @@ -2,13 +2,14 @@ from collections.abc import Callable from functools import wraps -from typing import Concatenate, ParamSpec, TypeVar +from typing import TYPE_CHECKING, Concatenate, ParamSpec, TypeVar -from crewai import Crew from crewai.project.utils import memoize + +if TYPE_CHECKING: + from crewai import Agent, Crew, Task from crewai.project.wrappers import ( AfterKickoffMethod, - AgentInstance, AgentMethod, BeforeKickoffMethod, CacheHandlerMethod, @@ -17,7 +18,6 @@ from crewai.project.wrappers import ( LLMMethod, OutputJsonClass, OutputPydanticClass, - TaskInstance, TaskMethod, TaskResultT, ToolMethod, @@ -174,8 +174,8 @@ def crew( Returns: The configured Crew instance with callbacks attached. """ - instantiated_tasks: list[TaskInstance] = [] - instantiated_agents: list[AgentInstance] = [] + instantiated_tasks: list[Task] = [] + instantiated_agents: list[Agent] = [] agent_roles: set[str] = set() # Use the preserved task and agent information diff --git a/src/crewai/project/wrappers.py b/src/crewai/project/wrappers.py index 5d4eca8c0..f75a435b6 100644 --- a/src/crewai/project/wrappers.py +++ b/src/crewai/project/wrappers.py @@ -2,7 +2,10 @@ from collections.abc import Callable from functools import wraps -from typing import Any, Generic, ParamSpec, Protocol, Self, TypeVar +from typing import TYPE_CHECKING, Any, Generic, ParamSpec, Protocol, Self, TypeVar + +if TYPE_CHECKING: + from crewai import Agent, Task P = ParamSpec("P") R = TypeVar("R") @@ -18,27 +21,15 @@ class TaskResult(Protocol): TaskResultT = TypeVar("TaskResultT", bound=TaskResult) -class AgentInstance(Protocol): - """Protocol for agent instances.""" - - role: str - - -class TaskInstance(Protocol): - """Protocol for task instances.""" - - agent: AgentInstance | None - - class CrewInstance(Protocol): """Protocol for crew class instances with required attributes.""" - _original_tasks: dict[str, Callable[[Self], TaskInstance]] - _original_agents: dict[str, Callable[[Self], AgentInstance]] + _original_tasks: dict[str, Callable[[Self], Task]] + _original_agents: dict[str, Callable[[Self], Agent]] _before_kickoff: dict[str, Callable[..., Any]] _after_kickoff: dict[str, Callable[..., Any]] - agents: list[AgentInstance] - tasks: list[TaskInstance] + agents: list[Agent] + tasks: list[Task] class DecoratedMethod(Generic[P, R]):