i having problem with current model providers can ...
# ask-ai
c
i having problem with current model providers can i modify provider with other provider using node pipeline
t
Thanks for reaching out, ARPAN. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Great question! You can definitely modify or switch the provider dynamically in a LiveKit node pipeline, and there are three main ways to do this: • Agent Transfer: This involves creating separate agent instances for each provider and then using function tools to switch between them as needed. It’s quite flexible! • Override tts_node: Here, you can add some conditional logic inside the
tts_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 Docs
c
can you provide a example that i can change model that not in livekit
t
I'm glad you're exploring ways to use models outside of LiveKit! You can definitely integrate them by overriding the relevant pipeline node (like
stt_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 AI
c
you want to switch between models on the fly, you can add conditional logic or use agent transfer patterns to make that happen smoothly. in python example
t
Here is a Python example demonstrating how to switch between models dynamically using agent transfer in LiveKit:
Copy code
from 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 Docs
c
my problm is auto language swithch using node pipline detact language and change models other providers
t
To help you implement automatic language detection and model switching in LiveKit using a node pipeline, here’s a friendly step-by-step guide: 1. Enable Automatic Language Detection: Start by configuring your STT provider (like Deepgram) with the
detectLanguage
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:
Copy code
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 agents
c
let suppose stt stop working some aoi issue or connection issue this case what can we as exception so if stt fails it will give llm that currently un avalble
t
To handle STT failures and provide fallback responses to the LLM, you can implement the following strategies: 1. Use a Fallback Adapter: Configure multiple STT providers to ensure automatic failover if one fails. For example:
Copy code
from 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:
Copy code
@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:
Copy code
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:
Copy code
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