Component evidence

UsageMetrics (types/usage_metrics.py)

crewai · lib/crewai/src/crewai/types/usage_metrics.py · python · MIT
aiAI / Agents

Pydantic model for tracking token usage and request metrics.

Source preview first 800 characters · full source over MCP
# Source: https://github.com/crewaiinc/crewai | License: MIT | Copyright 2025 crewAI, Inc
# Provided via justclaw.it.com; keep this notice with the code.
"""Usage metrics tracking for CrewAI execution.

This module provides models for tracking token usage and request metrics
during crew and agent execution.
"""

from typing import Any

from pydantic import BaseModel, Field
from typing_extensions import Self


def _coerce_int(value: Any) -> int:
    if value is None:
        return 0
    try:
        return int(value)
    except (TypeError, ValueError):
        return 0


def _first_int(usage_data: dict[str, Any], *keys: str) -> int:
    """Return the first integer-coercible value from ``usage_data`` under any
    of ``keys``. Falls back to ``0`` when nothing matches."""
    for key in keys

... (truncated -- full source via MCP)