How to support multiple languages in a single agent pipeline

This question originally came up in our Slack community and the thread has been consolidated here for long-term reference.

My use case is a telephony agent that needs to support both Spanish and English.

So far, I’ve had to create two different agents with two different prompts and two different pipelines (different STT and TTS language models). Is there a more efficient way than code duplication?

You can support multiple languages from a single agent by passing the language as a parameter:

session = AgentSession(
    tts=cartesia.TTS(language=language, voice=voice, api_key="cartesian_api_key"),
    llm=openai.realtime.RealtimeModel(modalities=["text"]),
    vad=silero.VAD.load()
)

Your client can send the required language parameter when connecting, and the agent will use the appropriate language settings.