Skip to content

feat(livekit): LiveKit cascade instrumentation - #1069

Draft
David Elner (delner) wants to merge 3 commits into
feat/audio-codecsfrom
feat/livekit-cascade-v3
Draft

David Elner (delner) wants to merge 3 commits into
feat/audio-codecsfrom
feat/livekit-cascade-v3

Conversation

@delner

Copy link
Copy Markdown
Contributor

Add LiveKit Python cascade tracing and recording

Adds end-to-end voice traces for LiveKit cascade sessions, including user speech, transcription, model responses, tools and agent speech. When audio recording is opted-in, it is linked to the traces.

Opt-in to the audio you want to capture:

export BRAINTRUST_CAPTURE_USER_AUDIO_ATTACHMENTS=true
export BRAINTRUST_CAPTURE_AGENT_AUDIO_ATTACHMENTS=true

Call setup in each worker before starting its LiveKit session:

import braintrust
from braintrust.integrations.livekit_agents import setup_livekit_agents

braintrust.init_logger(project="voice-agent")
setup_livekit_agents()

With braintrust-audio installed, recordings use Opus/Ogg by default. SDK auto-instrumentation also enables the integration.

A tool-using reply produces a trace like:

session                         ← recording attachments
├─ user_turn
│  ├─ user_speech
│  └─ stt
└─ agent_turn
   ├─ llm_response
   ├─ lookup_order
   ├─ llm_response              ← tool continuation
   ├─ tts
   └─ agent_speech              ← confirmed playback

See the runnable cascade example.

Design

flowchart LR
    L[LiveKit framework hooks] --> T[Session / turn / operation spans]
    L --> P[Consumed input + confirmed playback]
    P --> R[Common recorder + optional codecs]
    R --> A[Session audio attachments]
Loading
  • Opt-in audio recording flags and respect of LiveKit PII flags avoid unwanted capture/export of data.
  • On shutdown remaining recording audio/data is flushed.

Pin matching provider plugins, remove the older-version target and cassettes, and refresh the dependency lock for the qualified LiveKit release.
Own v3 session and operation spans, normalize model inputs, enforce effective privacy on canonical and supplemental provider records, and record only playback-confirmed output. Include lifecycle draining, auto instrumentation and recorded RoomIO regressions.
Document audio opt-ins, privacy, direct upload semantics and beta limitations. Add the executable cascade example and describe the local review stack.
@delner

Copy link
Copy Markdown
Contributor Author

First pass on implementation, may require more refactoring to get the design/behavior right.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant