Fixed typing issues for new crews (#1358)

This commit is contained in:
Brandon Hancock (bhancock_ai)
2024-09-26 13:12:24 -04:00
committed by GitHub
parent fb46fb9ca3
commit 164e7895bf

View File

@@ -1,14 +1,19 @@
import inspect import inspect
from pathlib import Path from pathlib import Path
from typing import Any, Callable, Dict from typing import Any, Callable, Dict, Type, TypeVar
import yaml import yaml
from dotenv import load_dotenv from dotenv import load_dotenv
from crewai.crew import Crew
load_dotenv() load_dotenv()
def CrewBase(cls): T = TypeVar("T", bound=Type[Any])
def CrewBase(cls: T) -> T:
class WrappedClass(cls): class WrappedClass(cls):
is_crew_class: bool = True # type: ignore is_crew_class: bool = True # type: ignore
@@ -32,6 +37,19 @@ def CrewBase(cls):
self.map_all_agent_variables() self.map_all_agent_variables()
self.map_all_task_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 @staticmethod
def load_yaml(config_path: Path): def load_yaml(config_path: Path):
try: try: