mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 16:18:30 +00:00
feat: add documentation functions (#1831)
* feat: add docstring * feat: add new docstring * fix: linting --------- Co-authored-by: João Moura <joaomdmoura@gmail.com>
This commit is contained in:
committed by
Devin AI
parent
036661196d
commit
de4d7bf9af
@@ -4,18 +4,23 @@ from typing import Callable
|
|||||||
from crewai import Crew
|
from crewai import Crew
|
||||||
from crewai.project.utils import memoize
|
from crewai.project.utils import memoize
|
||||||
|
|
||||||
|
"""Decorators for defining crew components and their behaviors."""
|
||||||
|
|
||||||
|
|
||||||
def before_kickoff(func):
|
def before_kickoff(func):
|
||||||
|
"""Marks a method to execute before crew kickoff."""
|
||||||
func.is_before_kickoff = True
|
func.is_before_kickoff = True
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
|
||||||
def after_kickoff(func):
|
def after_kickoff(func):
|
||||||
|
"""Marks a method to execute after crew kickoff."""
|
||||||
func.is_after_kickoff = True
|
func.is_after_kickoff = True
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
|
||||||
def task(func):
|
def task(func):
|
||||||
|
"""Marks a method as a crew task."""
|
||||||
func.is_task = True
|
func.is_task = True
|
||||||
|
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
@@ -29,43 +34,51 @@ def task(func):
|
|||||||
|
|
||||||
|
|
||||||
def agent(func):
|
def agent(func):
|
||||||
|
"""Marks a method as a crew agent."""
|
||||||
func.is_agent = True
|
func.is_agent = True
|
||||||
func = memoize(func)
|
func = memoize(func)
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
|
||||||
def llm(func):
|
def llm(func):
|
||||||
|
"""Marks a method as an LLM provider."""
|
||||||
func.is_llm = True
|
func.is_llm = True
|
||||||
func = memoize(func)
|
func = memoize(func)
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
|
||||||
def output_json(cls):
|
def output_json(cls):
|
||||||
|
"""Marks a class as JSON output format."""
|
||||||
cls.is_output_json = True
|
cls.is_output_json = True
|
||||||
return cls
|
return cls
|
||||||
|
|
||||||
|
|
||||||
def output_pydantic(cls):
|
def output_pydantic(cls):
|
||||||
|
"""Marks a class as Pydantic output format."""
|
||||||
cls.is_output_pydantic = True
|
cls.is_output_pydantic = True
|
||||||
return cls
|
return cls
|
||||||
|
|
||||||
|
|
||||||
def tool(func):
|
def tool(func):
|
||||||
|
"""Marks a method as a crew tool."""
|
||||||
func.is_tool = True
|
func.is_tool = True
|
||||||
return memoize(func)
|
return memoize(func)
|
||||||
|
|
||||||
|
|
||||||
def callback(func):
|
def callback(func):
|
||||||
|
"""Marks a method as a crew callback."""
|
||||||
func.is_callback = True
|
func.is_callback = True
|
||||||
return memoize(func)
|
return memoize(func)
|
||||||
|
|
||||||
|
|
||||||
def cache_handler(func):
|
def cache_handler(func):
|
||||||
|
"""Marks a method as a cache handler."""
|
||||||
func.is_cache_handler = True
|
func.is_cache_handler = True
|
||||||
return memoize(func)
|
return memoize(func)
|
||||||
|
|
||||||
|
|
||||||
def crew(func) -> Callable[..., Crew]:
|
def crew(func) -> Callable[..., Crew]:
|
||||||
|
"""Marks a method as the main crew execution point."""
|
||||||
|
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def wrapper(self, *args, **kwargs) -> Crew:
|
def wrapper(self, *args, **kwargs) -> Crew:
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ load_dotenv()
|
|||||||
|
|
||||||
T = TypeVar("T", bound=type)
|
T = TypeVar("T", bound=type)
|
||||||
|
|
||||||
|
"""Base decorator for creating crew classes with configuration and function management."""
|
||||||
|
|
||||||
def CrewBase(cls: T) -> T:
|
def CrewBase(cls: T) -> T:
|
||||||
|
"""Wraps a class with crew functionality and configuration management."""
|
||||||
class WrappedClass(cls): # type: ignore
|
class WrappedClass(cls): # type: ignore
|
||||||
is_crew_class: bool = True # type: ignore
|
is_crew_class: bool = True # type: ignore
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
"""JSON encoder for handling CrewAI specific types."""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
@@ -8,6 +10,7 @@ from pydantic import BaseModel
|
|||||||
|
|
||||||
|
|
||||||
class CrewJSONEncoder(json.JSONEncoder):
|
class CrewJSONEncoder(json.JSONEncoder):
|
||||||
|
"""Custom JSON encoder for CrewAI objects and special types."""
|
||||||
def default(self, obj):
|
def default(self, obj):
|
||||||
if isinstance(obj, BaseModel):
|
if isinstance(obj, BaseModel):
|
||||||
return self._handle_pydantic_model(obj)
|
return self._handle_pydantic_model(obj)
|
||||||
|
|||||||
@@ -6,9 +6,10 @@ from pydantic import BaseModel, ValidationError
|
|||||||
|
|
||||||
from crewai.agents.parser import OutputParserException
|
from crewai.agents.parser import OutputParserException
|
||||||
|
|
||||||
|
"""Parser for converting text outputs into Pydantic models."""
|
||||||
|
|
||||||
class CrewPydanticOutputParser:
|
class CrewPydanticOutputParser:
|
||||||
"""Parses the text into pydantic models"""
|
"""Parses text outputs into specified Pydantic models."""
|
||||||
|
|
||||||
pydantic_object: Type[BaseModel]
|
pydantic_object: Type[BaseModel]
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ from typing import Dict, Optional, Union
|
|||||||
|
|
||||||
from pydantic import BaseModel, Field, PrivateAttr, model_validator
|
from pydantic import BaseModel, Field, PrivateAttr, model_validator
|
||||||
|
|
||||||
|
"""Internationalization support for CrewAI prompts and messages."""
|
||||||
|
|
||||||
class I18N(BaseModel):
|
class I18N(BaseModel):
|
||||||
|
"""Handles loading and retrieving internationalized prompts."""
|
||||||
_prompts: Dict[str, Dict[str, str]] = PrivateAttr()
|
_prompts: Dict[str, Dict[str, str]] = PrivateAttr()
|
||||||
prompt_file: Optional[str] = Field(
|
prompt_file: Optional[str] = Field(
|
||||||
default=None,
|
default=None,
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ from pathlib import Path
|
|||||||
|
|
||||||
import appdirs
|
import appdirs
|
||||||
|
|
||||||
|
"""Path management utilities for CrewAI storage and configuration."""
|
||||||
|
|
||||||
def db_storage_path():
|
def db_storage_path():
|
||||||
|
"""Returns the path for database storage."""
|
||||||
app_name = get_project_directory_name()
|
app_name = get_project_directory_name()
|
||||||
app_author = "CrewAI"
|
app_author = "CrewAI"
|
||||||
|
|
||||||
@@ -14,6 +16,7 @@ def db_storage_path():
|
|||||||
|
|
||||||
|
|
||||||
def get_project_directory_name():
|
def get_project_directory_name():
|
||||||
|
"""Returns the current project directory name."""
|
||||||
project_directory_name = os.environ.get("CREWAI_STORAGE_DIR")
|
project_directory_name = os.environ.get("CREWAI_STORAGE_DIR")
|
||||||
|
|
||||||
if project_directory_name:
|
if project_directory_name:
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ from pydantic import BaseModel, Field
|
|||||||
from crewai.agent import Agent
|
from crewai.agent import Agent
|
||||||
from crewai.task import Task
|
from crewai.task import Task
|
||||||
|
|
||||||
|
"""Handles planning and coordination of crew tasks."""
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class PlanPerTask(BaseModel):
|
class PlanPerTask(BaseModel):
|
||||||
|
"""Represents a plan for a specific task."""
|
||||||
task: str = Field(..., description="The task for which the plan is created")
|
task: str = Field(..., description="The task for which the plan is created")
|
||||||
plan: str = Field(
|
plan: str = Field(
|
||||||
...,
|
...,
|
||||||
@@ -19,6 +20,7 @@ class PlanPerTask(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class PlannerTaskPydanticOutput(BaseModel):
|
class PlannerTaskPydanticOutput(BaseModel):
|
||||||
|
"""Output format for task planning results."""
|
||||||
list_of_plans_per_task: List[PlanPerTask] = Field(
|
list_of_plans_per_task: List[PlanPerTask] = Field(
|
||||||
...,
|
...,
|
||||||
description="Step by step plan on how the agents can execute their tasks using the available tools with mastery",
|
description="Step by step plan on how the agents can execute their tasks using the available tools with mastery",
|
||||||
@@ -26,6 +28,7 @@ class PlannerTaskPydanticOutput(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class CrewPlanner:
|
class CrewPlanner:
|
||||||
|
"""Plans and coordinates the execution of crew tasks."""
|
||||||
def __init__(self, tasks: List[Task], planning_agent_llm: Optional[Any] = None):
|
def __init__(self, tasks: List[Task], planning_agent_llm: Optional[Any] = None):
|
||||||
self.tasks = tasks
|
self.tasks = tasks
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
|
"""Utility for colored console output."""
|
||||||
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
class Printer:
|
class Printer:
|
||||||
|
"""Handles colored console output formatting."""
|
||||||
|
|
||||||
def print(self, content: str, color: Optional[str] = None):
|
def print(self, content: str, color: Optional[str] = None):
|
||||||
if color == "purple":
|
if color == "purple":
|
||||||
self._print_purple(content)
|
self._print_purple(content)
|
||||||
|
|||||||
@@ -6,8 +6,10 @@ from pydantic import BaseModel, Field, PrivateAttr, model_validator
|
|||||||
|
|
||||||
from crewai.utilities.logger import Logger
|
from crewai.utilities.logger import Logger
|
||||||
|
|
||||||
|
"""Controls request rate limiting for API calls."""
|
||||||
|
|
||||||
class RPMController(BaseModel):
|
class RPMController(BaseModel):
|
||||||
|
"""Manages requests per minute limiting."""
|
||||||
max_rpm: Optional[int] = Field(default=None)
|
max_rpm: Optional[int] = Field(default=None)
|
||||||
logger: Logger = Field(default_factory=lambda: Logger(verbose=False))
|
logger: Logger = Field(default_factory=lambda: Logger(verbose=False))
|
||||||
_current_rpm: int = PrivateAttr(default=0)
|
_current_rpm: int = PrivateAttr(default=0)
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ from crewai.memory.storage.kickoff_task_outputs_storage import (
|
|||||||
)
|
)
|
||||||
from crewai.task import Task
|
from crewai.task import Task
|
||||||
|
|
||||||
|
"""Handles storage and retrieval of task execution outputs."""
|
||||||
|
|
||||||
class ExecutionLog(BaseModel):
|
class ExecutionLog(BaseModel):
|
||||||
|
"""Represents a log entry for task execution."""
|
||||||
task_id: str
|
task_id: str
|
||||||
expected_output: Optional[str] = None
|
expected_output: Optional[str] = None
|
||||||
output: Dict[str, Any]
|
output: Dict[str, Any]
|
||||||
@@ -22,6 +24,8 @@ class ExecutionLog(BaseModel):
|
|||||||
return getattr(self, key)
|
return getattr(self, key)
|
||||||
|
|
||||||
|
|
||||||
|
"""Manages storage and retrieval of task outputs."""
|
||||||
|
|
||||||
class TaskOutputStorageHandler:
|
class TaskOutputStorageHandler:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.storage = KickoffTaskOutputsSQLiteStorage()
|
self.storage = KickoffTaskOutputsSQLiteStorage()
|
||||||
|
|||||||
Reference in New Issue
Block a user