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.

chore: update typing in types module to Python 3.10+ syntax (#3482)

Greyson LaLonde079cb72f6e97
diff --git a/src/crewai/types/crew_chat.py b/src/crewai/types/crew_chat.py
index 354642442..2873700f4 100644
--- a/src/crewai/types/crew_chat.py
+++ b/src/crewai/types/crew_chat.py
@@ -1,16 +1,22 @@
-from typing import List
+"""Crew chat input models.
+
+This module provides models for defining chat inputs and fields
+for crew interactions.
+"""
from pydantic import BaseModel, Field
class ChatInputField(BaseModel):
- """
- Represents a single required input for the crew, with a name and short description.
+ """Represents a single required input for the crew.
+
Example:
- {
- "name": "topic",
- "description": "The topic to focus on for the conversation"
- }
+ ```python
+ field = ChatInputField(
+ name="topic",
+ description="The topic to focus on for the conversation"
+ )
+ ```
"""
name: str = Field(..., description="The name of the input field")
@@ -18,23 +24,25 @@ class ChatInputField(BaseModel):
class ChatInputs(BaseModel):
- """
- Holds a high-level crew_description plus a list of ChatInputFields.
+ """Holds crew metadata and input field definitions.
+
Example:
- {
- "crew_name": "topic-based-qa",
- "crew_description": "Use this crew for topic-based Q&A",
- "inputs": [
- {"name": "topic", "description": "The topic to focus on"},
- {"name": "username", "description": "Name of the user"},
+ ```python
+ inputs = ChatInputs(
+ crew_name="topic-based-qa",
+ crew_description="Use this crew for topic-based Q&A",
+ inputs=[
+ ChatInputField(name="topic", description="The topic to focus on"),
+ ChatInputField(name="username", description="Name of the user"),
]
- }
+ )
+ ```
"""
crew_name: str = Field(..., description="The name of the crew")
crew_description: str = Field(
..., description="A description of the crew's purpose"
)
- inputs: List[ChatInputField] = Field(
+ inputs: list[ChatInputField] = Field(
default_factory=list, description="A list of input fields for the crew"
)
diff --git a/src/crewai/types/hitl.py b/src/crewai/types/hitl.py
index 80105a29f..d5fd33e14 100644
--- a/src/crewai/types/hitl.py
+++ b/src/crewai/types/hitl.py
@@ -1,18 +1,37 @@
-from typing import List, Dict, TypedDict
+"""Human-in-the-loop (HITL) type definitions.
+
+This module provides type definitions for human-in-the-loop interactions
+in crew executions.
+"""
+
+from typing import TypedDict
class HITLResumeInfo(TypedDict, total=False):
- """HITL resume information passed from flow to crew."""
+ """HITL resume information passed from flow to crew.
+
+ Attributes:
+ task_id: Unique identifier for the task.
+ crew_execution_id: Unique identifier for the crew execution.
+ task_key: Key identifying the specific task.
+ task_output: Output from the task before human intervention.
+ human_feedback: Feedback provided by the human.
+ previous_messages: History of messages in the conversation.
+ """
task_id: str
crew_execution_id: str
task_key: str
task_output: str
human_feedback: str
- previous_messages: List[Dict[str, str]]
+ previous_messages: list[dict[str, str]]
class CrewInputsWithHITL(TypedDict, total=False):
- """Crew inputs that may contain HITL resume information."""
+ """Crew inputs that may contain HITL resume information.
+
+ Attributes:
+ _hitl_resume: Optional HITL resume information for continuing execution.
+ """
_hitl_resume: HITLResumeInfo
diff --git a/src/crewai/types/usage_metrics.py b/src/crewai/types/usage_metrics.py
index e87a79e33..77e9ef598 100644
--- a/src/crewai/types/usage_metrics.py
+++ b/src/crewai/types/usage_metrics.py
@@ -1,9 +1,15 @@
+"""Usage metrics tracking for CrewAI execution.
+
+This module provides models for tracking token usage and request metrics
+during crew and agent execution.
+"""
+
from pydantic import BaseModel, Field
+from typing_extensions import Self
class UsageMetrics(BaseModel):
- """
- Model to track usage metrics for the crew's execution.
+ """Track usage metrics for crew execution.
Attributes:
total_tokens: Total number of tokens used.
@@ -27,12 +33,11 @@ class UsageMetrics(BaseModel):
default=0, description="Number of successful requests made."
)
- def add_usage_metrics(self, usage_metrics: "UsageMetrics"):
- """
- Add the usage metrics from another UsageMetrics object.
+ def add_usage_metrics(self, usage_metrics: Self) -> None:
+ """Add usage metrics from another UsageMetrics object.
Args:
- usage_metrics (UsageMetrics): The usage metrics to add.
+ usage_metrics: The usage metrics to add.
"""
self.total_tokens += usage_metrics.total_tokens
self.prompt_tokens += usage_metrics.prompt_tokens