Module livekit.agents.metrics.usage_collector

Classes

class UsageCollector
Expand source code
class UsageCollector:
    def __init__(self) -> None:
        self._summary = UsageSummary(0, 0, 0, 0.0)

    def __call__(self, metrics: AgentMetrics) -> None:
        self.collect(metrics)

    def collect(self, metrics: AgentMetrics) -> None:
        if isinstance(metrics, LLMMetrics):
            self._summary.llm_prompt_tokens += metrics.prompt_tokens
            self._summary.llm_completion_tokens += metrics.completion_tokens

        elif isinstance(metrics, TTSMetrics):
            self._summary.tts_characters_count += metrics.characters_count

        elif isinstance(metrics, STTMetrics):
            self._summary.stt_audio_duration += metrics.audio_duration

    def get_summary(self) -> UsageSummary:
        return deepcopy(self._summary)

Methods

def collect(self,
metrics: STTMetrics | LLMMetrics | TTSMetrics | VADMetrics | PipelineSTTMetrics | PipelineEOUMetrics | PipelineLLMMetrics | PipelineTTSMetrics | PipelineVADMetrics | MultimodalLLMMetrics) ‑> None
Expand source code
def collect(self, metrics: AgentMetrics) -> None:
    if isinstance(metrics, LLMMetrics):
        self._summary.llm_prompt_tokens += metrics.prompt_tokens
        self._summary.llm_completion_tokens += metrics.completion_tokens

    elif isinstance(metrics, TTSMetrics):
        self._summary.tts_characters_count += metrics.characters_count

    elif isinstance(metrics, STTMetrics):
        self._summary.stt_audio_duration += metrics.audio_duration
def get_summary(self) ‑> UsageSummary
Expand source code
def get_summary(self) -> UsageSummary:
    return deepcopy(self._summary)
class UsageSummary (llm_prompt_tokens: int,
llm_completion_tokens: int,
tts_characters_count: int,
stt_audio_duration: float)
Expand source code
@dataclass
class UsageSummary:
    llm_prompt_tokens: int
    llm_completion_tokens: int
    tts_characters_count: int
    stt_audio_duration: float

UsageSummary(llm_prompt_tokens: int, llm_completion_tokens: int, tts_characters_count: int, stt_audio_duration: float)

Class variables

var llm_completion_tokens : int
var llm_prompt_tokens : int
var stt_audio_duration : float
var tts_characters_count : int