From cfc0645afb7d7813c173075865147b7a9051db41 Mon Sep 17 00:00:00 2001 From: "Brandon Hancock (bhancock_ai)" <109994880+bhancockio@users.noreply.github.com> Date: Thu, 26 Sep 2024 13:12:24 -0400 Subject: [PATCH] Fixed typing issues for new crews (#1358) --- src/crewai/project/crew_base.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/crewai/project/crew_base.py b/src/crewai/project/crew_base.py index 4c9bbabed..62390e991 100644 --- a/src/crewai/project/crew_base.py +++ b/src/crewai/project/crew_base.py @@ -1,14 +1,19 @@ import inspect from pathlib import Path -from typing import Any, Callable, Dict +from typing import Any, Callable, Dict, Type, TypeVar import yaml from dotenv import load_dotenv +from crewai.crew import Crew + load_dotenv() -def CrewBase(cls): +T = TypeVar("T", bound=Type[Any]) + + +def CrewBase(cls: T) -> T: class WrappedClass(cls): is_crew_class: bool = True # type: ignore @@ -32,6 +37,19 @@ def CrewBase(cls): self.map_all_agent_variables() self.map_all_task_variables() + def crew(self) -> "Crew": + agents = [ + getattr(self, name)() + for name, func in self._get_all_functions().items() + if hasattr(func, "is_agent") + ] + tasks = [ + getattr(self, name)() + for name, func in self._get_all_functions().items() + if hasattr(func, "is_task") + ] + return Crew(agents=agents, tasks=tasks) + @staticmethod def load_yaml(config_path: Path): try: