Skip to content

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.

feat: add documentation functions (#1831)

Marco Vinciguerrabfe2c44f55a7
diff --git a/src/crewai/project/annotations.py b/src/crewai/project/annotations.py
index bf0051c4d..d7c636ccf 100644
--- a/src/crewai/project/annotations.py
+++ b/src/crewai/project/annotations.py
@@ -4,18 +4,23 @@ from typing import Callable
from crewai import Crew
from crewai.project.utils import memoize
+"""Decorators for defining crew components and their behaviors."""
+
def before_kickoff(func):
+ """Marks a method to execute before crew kickoff."""
func.is_before_kickoff = True
return func
def after_kickoff(func):
+ """Marks a method to execute after crew kickoff."""
func.is_after_kickoff = True
return func
def task(func):
+ """Marks a method as a crew task."""
func.is_task = True
@wraps(func)
@@ -29,43 +34,51 @@ def task(func):
def agent(func):
+ """Marks a method as a crew agent."""
func.is_agent = True
func = memoize(func)
return func
def llm(func):
+ """Marks a method as an LLM provider."""
func.is_llm = True
func = memoize(func)
return func
def output_json(cls):
+ """Marks a class as JSON output format."""
cls.is_output_json = True
return cls
def output_pydantic(cls):
+ """Marks a class as Pydantic output format."""
cls.is_output_pydantic = True
return cls
def tool(func):
+ """Marks a method as a crew tool."""
func.is_tool = True
return memoize(func)
def callback(func):
+ """Marks a method as a crew callback."""
func.is_callback = True
return memoize(func)
def cache_handler(func):
+ """Marks a method as a cache handler."""
func.is_cache_handler = True
return memoize(func)
def crew(func) -> Callable[..., Crew]:
+ """Marks a method as the main crew execution point."""
@wraps(func)
def wrapper(self, *args, **kwargs) -> Crew:
diff --git a/src/crewai/project/crew_base.py b/src/crewai/project/crew_base.py
index 0b43882f2..ea518be70 100644
--- a/src/crewai/project/crew_base.py
+++ b/src/crewai/project/crew_base.py
@@ -9,8 +9,10 @@ load_dotenv()
T = TypeVar("T", bound=type)
+"""Base decorator for creating crew classes with configuration and function management."""
def CrewBase(cls: T) -> T:
+ """Wraps a class with crew functionality and configuration management."""
class WrappedClass(cls): # type: ignore
is_crew_class: bool = True # type: ignore
diff --git a/src/crewai/utilities/crew_json_encoder.py b/src/crewai/utilities/crew_json_encoder.py
index 298c9681a..6e667431d 100644
--- a/src/crewai/utilities/crew_json_encoder.py
+++ b/src/crewai/utilities/crew_json_encoder.py
@@ -1,3 +1,5 @@
+"""JSON encoder for handling CrewAI specific types."""
+
import json
from datetime import date, datetime
from decimal import Decimal
@@ -8,6 +10,7 @@ from pydantic import BaseModel
class CrewJSONEncoder(json.JSONEncoder):
+ """Custom JSON encoder for CrewAI objects and special types."""
def default(self, obj):
if isinstance(obj, BaseModel):
return self._handle_pydantic_model(obj)
diff --git a/src/crewai/utilities/crew_pydantic_output_parser.py b/src/crewai/utilities/crew_pydantic_output_parser.py
index c269f3189..d0dbfae06 100644
--- a/src/crewai/utilities/crew_pydantic_output_parser.py
+++ b/src/crewai/utilities/crew_pydantic_output_parser.py
@@ -6,9 +6,10 @@ from pydantic import BaseModel, ValidationError
from crewai.agents.parser import OutputParserException
+"""Parser for converting text outputs into Pydantic models."""
class CrewPydanticOutputParser:
- """Parses the text into pydantic models"""
+ """Parses text outputs into specified Pydantic models."""
pydantic_object: Type[BaseModel]
diff --git a/src/crewai/utilities/i18n.py b/src/crewai/utilities/i18n.py
index ebf1abcda..f2540e455 100644
--- a/src/crewai/utilities/i18n.py
+++ b/src/crewai/utilities/i18n.py
@@ -4,8 +4,10 @@ from typing import Dict, Optional, Union
from pydantic import BaseModel, Field, PrivateAttr, model_validator
+"""Internationalization support for CrewAI prompts and messages."""
class I18N(BaseModel):
+ """Handles loading and retrieving internationalized prompts."""
_prompts: Dict[str, Dict[str, str]] = PrivateAttr()
prompt_file: Optional[str] = Field(
default=None,
diff --git a/src/crewai/utilities/paths.py b/src/crewai/utilities/paths.py
index 51cf8b4e4..9bf167ee6 100644
--- a/src/crewai/utilities/paths.py
+++ b/src/crewai/utilities/paths.py
@@ -3,8 +3,10 @@ from pathlib import Path
import appdirs
+"""Path management utilities for CrewAI storage and configuration."""
def db_storage_path():
+ """Returns the path for database storage."""
app_name = get_project_directory_name()
app_author = "CrewAI"
@@ -14,6 +16,7 @@ def db_storage_path():
def get_project_directory_name():
+ """Returns the current project directory name."""
project_directory_name = os.environ.get("CREWAI_STORAGE_DIR")
if project_directory_name:
diff --git a/src/crewai/utilities/planning_handler.py b/src/crewai/utilities/planning_handler.py
index 21ee093a1..9092dedda 100644
--- a/src/crewai/utilities/planning_handler.py
+++ b/src/crewai/utilities/planning_handler.py
@@ -7,10 +7,11 @@ from pydantic import BaseModel, Field
from crewai.agent import Agent
from crewai.task import Task
+"""Handles planning and coordination of crew tasks."""
logger = logging.getLogger(__name__)
-
class PlanPerTask(BaseModel):
+ """Represents a plan for a specific task."""
task: str = Field(..., description="The task for which the plan is created")
plan: str = Field(
...,
@@ -19,6 +20,7 @@ class PlanPerTask(BaseModel):
class PlannerTaskPydanticOutput(BaseModel):
+ """Output format for task planning results."""
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",
@@ -26,6 +28,7 @@ class PlannerTaskPydanticOutput(BaseModel):
class CrewPlanner:
+ """Plans and coordinates the execution of crew tasks."""
def __init__(self, tasks: List[Task], planning_agent_llm: Optional[Any] = None):
self.tasks = tasks
diff --git a/src/crewai/utilities/printer.py b/src/crewai/utilities/printer.py
index edb339c29..abebf6aae 100644
--- a/src/crewai/utilities/printer.py
+++ b/src/crewai/utilities/printer.py
@@ -1,7 +1,11 @@
+"""Utility for colored console output."""
+
from typing import Optional
class Printer:
+ """Handles colored console output formatting."""
+
def print(self, content: str, color: Optional[str] = None):
if color == "purple":
self._print_purple(content)
diff --git a/src/crewai/utilities/rpm_controller.py b/src/crewai/utilities/rpm_controller.py
index 5ee054c5f..f2d90615c 100644
--- a/src/crewai/utilities/rpm_controller.py
+++ b/src/crewai/utilities/rpm_controller.py
@@ -6,8 +6,10 @@ from pydantic import BaseModel, Field, PrivateAttr, model_validator
from crewai.utilities.logger import Logger
+"""Controls request rate limiting for API calls."""
class RPMController(BaseModel):
+ """Manages requests per minute limiting."""
max_rpm: Optional[int] = Field(default=None)
logger: Logger = Field(default_factory=lambda: Logger(verbose=False))
_current_rpm: int = PrivateAttr(default=0)
diff --git a/src/crewai/utilities/task_output_storage_handler.py b/src/crewai/utilities/task_output_storage_handler.py
index 34cdaccbb..80e749bee 100644
--- a/src/crewai/utilities/task_output_storage_handler.py
+++ b/src/crewai/utilities/task_output_storage_handler.py
@@ -8,8 +8,10 @@ from crewai.memory.storage.kickoff_task_outputs_storage import (
)
from crewai.task import Task
+"""Handles storage and retrieval of task execution outputs."""
class ExecutionLog(BaseModel):
+ """Represents a log entry for task execution."""
task_id: str
expected_output: Optional[str] = None
output: Dict[str, Any]
@@ -22,6 +24,8 @@ class ExecutionLog(BaseModel):
return getattr(self, key)
+"""Manages storage and retrieval of task outputs."""
+
class TaskOutputStorageHandler:
def __init__(self) -> None:
self.storage = KickoffTaskOutputsSQLiteStorage()