crooked-vr-68387
10/30/2025, 3:37 AMtall-airline-16756
10/30/2025, 3:37 AMtall-airline-16756
10/30/2025, 3:37 AMtts_node method to decide which provider to use for text synthesis based on the context. It’s a neat way to customize behavior.
• LiveKit Inference: This is a simpler option where you just update the tts configuration string in the agent session to switch providers smoothly.
Each of these methods works well depending on what you’re aiming for. If you’d like, I’d be happy to walk you through the detailed steps for any of these approaches—just let me know!
Sources: Introducing LiveKit Inference: A unified model interface for voice AI | docs/index.yaml | Pipeline nodes and hooks | LiveKit Docscrooked-vr-68387
10/30/2025, 3:38 AMtall-airline-16756
10/30/2025, 3:39 AMstt_node, llm_node, or tts_node) in your agent subclass. This approach lets you connect with external models, whether they're self-hosted, local, or accessed through APIs.
Here are some friendly examples to guide you:
• You can override llm_node to connect with a custom LLM API or a model hosted locally.
• Running ONNX models locally is also an option by downloading and incorporating them into your pipeline.
• If you want to switch between models on the fly, you can add conditional logic or use agent transfer patterns to make that happen smoothly.
If it helps, I’d be happy to provide a specific code example—whether that’s integrating a self-hosted LLM, using a local ONNX model, or switching between custom TTS engines. Just let me know what you'd prefer!
Sources: livekit-agents/livekit/agents/voice/agent.py | plugins/livekit/src/turn_detector/base.ts | examples/face_landmark/README.md | pipeline-tts/tts_comparison/README.md | Introducing LiveKit Inference: A unified model interface for voice AIcrooked-vr-68387
10/30/2025, 3:40 AMtall-airline-16756
10/30/2025, 3:41 AMfrom livekit.agents import Agent, AgentSession
from livekit.agents.llm import function_tool
from livekit.plugins import silero
class ShortAgent(Agent):
def __init__(self) -> None:
super().__init__(
instructions="You are a helpful agent. Be as brief as possible.",
stt="assemblyai/universal-streaming",
llm="openai/gpt-4.1-mini",
tts="cartesia/sonic-2:6f84f4b8-58a2-430c-8c79-688dad597532",
vad=silero.VAD.load()
)
@function_tool
async def change_agent(self):
"""Change the agent to the long agent."""
self.session.update_agent(LongAgent())
class LongAgent(Agent):
def __init__(self) -> None:
super().__init__(
instructions="You are a helpful agent. Respond in overly verbose, flowery sentences.",
stt="assemblyai/universal-streaming",
llm="openai/gpt-4.1-mini",
tts="cartesia/sonic-2:6f84f4b8-58a2-430c-8c79-688dad597532",
vad=silero.VAD.load()
)
@function_tool
async def change_agent(self):
"""Change the agent to the short agent."""
self.session.update_agent(ShortAgent())
In this example, the change_agent function tool lets you smoothly switch between two agents with different configurations. It’s a flexible approach you can easily expand to include more models or providers based on your needs.
If you have any questions or would like me to walk you through more examples, please don’t hesitate to ask. I’m here to help!
Sources: basics/say_in_voice.py | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real... | Models | LiveKit Docscrooked-vr-68387
10/30/2025, 3:45 AMtall-airline-16756
10/30/2025, 3:46 AMdetectLanguage option. This will automatically detect the language from the user’s input, making things much smoother.
2. Dynamic Model Updates: You can then use the updateOptions() method to switch the STT and TTS models on the fly, based on the language detected. It’s a great way to keep the experience seamless for your users.
3. Multilingual Turn Detection: Don’t forget to take advantage of LiveKit’s multilingual turn detection model, which is designed to handle conversations with mixed languages effortlessly.
Here’s a simple Node.js example to illustrate this:
import { Agent } from '@livekit/agents';
import { STT } from '@livekit/agents-plugin-deepgram';
class MultilingualAgent extends Agent {
constructor() {
super();
this.currentLanguage = 'en-US';
// Configure STT with language detection
this.stt = new STT({
detectLanguage: true,
model: 'nova-2-general',
interimResults: true
});
}
async onUserInputTranscribed(userMsg, metadata) {
const detectedLanguage = metadata?.language;
if (detectedLanguage && detectedLanguage !== this.currentLanguage) {
await this.switchLanguage(detectedLanguage);
}
await this.processUserInput(userMsg);
}
async switchLanguage(newLanguage) {
this.stt.updateOptions({ language: newLanguage });
this.currentLanguage = newLanguage;
await this.say(`Switched to ${newLanguage}. How can I help you?`);
}
}
This example shows how the language is detected dynamically and how the STT and TTS configurations update accordingly. If you have any questions or would like me to walk you through more examples, just let me know—I’m here to help!
Sources: plugins/livekit/src/turn_detector/index.ts | Speech-to-text (STT) models | LiveKit Docs | LiveKit turn detector plugin | LiveKit Docs | Building the all-in-one platform for voice AI agentscrooked-vr-68387
12/20/2025, 8:17 AMtall-airline-16756
12/20/2025, 8:18 AMfrom livekit.agents.stt import FallbackAdapter
from livekit.plugins import deepgram, google
stt_fallback = FallbackAdapter(
stt=[deepgram.STT(), google.STT()],
vad=vad, # Required if any non-streaming STT is used
attempt_timeout=10.0,
max_retry_per_stt=1
)
1. Handle Errors with Event Listeners: Use the on_error event in AgentSession to catch STT failures and provide fallback responses:
@session.on("error")
def on_error(ev):
if not ev.error.recoverable:
session.say(
"I'm having trouble connecting right now. Please try again later.",
allow_interruptions=False
)
1. Fallback to VAD-Based Turn Detection: Configure the session to use VAD for detecting when the user stops speaking if STT is unavailable:
session = AgentSession(
turn_detection="vad",
min_endpointing_delay=0.5,
max_endpointing_delay=6.0
)
1. Provide Feedback During Delays: Use interim messages or pre-recorded audio to maintain engagement while handling errors:
await agent.say("One moment while I check...")
These strategies ensure that your system remains resilient and user-friendly even during STT failures. Let me know if you need further assistance or examples!
Sources: tests/fake_session.py | How does end-of-utterance detection work in conversations? | Agents (Python) | livekit/livekit_composite | DeepWiki | examples/bank-ivr | livekit/livekit_composite | DeepWiki | delay-handling/README.mdoc