mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-28 09:38:17 +00:00
Compare commits
5 Commits
devin/1769
...
devin/1741
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
24f6530292 | ||
|
|
50fc4e5774 | ||
|
|
9f81fbf28a | ||
|
|
66e787b9d8 | ||
|
|
a421de63e6 |
@@ -1,7 +1,10 @@
|
|||||||
import inspect
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Callable, Dict, TypeVar, cast
|
from typing import Any, Callable, Dict, List, TypeVar, cast
|
||||||
|
|
||||||
|
from crewai.agent import Agent
|
||||||
|
from crewai.task import Task
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
@@ -30,6 +33,10 @@ def CrewBase(cls: T) -> T:
|
|||||||
original_tasks_config_path = getattr(cls, "tasks_config", "config/tasks.yaml")
|
original_tasks_config_path = getattr(cls, "tasks_config", "config/tasks.yaml")
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
# Initialize agents and tasks before anything else
|
||||||
|
self._agents = []
|
||||||
|
self._tasks = []
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.load_configurations()
|
self.load_configurations()
|
||||||
self.map_all_agent_variables()
|
self.map_all_agent_variables()
|
||||||
@@ -250,6 +257,36 @@ def CrewBase(cls: T) -> T:
|
|||||||
callback_functions[callback]() for callback in callbacks
|
callback_functions[callback]() for callback in callbacks
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@property
|
||||||
|
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.
|
||||||
|
"""
|
||||||
|
return self._agents
|
||||||
|
|
||||||
|
@agents.setter
|
||||||
|
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) -> List["Task"]:
|
||||||
|
"""
|
||||||
|
Returns the list of tasks for this crew.
|
||||||
|
This property is populated by the @crew decorator when the crew method is called.
|
||||||
|
"""
|
||||||
|
return self._tasks
|
||||||
|
|
||||||
|
@tasks.setter
|
||||||
|
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.
|
# Include base class (qual)name in the wrapper class (qual)name.
|
||||||
WrappedClass.__name__ = CrewBase.__name__ + "(" + cls.__name__ + ")"
|
WrappedClass.__name__ = CrewBase.__name__ + "(" + cls.__name__ + ")"
|
||||||
WrappedClass.__qualname__ = CrewBase.__qualname__ + "(" + cls.__name__ + ")"
|
WrappedClass.__qualname__ = CrewBase.__qualname__ + "(" + cls.__name__ + ")"
|
||||||
|
|||||||
71
tests/test_crewbase_linting.py
Normal file
71
tests/test_crewbase_linting.py
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
from crewai import Agent, Crew, Process, Task
|
||||||
|
from crewai.project import CrewBase, agent, crew, task
|
||||||
|
|
||||||
|
|
||||||
|
@CrewBase
|
||||||
|
class TestCrewBaseLinting:
|
||||||
|
"""Test class for verifying that CrewBase doesn't cause linting errors."""
|
||||||
|
|
||||||
|
# Override config paths to avoid loading non-existent files
|
||||||
|
agents_config = {}
|
||||||
|
tasks_config = {}
|
||||||
|
|
||||||
|
@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",
|
||||||
|
backstory="Test Backstory"
|
||||||
|
)
|
||||||
|
|
||||||
|
@task
|
||||||
|
def task_one(self) -> Task:
|
||||||
|
"""
|
||||||
|
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",
|
||||||
|
agent=self.agent_one() # Assign the agent to the task
|
||||||
|
)
|
||||||
|
|
||||||
|
@crew
|
||||||
|
def crew(self) -> Crew:
|
||||||
|
"""
|
||||||
|
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
|
||||||
|
process=Process.sequential,
|
||||||
|
verbose=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_crewbase_linting():
|
||||||
|
"""Test that CrewBase doesn't cause linting errors."""
|
||||||
|
crew_instance = TestCrewBaseLinting()
|
||||||
|
crew_obj = crew_instance.crew()
|
||||||
|
|
||||||
|
# Verify that agents and tasks are accessible
|
||||||
|
assert len(crew_instance.agents) > 0
|
||||||
|
assert len(crew_instance.tasks) > 0
|
||||||
|
|
||||||
|
# Verify that the crew object was created correctly
|
||||||
|
assert crew_obj is not None
|
||||||
|
assert isinstance(crew_obj, Crew)
|
||||||
Reference in New Issue
Block a user