faint-chef-17831
12/07/2025, 12:22 PMtall-airline-16756
12/07/2025, 12:22 PMtall-airline-16756
12/07/2025, 12:23 PMllm.ttft).
• LLM end_time (if available).
• TTS time_to_first_byte (tts.ttfb) and audio_playback_start.
• Agent audio playback start (when user actually hears audio).
How to capture these
• Enable Agent Observability and subscribe to metrics/traces for each turn (EOU, LLM, TTS, playback). Use the MetricsCollected / trace spans that include EOUMetrics, LLMMetrics, TTSMetrics, and speech/audio playback timing.
• Correlate by speech_id or turn_id so STT → LLM → TTS → playback events link.
Calculations to compute actual vs perceived difference
1. Baseline (no preemptive): measured_latency_baseline = EOU_end → audio_playback_start = eou + llm.ttft + tts.ttfb (observed)
2. With preemptive: measured_latency_preemptive = EOU_end → audio_playback_start (observed)
3. Overlap_time = max(0, LLM_start - STT_start) overlapping portion while user is still speaking
4. Perceived_saved = measured_latency_baseline - measured_latency_preemptive
◦ Or equivalently: perceived_saved ≈ overlap_time that hides compute behind user speech
1. If LLM finishes before EOU_end, measured_latency_preemptive may approach 0 (user hears immediate response after EOU).
Practical test plan (A/B)
1. Use identical input audio and prompts.
2. Run N trials with preemptive_generation=True and N with it disabled.
3. For each trial log: EOU_end, LLM_start, LLM_ttf, TTS_ttfb, audio_playback_start, speech_id.
4. Compute averages and distributions for:
◦ measured_latency_baseline vs measured_latency_preemptive
◦ perceived_saved per turn
◦ fraction of turns where LLM finished before EOU_end (canceled runs/wasted compute)
Tools & verification
• Use the LiveKit agent traces in the dashboard (Agent Insights → Trace) to visually confirm LLM starts during STT when preemptive is on.
• Export MetricsCollected events to your logs/analytics for programmatic analysis.
• Optionally record audio/video to manually validate perceived timings (time from user stop to agent start).
Caveats to watch for
• If interim transcripts differ from final transcript, preemptive responses may be canceled and wasted compute occurs — this affects efficiency but not the timing math.
• Perceived latency is also affected by conversational design (use of fillers, immediate partial audio, etc.) — measure user perception with UX tests if needed.
Would you like a short code example to log the exact metrics per turn and compute the saved latency automatically?
Sources: Observability data hooks | LiveKit docs | Agents (Python) | livekit/livekit_composite | DeepWiki | https://blog.livekit.io/streamline-troubleshooting-with-agent-observability/#/portal/signup| | Agent speech and audio | LiveKit docsfaint-chef-17831
12/07/2025, 12:47 PMtall-airline-16756
12/07/2025, 12:47 PMon_user_turn_completed hook to run custom logic (RAG, sanitization, context injection) before the final LLM call.
Tradeoffs and practical notes
• Benefit: perceived latency is reduced when the interim transcript was accurate because compute is overlapped with user speech.
• Cost: if the interim transcript misses a critical late detail, the preemptive work is wasted and you incur extra compute/time for the fresh, correct generation — but the final response will reflect the complete user input.
• Mitigation: tune voice activity detection and interim transcript confidence thresholds; only start preemptive generation when interim transcripts meet a confidence threshold to reduce wasted speculative runs.
If you’d like, I can sketch a small flow or code snippet showing how to detect differences between interim and final transcripts and cancel/restart generation automatically. Would you like that?
Sources: examples/voice_agents | livekit/livekit_composite | DeepWiki | Agents (Python) | livekit/livekit_composite | DeepWiki | Pipeline nodes and hooks | LiveKit docs