What’s the best way to update models dynamically i...
# ask-ai
m
What’s the best way to update models dynamically in the middle of a telephony conversation?
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 update models during a telephony conversation! LiveKit offers some great methods to help you make real-time changes smoothly: • Update System Instructions: You can easily change the agent's behavior on the fly using
update_instructions()
. For instance, if you want to switch from a support tone to a sales tone, this method has got you covered. • Update Tools: Need to add or tweak tools?
update_tools()
lets you update the agent’s capabilities right when you need it. • Update Chat Context: Sometimes the conversation needs a fresh context. You can replace or adjust the conversation history with
update_chat_ctx()
so the agent stays relevant and responsive. • Update Model Options: Want to change parameters like voice, temperature, or noise reduction?
update_options()
is the way to go. Just a heads-up, some changes might require restarting the session depending on your provider. These handy updates work seamlessly across popular AI providers like OpenAI, Google Gemini, and Ultravox. If you'd like, I’m here to help with specific implementation details or examples—just let me know! Sources: pipeline-tts/tts_comparison/README.md | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real... | Real-time AI Models & Streaming | livekit/livekit_composite | DeepWiki | Agent Session Management & Turn Detection | livekit/livekit_composite | Dee...
m
I need to change the models themselves. For example a switch from Deepgram to elevenlabs
t
Hi there! If you're looking to switch models dynamically during a telephony conversation, like moving from Deepgram to ElevenLabs, here are some friendly ways to do that: • Agent Transfer: You can create a new agent instance set up with the model you want (such as ElevenLabs) and transfer the session over. This is the go-to method for smoothly switching STT or TTS providers while the conversation is happening. • Dynamic Configuration: For things like language or voice, you can use
update_options()
to tweak settings on the fly without needing to restart the session. • LiveKit Inference: This lets you use unified model identifiers to adjust the session dynamically, making it easier to switch between models. Just a heads-up: directly swapping STT models within the same agent instance during runtime isn’t supported yet, so using agent transfer is your best bet for a seamless experience. If you'd like, I’d be happy to share a code example or help you out further—just let me know! Sources: examples/src/comprehensive_test.ts | docs/index.yaml | Introducing LiveKit Inference: A unified model interface for voice AI
m
Ah okay. What is the procedure for agent transfer?
t
Hi there! I’d love to help you understand how agent transfer works in LiveKit during a telephony conversation. It actually depends on whether you’re doing a cold transfer or a *warm transfer*—let’s walk through both together: Cold Transfer With a cold transfer, the call is handed off directly to another number or SIP destination, and the agent doesn’t stay on the line. You can do this using the
TransferSIPParticipant
API: • First, create a
TransferSIPParticipantRequest
with details like the participant identity, room name, and the destination number (for example,
tel:+123456789
). • If you want, you can set
play_dialtone
to
true
so a dial tone plays during the transfer. • Then, execute the transfer using the LiveKit API client:
await livekit_api.sip.transfer_sip_participant(transfer_request)
. This is often triggered by DTMF input, like pressing "1" to reach a specific department. Warm Transfer Now, a warm transfer is a bit more involved because the agent stays on the line to give a quick summary to another agent or supervisor before connecting them to the caller. Here’s how it usually goes: • Place the caller on hold and play some hold music to keep things smooth. • Dial the supervisor using
create_sip_participant()
and wait for them to answer. • Briefly summarize the conversation to the supervisor so they’re in the loop. • Use the
move_participant()
API to connect the supervisor to the caller’s room. • Once everything’s set, disconnect the original agent to complete the transfer. Keep in mind, warm transfers need two agent sessions and a
SessionManager
to coordinate everything nicely. This approach is great when it’s important to keep context and ensure a smooth handoff. If you’d like, I’m happy to provide code examples or dive deeper into any part of this process—just let me know! Sources: Agent-assisted warm transfer | LiveKit docs | agent.py | sip-refer/agent.py | livekit-agents/livekit/agents/job.py | Agents telephony integration | LiveKit Docs
m
Sorry, I don’t mean to another caller. I mean switching agents.
t
I’m glad you asked about switching agents dynamically during a telephony conversation in LiveKit! Here’s a friendly approach you can try: Using `session.update_agent()`: • First, create a new agent instance with the configuration you want (like a different STT, TTS, or behavior). • Then, simply call
session.update_agent()
to swap out the current agent with your new one. Here’s a little example to guide you:
Copy code
class ShortAgent(Agent):
    def __init__(self):
        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",
            vad=silero.VAD.load()
        )

    @function_tool
    async def change_agent(self):
        """Change the agent to a different configuration."""
        self.session.update_agent(LongAgent())
This way, you can smoothly switch agents without losing the flow of your conversation. If you’d like, I’m here to help with more details or examples—just let me know! Sources: examples/warm-transfer/warm_transfer.py | docs/index.yaml | Agent-assisted warm transfer | LiveKit docs | agent.py