Module livekit.agents.voice.report

Classes

class SessionReport (recording_options: RecordingOptions,
job_id: str,
room_id: str,
room: str,
options: AgentSessionOptions,
events: list[AgentEvent],
chat_history: ChatContext,
audio_recording_path: Path | None = None,
audio_recording_started_at: float | None = None,
duration: float | None = None,
started_at: float | None = None,
timestamp: float = <factory>,
model_usage: list[ModelUsage] | None = None,
sdk_version: str = <factory>)
Expand source code
@dataclass
class SessionReport:
    recording_options: RecordingOptions
    job_id: str
    room_id: str
    room: str
    options: AgentSessionOptions
    events: list[AgentEvent]
    chat_history: ChatContext
    audio_recording_path: Path | None = None
    audio_recording_started_at: float | None = None
    """Timestamp when the audio recording started"""
    duration: float | None = None
    started_at: float | None = None
    """Timestamp when the session started"""
    timestamp: float = field(default_factory=time.time)
    """Timestamp when the session report was created, typically at the end of the session"""
    model_usage: list[ModelUsage] | None = None
    """Usage summaries for the session, one per model/provider combination"""
    sdk_version: str = field(default_factory=lambda: __version__)
    """Version of the agents SDK"""

    def to_dict(self) -> dict:
        events_dict: list[dict] = []

        for event in self.events:
            if event.type == "metrics_collected":
                continue  # metrics are too noisy, Cloud is using the chat_history as the source of thruth

            events_dict.append(event.model_dump())

        return {
            "job_id": self.job_id,
            "room_id": self.room_id,
            "room": self.room,
            "events": events_dict,
            "audio_recording_path": (
                str(self.audio_recording_path.absolute()) if self.audio_recording_path else None
            ),
            "audio_recording_started_at": self.audio_recording_started_at,
            "options": {
                "allow_interruptions": self.options.interruption["enabled"],
                "discard_audio_if_uninterruptible": self.options.interruption[
                    "discard_audio_if_uninterruptible"
                ],
                "min_interruption_duration": self.options.interruption["min_duration"],
                "min_interruption_words": self.options.interruption["min_words"],
                "min_endpointing_delay": self.options.endpointing["min_delay"],
                "max_endpointing_delay": self.options.endpointing["max_delay"],
                "max_tool_steps": self.options.max_tool_steps,
                "user_away_timeout": self.options.user_away_timeout,
                "min_consecutive_speech_delay": self.options.min_consecutive_speech_delay,
                "preemptive_generation": dict(self.options.preemptive_generation),
            },
            "chat_history": self.chat_history.to_dict(exclude_timestamp=False),
            "timestamp": self.timestamp,
            "usage": self._usage_to_dict() if self.model_usage else None,
            "sdk_version": self.sdk_version,
        }

    def _usage_to_dict(self) -> list[dict] | None:
        if self.model_usage is None:
            return None
        return [summary.model_dump(exclude_defaults=True) for summary in self.model_usage]

SessionReport(recording_options: 'RecordingOptions', job_id: 'str', room_id: 'str', room: 'str', options: 'AgentSessionOptions', events: 'list[AgentEvent]', chat_history: 'ChatContext', audio_recording_path: 'Path | None' = None, audio_recording_started_at: 'float | None' = None, duration: 'float | None' = None, started_at: 'float | None' = None, timestamp: 'float' = , model_usage: 'list[ModelUsage] | None' = None, sdk_version: 'str' = )

Instance variables

var audio_recording_path : pathlib.Path | None
var audio_recording_started_at : float | None

Timestamp when the audio recording started

var chat_history : livekit.agents.llm.chat_context.ChatContext
var duration : float | None
var events : list[livekit.agents.voice.events.UserInputTranscribedEvent | livekit.agents.voice.events.UserStateChangedEvent | livekit.agents.voice.events.AgentStateChangedEvent | livekit.agents.voice.events.AgentFalseInterruptionEvent | livekit.agents.voice.events.MetricsCollectedEvent | livekit.agents.voice.events.SessionUsageUpdatedEvent | livekit.agents.voice.events.ConversationItemAddedEvent | livekit.agents.voice.events.FunctionToolsExecutedEvent | livekit.agents.voice.events.SpeechCreatedEvent | livekit.agents.voice.events.ErrorEvent | livekit.agents.voice.events.CloseEvent | OverlappingSpeechEvent]
var job_id : str
var model_usage : list[livekit.agents.metrics.usage.LLMModelUsage | livekit.agents.metrics.usage.TTSModelUsage | livekit.agents.metrics.usage.STTModelUsage | livekit.agents.metrics.usage.InterruptionModelUsage] | None

Usage summaries for the session, one per model/provider combination

var options : livekit.agents.voice.agent_session.AgentSessionOptions
var recording_options : livekit.agents.voice.agent_session.RecordingOptions
var room : str
var room_id : str
var sdk_version : str

Version of the agents SDK

var started_at : float | None

Timestamp when the session started

var timestamp : float

Timestamp when the session report was created, typically at the end of the session

Methods

def to_dict(self) ‑> dict
Expand source code
def to_dict(self) -> dict:
    events_dict: list[dict] = []

    for event in self.events:
        if event.type == "metrics_collected":
            continue  # metrics are too noisy, Cloud is using the chat_history as the source of thruth

        events_dict.append(event.model_dump())

    return {
        "job_id": self.job_id,
        "room_id": self.room_id,
        "room": self.room,
        "events": events_dict,
        "audio_recording_path": (
            str(self.audio_recording_path.absolute()) if self.audio_recording_path else None
        ),
        "audio_recording_started_at": self.audio_recording_started_at,
        "options": {
            "allow_interruptions": self.options.interruption["enabled"],
            "discard_audio_if_uninterruptible": self.options.interruption[
                "discard_audio_if_uninterruptible"
            ],
            "min_interruption_duration": self.options.interruption["min_duration"],
            "min_interruption_words": self.options.interruption["min_words"],
            "min_endpointing_delay": self.options.endpointing["min_delay"],
            "max_endpointing_delay": self.options.endpointing["max_delay"],
            "max_tool_steps": self.options.max_tool_steps,
            "user_away_timeout": self.options.user_away_timeout,
            "min_consecutive_speech_delay": self.options.min_consecutive_speech_delay,
            "preemptive_generation": dict(self.options.preemptive_generation),
        },
        "chat_history": self.chat_history.to_dict(exclude_timestamp=False),
        "timestamp": self.timestamp,
        "usage": self._usage_to_dict() if self.model_usage else None,
        "sdk_version": self.sdk_version,
    }