handsome-dinner-3063
12/06/2025, 3:17 PMtall-airline-16756
12/06/2025, 3:17 PMtall-airline-16756
12/06/2025, 3:18 PMsession.generate_reply() so the UI/voice stays responsive.
• Pre-warm and keep agents/containers ready so you avoid cold-starts on model or service initialization.
• Choose lower-latency models/providers for interactive turns (faster LLMs or smaller models for first-pass replies; reserve larger models for follow-up processing).
• Co-locate services (agent, LLM, STT, TTS) to reduce network RTTs and use private/backbone networks where available.
• Use caching or cheap heuristics for predictable queries (serve cached or template replies immediately while full processing continues in background).
• Design UX for perceived speed: show typing/streaming indicators, play short acknowledgement audio, or display progressive UI placeholders so users see progress before full result.
Implementation options (pick based on your pipeline)
1. Preemptive + streaming: enable preemptive_generation, stream tokens to UI/TTS, cancel/regenerate if context changes.
2. Quick ACK + background work: immediately return a short spoken/text ACK; perform long HTTP calls async and push final result when ready.
3. Hybrid: use a fast smaller model to produce an initial summary/acknowledgement, then replace/extend it with a higher-quality response when the larger model finishes.
Would you like example code for:
• enabling preemptive generation and streaming tokens, or
• a pattern that sends verbal status updates while awaiting long HTTP calls? Sources: Agent session | LiveKit docs | Agent speech and audio | LiveKit docs | External data and RAG | LiveKit Docs | Live Conversations with AI using ChatGPT and WebRTC | Live Conversations with AI using ChatGPT and WebRTChandsome-dinner-3063
12/07/2025, 11:17 AMtall-airline-16756
12/07/2025, 11:17 AMConversationItemAddedEvent to receive finalized messages (user or agent) when a turn is committed. Runs asynchronously and does not block agent flow.
◦ Python example:
from livekit.agents import ConversationItemAddedEvent
@session.on("conversation_item_added")
async def on_conversation_item_added(event: ConversationItemAddedEvent):
text = event.item.text_content
role = event.item.role
# handle/save asynchronously
• Node example:
session.on(voice.AgentSessionEventTypes.ConversationItemAdded, (event) => {
const text = event.item.textContent;
const role = event.item.role;
// handle/save asynchronously
});
• user_input_transcribed event — use UserInputTranscribedEvent and check is_final to capture final STT results for user utterances (non-blocking).
Advanced / lower-level options
• transcription_node (Python only) — override a transcription_node pipeline node to receive transcription chunks (including timing) as an async iterable. Yield through each chunk so pipeline continues; collect or forward data without blocking main agent logic.
async def transcription_node(self, text: AsyncIterable[str], model_settings: ModelSettings) -> AsyncIterable[str]:
async for chunk in text:
# collect or forward
yield chunk
Best practice
• Use conversation_item_added for most end-of-turn collection needs (captures finalized turns, simple to hook into).
• Use transcription_node if you need real-time chunks or TTS-aligned timestamps.
• Ensure your event handlers perform IO asynchronously (e.g., use async DB/HTTP clients or create background tasks) so they never block the agent’s main pipeline.
Would you like a full sample demonstrating non-blocking persistence (e.g., write final transcriptions to a DB or call an async API) in Python or Node?
Sources: Events and error handling | LiveKit docs | Text and transcriptions | LiveKit docs | Pipeline nodes and hooks | LiveKit docs | How to capture real-time agent transcriptions during conversations