mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-28 17:48:13 +00:00
Compare commits
4 Commits
devin/1744
...
63028e1b20
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
63028e1b20 | ||
|
|
81759e8c72 | ||
|
|
27472ba69e | ||
|
|
25aa774d8c |
@@ -23,7 +23,6 @@ from crewai.utilities.constants import TRAINED_AGENTS_DATA_FILE, TRAINING_DATA_F
|
||||
from crewai.utilities.converter import generate_model_description
|
||||
from crewai.utilities.token_counter_callback import TokenCalcHandler
|
||||
from crewai.utilities.training_handler import CrewTrainingHandler
|
||||
from crewai.utilities.typing import AgentConfig
|
||||
|
||||
agentops = None
|
||||
|
||||
@@ -89,7 +88,6 @@ class Agent(BaseAgent):
|
||||
function_calling_llm: Optional[Any] = Field(
|
||||
description="Language model that will run the agent.", default=None
|
||||
)
|
||||
config: Optional[Union[Dict[str, Any], AgentConfig]] = Field(default=None)
|
||||
system_template: Optional[str] = Field(
|
||||
default=None, description="System format for the agent."
|
||||
)
|
||||
|
||||
@@ -14,13 +14,13 @@ class Knowledge(BaseModel):
|
||||
Knowledge is a collection of sources and setup for the vector store to save and query relevant context.
|
||||
Args:
|
||||
sources: List[BaseKnowledgeSource] = Field(default_factory=list)
|
||||
storage: KnowledgeStorage = Field(default_factory=KnowledgeStorage)
|
||||
storage: Optional[KnowledgeStorage] = Field(default=None)
|
||||
embedder_config: Optional[Dict[str, Any]] = None
|
||||
"""
|
||||
|
||||
sources: List[BaseKnowledgeSource] = Field(default_factory=list)
|
||||
model_config = ConfigDict(arbitrary_types_allowed=True)
|
||||
storage: KnowledgeStorage = Field(default_factory=KnowledgeStorage)
|
||||
storage: Optional[KnowledgeStorage] = Field(default=None)
|
||||
embedder_config: Optional[Dict[str, Any]] = None
|
||||
collection_name: Optional[str] = None
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class BaseFileKnowledgeSource(BaseKnowledgeSource, ABC):
|
||||
default_factory=list, description="The path to the file"
|
||||
)
|
||||
content: Dict[Path, str] = Field(init=False, default_factory=dict)
|
||||
storage: KnowledgeStorage = Field(default_factory=KnowledgeStorage)
|
||||
storage: Optional[KnowledgeStorage] = Field(default=None)
|
||||
safe_file_paths: List[Path] = Field(default_factory=list)
|
||||
|
||||
@field_validator("file_path", "file_paths", mode="before")
|
||||
@@ -62,7 +62,10 @@ class BaseFileKnowledgeSource(BaseKnowledgeSource, ABC):
|
||||
|
||||
def _save_documents(self):
|
||||
"""Save the documents to the storage."""
|
||||
self.storage.save(self.chunks)
|
||||
if self.storage:
|
||||
self.storage.save(self.chunks)
|
||||
else:
|
||||
raise ValueError("No storage found to save documents.")
|
||||
|
||||
def convert_to_path(self, path: Union[Path, str]) -> Path:
|
||||
"""Convert a path to a Path object."""
|
||||
|
||||
@@ -16,7 +16,7 @@ class BaseKnowledgeSource(BaseModel, ABC):
|
||||
chunk_embeddings: List[np.ndarray] = Field(default_factory=list)
|
||||
|
||||
model_config = ConfigDict(arbitrary_types_allowed=True)
|
||||
storage: KnowledgeStorage = Field(default_factory=KnowledgeStorage)
|
||||
storage: Optional[KnowledgeStorage] = Field(default=None)
|
||||
metadata: Dict[str, Any] = Field(default_factory=dict) # Currently unused
|
||||
collection_name: Optional[str] = Field(default=None)
|
||||
|
||||
@@ -46,4 +46,7 @@ class BaseKnowledgeSource(BaseModel, ABC):
|
||||
Save the documents to the storage.
|
||||
This method should be called after the chunks and embeddings are generated.
|
||||
"""
|
||||
self.storage.save(self.chunks)
|
||||
if self.storage:
|
||||
self.storage.save(self.chunks)
|
||||
else:
|
||||
raise ValueError("No storage found to save documents.")
|
||||
|
||||
@@ -16,12 +16,6 @@ def after_kickoff(func):
|
||||
|
||||
|
||||
def task(func):
|
||||
"""Decorator to mark a method as a task creator.
|
||||
|
||||
When applied to a method in a class decorated with @CrewBase,
|
||||
this makes the method's return value accessible as an element
|
||||
of the self.tasks list.
|
||||
"""
|
||||
func.is_task = True
|
||||
|
||||
@wraps(func)
|
||||
@@ -35,12 +29,6 @@ def task(func):
|
||||
|
||||
|
||||
def agent(func):
|
||||
"""Decorator to mark a method as an agent creator.
|
||||
|
||||
When applied to a method in a class decorated with @CrewBase,
|
||||
this makes the method's return value accessible as an element
|
||||
of the self.agents list.
|
||||
"""
|
||||
func.is_agent = True
|
||||
func = memoize(func)
|
||||
return func
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import inspect
|
||||
from pathlib import Path
|
||||
from typing import Any, Callable, Dict, List, TypeVar, cast
|
||||
from typing import Any, Callable, Dict, TypeVar, cast
|
||||
|
||||
import yaml
|
||||
from dotenv import load_dotenv
|
||||
@@ -66,9 +66,6 @@ def CrewBase(cls: T) -> T:
|
||||
self._kickoff = self._filter_functions(
|
||||
self._original_functions, "is_kickoff"
|
||||
)
|
||||
|
||||
self.agents = [] # type: List[Any]
|
||||
self.tasks = [] # type: List[Any]
|
||||
|
||||
@staticmethod
|
||||
def load_yaml(config_path: Path):
|
||||
|
||||
@@ -41,7 +41,6 @@ from crewai.tools.base_tool import BaseTool
|
||||
from crewai.utilities.config import process_config
|
||||
from crewai.utilities.converter import Converter, convert_to_model
|
||||
from crewai.utilities.i18n import I18N
|
||||
from crewai.utilities.typing import TaskConfig
|
||||
|
||||
|
||||
class Task(BaseModel):
|
||||
@@ -75,7 +74,7 @@ class Task(BaseModel):
|
||||
expected_output: str = Field(
|
||||
description="Clear definition of expected output for the task."
|
||||
)
|
||||
config: Optional[Union[Dict[str, Any], TaskConfig]] = Field(
|
||||
config: Optional[Dict[str, Any]] = Field(
|
||||
description="Configuration for the agent",
|
||||
default=None,
|
||||
)
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
from typing import Dict, List, Optional, Any, TypedDict, Union
|
||||
|
||||
class AgentConfig(TypedDict, total=False):
|
||||
"""TypedDict for agent configuration loaded from YAML."""
|
||||
role: str
|
||||
goal: str
|
||||
backstory: str
|
||||
verbose: bool
|
||||
|
||||
class TaskConfig(TypedDict, total=False):
|
||||
"""TypedDict for task configuration loaded from YAML."""
|
||||
description: str
|
||||
expected_output: str
|
||||
agent: str # Role of the agent to execute this task
|
||||
@@ -1,55 +0,0 @@
|
||||
from typing import Dict, Any
|
||||
|
||||
import pytest
|
||||
|
||||
from crewai.agent import Agent
|
||||
from crewai.task import Task
|
||||
from crewai.utilities.typing import AgentConfig, TaskConfig
|
||||
|
||||
|
||||
def test_agent_with_config_dict():
|
||||
config: AgentConfig = {
|
||||
"role": "Test Agent",
|
||||
"goal": "Test Goal",
|
||||
"backstory": "Test Backstory",
|
||||
"verbose": True
|
||||
}
|
||||
|
||||
agent = Agent(config=config)
|
||||
|
||||
assert agent.role == "Test Agent"
|
||||
assert agent.goal == "Test Goal"
|
||||
assert agent.backstory == "Test Backstory"
|
||||
assert agent.verbose is True
|
||||
|
||||
|
||||
def test_agent_with_yaml_config():
|
||||
config: Dict[str, Any] = {
|
||||
"researcher": {
|
||||
"role": "Researcher",
|
||||
"goal": "Research Goal",
|
||||
"backstory": "Researcher Backstory",
|
||||
"verbose": True
|
||||
}
|
||||
}
|
||||
|
||||
agent = Agent(config=config["researcher"])
|
||||
|
||||
assert agent.role == "Researcher"
|
||||
assert agent.goal == "Research Goal"
|
||||
assert agent.backstory == "Researcher Backstory"
|
||||
|
||||
|
||||
def test_task_with_config_dict():
|
||||
config: TaskConfig = {
|
||||
"description": "Test Task",
|
||||
"expected_output": "Test Output",
|
||||
"agent": "researcher"
|
||||
}
|
||||
|
||||
agent = Agent(role="Researcher", goal="Goal", backstory="Backstory")
|
||||
task = Task(config=config, agent=agent)
|
||||
|
||||
assert task.description == "Test Task"
|
||||
assert task.expected_output == "Test Output"
|
||||
assert task.agent == agent
|
||||
Reference in New Issue
Block a user