enough-dentist-75383
12/04/2025, 7:12 AMtall-airline-16756
12/04/2025, 7:12 AMtall-airline-16756
12/04/2025, 7:13 AM# switch to GPT-4.1
session.update_llm("openai/gpt-4.1-mini")
# later switch to Gemini 2.5 Flash
session.update_llm("google/gemini-2.5-flash")
• Node.js:
session.updateLlm("openai/gpt-4.1-mini");
session.updateLlm("google/gemini-2.5-flash");
This lets you optimize for cost, latency, or capability within the same conversation. Would you like a code sample showing how to handle state or context when switching models?
Sources: Models | LiveKit Docs | OpenAI LLM models | LiveKit Docs | Google Gemini LLM | LiveKit Docsenough-dentist-75383
12/04/2025, 7:13 AMtall-airline-16756
12/04/2025, 7:14 AMenough-dentist-75383
12/04/2025, 7:14 AMtall-airline-16756
12/04/2025, 7:14 AMupdate_llm(), and preserve conversation context (history) across model changes.
# Example assumes LiveKit Python SDK with AgentSession-like API is available.
# Pseudocode may need minor adjustments to match your SDK import paths.
from livekit_inference import LiveKitClient, AgentSession
# 1) Create client and session (replace with your auth/config)
client = LiveKitClient(api_key="YOUR_API_KEY", url="https://your-livekit-endpoint")
session = client.create_agent_session(name="assistant-session")
# 2) Start with a default model (GPT-4.1)
session.update_llm("openai/gpt-4.1-mini")
# 3) Function to send a user message and get assistant response
def send_user_message(text):
# Append user message to session conversation/history
session.append_user_message(text)
# Run the agent to get a response (sync or async depending on SDK)
response = session.run() # returns assistant message object/str
# Append assistant reply to history
session.append_assistant_message(response.text if hasattr(response, "text") else str(response))
return response
# 4) Preserve context when switching models:
# The session stores conversation history internally. When you call update_llm(),
# history remains available so new model continues the same conversation.
def switch_model(llm_name):
session.update_llm(llm_name)
# Optionally adjust system prompt or model-specific params
# session.update_system_prompt("You are now using Gemini 2.5 Flash...")
# 5) Usage example
resp1 = send_user_message("Hello — can you summarize the meeting notes?")
print("Assistant (GPT-4.1):", resp1)
# Switch to Gemini 2.5 Flash mid-session
switch_model("google/gemini-2.5-flash")
resp2 = send_user_message("Now expand that summary with action items.")
print("Assistant (Gemini 2.5):", resp2)
Notes:
• Keep conversation history (user + assistant + system messages) inside the same `AgentSession`; calling update_llm() preserves that history so the new model has context.
• You can also update system prompts or model params after switching to tune behavior.
• Handle any model-specific token/response limits in your application (truncate older history if needed).
Would you like a version that shows async usage, explicit history truncation, or a complete session-creation snippet with auth details?