How would I dynamically change the model that I am...
# ask-ai
m
How would I dynamically change the model that I am using at runtime lets say if I realize I need to switch langauges and want to switch from OAI transcription to Deepgram or something?
t
Thanks for reaching out, Alexander. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you're exploring how to dynamically change transcription models at runtime in LiveKit! There are a couple of ways to approach this, depending on what fits your needs best: • Switching Models Within the Same Provider: If you're working with a provider like Deepgram, you can easily update the model during an active session using the
update_options()
method. For instance, switching to a medical model is as simple as
stt.update_options(model="nova-3-medical")
. • Switching Between Different Providers: When you want to switch from one provider (like OpenAI) to another (such as Deepgram), a great way to handle this is by using an agent transfer pattern. This means setting up multiple agent classes, each tailored to a specific STT provider, and then transferring the session to the agent that fits your current needs. If you'd like, I’d be happy to share a code example that demonstrates how to implement the agent transfer pattern for switching STT providers. Just let me know! Sources: livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/stt.py | Deepgram STT | LiveKit Docs | Speech-to-text (STT) models | LiveKit Docs | basics/say_in_voice.py
m
Please teach me how to hand off between different classes
t
I'm happy to guide you through implementing handoff between different classes for switching STT providers in LiveKit. Here’s a simple way to approach it: 1. Define Agent Classes: Start by creating separate agent classes for each STT provider you want to use. For instance, one class could handle Deepgram, and another could manage AssemblyAI. Each class should be set up to initialize with its respective STT provider. 2. Trigger Handoff: In your current agent, you can use a function tool to initiate the handoff. This function should return an instance of the new agent. Here’s a quick example in Python:
Copy code
@function_tool
async def switch_to_deepgram(self):
    return DeepgramAgent()  # Handoff triggered
1. Confirm Transition: To make sure the user knows about the switch, use the
on_enter()
method in the new agent to send a confirmation message. Like this:
Copy code
async def on_enter(self):
    await self.session.say("Now using Deepgram for voice recognition.")
1. Preserve Context: It’s important to keep user preferences or chat history intact. You can do this by using a shared
UserData
object that’s passed along with the session, ensuring a smooth experience across agents. If you’d like, I can provide a complete code example tailored to your preferred programming language, such as Python or Node.js. Just let me know! Sources: Tool definition and use | LiveKit Docs | examples/src/basic_tool_call_agent.ts | complex-agents/role-playing/README.md | Introducing LiveKit Inference: A unified model interface for voice AI | livekit-agents/livekit/agents/inference/stt.py