mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 08:38:30 +00:00
chore: refactor type hints for Agent and Task in annotations and wrappers
This commit is contained in:
@@ -2,13 +2,14 @@
|
|||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from functools import wraps
|
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
|
from crewai.project.utils import memoize
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from crewai import Agent, Crew, Task
|
||||||
from crewai.project.wrappers import (
|
from crewai.project.wrappers import (
|
||||||
AfterKickoffMethod,
|
AfterKickoffMethod,
|
||||||
AgentInstance,
|
|
||||||
AgentMethod,
|
AgentMethod,
|
||||||
BeforeKickoffMethod,
|
BeforeKickoffMethod,
|
||||||
CacheHandlerMethod,
|
CacheHandlerMethod,
|
||||||
@@ -17,7 +18,6 @@ from crewai.project.wrappers import (
|
|||||||
LLMMethod,
|
LLMMethod,
|
||||||
OutputJsonClass,
|
OutputJsonClass,
|
||||||
OutputPydanticClass,
|
OutputPydanticClass,
|
||||||
TaskInstance,
|
|
||||||
TaskMethod,
|
TaskMethod,
|
||||||
TaskResultT,
|
TaskResultT,
|
||||||
ToolMethod,
|
ToolMethod,
|
||||||
@@ -174,8 +174,8 @@ def crew(
|
|||||||
Returns:
|
Returns:
|
||||||
The configured Crew instance with callbacks attached.
|
The configured Crew instance with callbacks attached.
|
||||||
"""
|
"""
|
||||||
instantiated_tasks: list[TaskInstance] = []
|
instantiated_tasks: list[Task] = []
|
||||||
instantiated_agents: list[AgentInstance] = []
|
instantiated_agents: list[Agent] = []
|
||||||
agent_roles: set[str] = set()
|
agent_roles: set[str] = set()
|
||||||
|
|
||||||
# Use the preserved task and agent information
|
# Use the preserved task and agent information
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from functools import wraps
|
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")
|
P = ParamSpec("P")
|
||||||
R = TypeVar("R")
|
R = TypeVar("R")
|
||||||
@@ -18,27 +21,15 @@ class TaskResult(Protocol):
|
|||||||
TaskResultT = TypeVar("TaskResultT", bound=TaskResult)
|
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):
|
class CrewInstance(Protocol):
|
||||||
"""Protocol for crew class instances with required attributes."""
|
"""Protocol for crew class instances with required attributes."""
|
||||||
|
|
||||||
_original_tasks: dict[str, Callable[[Self], TaskInstance]]
|
_original_tasks: dict[str, Callable[[Self], Task]]
|
||||||
_original_agents: dict[str, Callable[[Self], AgentInstance]]
|
_original_agents: dict[str, Callable[[Self], Agent]]
|
||||||
_before_kickoff: dict[str, Callable[..., Any]]
|
_before_kickoff: dict[str, Callable[..., Any]]
|
||||||
_after_kickoff: dict[str, Callable[..., Any]]
|
_after_kickoff: dict[str, Callable[..., Any]]
|
||||||
agents: list[AgentInstance]
|
agents: list[Agent]
|
||||||
tasks: list[TaskInstance]
|
tasks: list[Task]
|
||||||
|
|
||||||
|
|
||||||
class DecoratedMethod(Generic[P, R]):
|
class DecoratedMethod(Generic[P, R]):
|
||||||
|
|||||||
Reference in New Issue
Block a user