diff --git a/src/crewai/project/crew_base.py b/src/crewai/project/crew_base.py index b5c93240b..8aecce608 100644 --- a/src/crewai/project/crew_base.py +++ b/src/crewai/project/crew_base.py @@ -1,7 +1,7 @@ import inspect import logging from pathlib import Path -from typing import Any, Callable, Dict, TypeVar, cast +from typing import Any, Callable, Dict, List, TypeVar, cast import yaml from dotenv import load_dotenv @@ -29,11 +29,6 @@ def CrewBase(cls: T) -> T: ) original_tasks_config_path = getattr(cls, "tasks_config", "config/tasks.yaml") - # Initialize empty agents and tasks lists for linting purposes - # These will be populated by the @crew decorator when the crew method is called - _agents = [] - _tasks = [] - def __init__(self, *args, **kwargs): # Initialize agents and tasks before anything else self._agents = [] @@ -260,7 +255,7 @@ def CrewBase(cls: T) -> T: ] @property - def agents(self): + def agents(self) -> List["Agent"]: """ Returns the list of agents for this crew. This property is populated by the @crew decorator when the crew method is called. @@ -268,12 +263,14 @@ def CrewBase(cls: T) -> T: return self._agents @agents.setter - def agents(self, value): + def agents(self, value: List["Agent"]) -> None: """Sets the list of agents for this crew.""" + if not isinstance(value, list): + raise TypeError("Agents must be provided as a list") self._agents = value @property - def tasks(self): + def tasks(self) -> List["Task"]: """ Returns the list of tasks for this crew. This property is populated by the @crew decorator when the crew method is called. @@ -281,8 +278,10 @@ def CrewBase(cls: T) -> T: return self._tasks @tasks.setter - def tasks(self, value): + def tasks(self, value: List["Task"]) -> None: """Sets the list of tasks for this crew.""" + if not isinstance(value, list): + raise TypeError("Tasks must be provided as a list") self._tasks = value # Include base class (qual)name in the wrapper class (qual)name. diff --git a/tests/test_crewbase_linting.py b/tests/test_crewbase_linting.py index 354d1923c..4c6c8ba51 100644 --- a/tests/test_crewbase_linting.py +++ b/tests/test_crewbase_linting.py @@ -14,6 +14,12 @@ class TestCrewBaseLinting: @agent def agent_one(self) -> Agent: + """ + Creates a test agent for validation purposes. + + Returns: + Agent: A configured test agent instance + """ return Agent( role="Test Agent", goal="Test Goal", @@ -22,7 +28,12 @@ class TestCrewBaseLinting: @task def task_one(self) -> Task: - # Create a task with an agent assigned to it + """ + Creates a test task with an agent assigned to it. + + Returns: + Task: A configured test task instance with an agent assigned + """ return Task( description="Test Description", expected_output="Test Output", @@ -31,7 +42,13 @@ class TestCrewBaseLinting: @crew def crew(self) -> Crew: - # Access self.agents and self.tasks to verify no linting errors + """ + Creates a test crew with agents and tasks. + This method accesses self.agents and self.tasks to verify no linting errors. + + Returns: + Crew: A configured test crew instance + """ return Crew( agents=self.agents, # Should not cause linting errors tasks=self.tasks, # Should not cause linting errors