loud-apple-6481
09/21/2025, 5:25 AMtall-airline-16756
09/21/2025, 5:25 AMtall-airline-16756
09/21/2025, 5:26 AMentrypoint function to fetch the prompt from your database (for example, Supabase) and set it in the ChatContext before starting the agent session. Here’s a simple example:
async def entrypoint(ctx: JobContext):
# Fetch system prompt from database
system_prompt = await fetch_prompt_from_supabase(ctx.job.metadata)
initial_ctx = ChatContext()
initial_ctx.add_message(
role="system",
content=system_prompt
)
session = AgentSession()
await session.start(
room=ctx.room,
agent=Assistant(chat_ctx=initial_ctx)
)
• During an Active Session: You can use update_instructions() or modify the ChatContext on the fly to update the system prompt based on user interactions or other triggers.
To keep things running smoothly, it’s a good idea to preload static data using the prewarm function and try to minimize latency by doing your database queries before ctx.connect().
If you’d like, I’m here to help with any part of the implementation or to provide more details—just let me know!
Sources: Tool definition and use | LiveKit Docs | tools/server/public_legacy/system-prompts.js | External data and RAG | LiveKit Docs | rag/README.md | Vision Agent Quickstart | LiveKit Docsloud-apple-6481
09/21/2025, 6:19 AMtall-airline-16756
09/21/2025, 6:19 AMentrypoint function. But don’t worry—you also have the flexibility to update the system prompt dynamically during your session if that’s what you need.
For instance, you can use update_instructions() or tweak the ChatContext to grab new data and refresh the system prompt based on certain triggers or user actions.
If you’re looking to fetch and update the prompt just once at the start, the initialization logic will take care of that smoothly. Feel free to reach out if you’d like a hand customizing this behavior—I’m here to help!loud-apple-6481
09/25/2025, 8:14 AMtall-airline-16756
09/25/2025, 8:15 AMupdate_options() method (which most TTS plugins support) to change parameters such as model, voice, and language while everything is running. Here’s a quick example:
tts.update_options(
model="sonic-2",
voice="new_voice_embedding",
language="es"
)
Another great approach is to listen for LiveKit events like participant_attributes_changed. This way, you can update the TTS settings on the fly based on user preferences or other triggers, giving a really smooth and real-time personalized voice experience.
If you'd like, I’m here to help with more details or specific examples tailored just for your use case—just let me know!
Sources: agent/main.py | livekit-plugins/livekit-plugins-cartesia/livekit/plugins/cartesia/models.pyloud-apple-6481
09/25/2025, 8:16 AMtall-airline-16756
09/25/2025, 8:16 AMupdate_options() method lets you adjust the TTS settings while the session is still active. You can change things like the model, voice, or language on the fly, and these updates will take effect immediately for any upcoming TTS outputs.
If you'd like, I’m here to help you implement this or talk through any particular scenario you have in mind!loud-apple-6481
10/01/2025, 11:30 AMtall-airline-16756
10/01/2025, 11:30 AMloud-apple-6481
10/01/2025, 11:34 AMtall-airline-16756
10/01/2025, 11:34 AMopenai.realtime.RealtimeModel) paired with TTS for audio output. Then, for chat mode, switching to a standard LLM (such as openai.LLM) can help handle text interactions while keeping costs down.
The Agent class is designed to let you switch smoothly between different stt, llm, and tts setups at runtime, making it easy to move between voice and chat modes seamlessly.
If you'd like, I’m here to help you with implementation details or provide specific examples tailored to your needs—just let me know!
Sources: Docs::Agents | examples/src/comprehensive_test.ts | examples/voice_agents/README.mdloud-apple-6481
10/01/2025, 11:36 AMtall-airline-16756
10/01/2025, 11:36 AMloud-apple-6481
10/01/2025, 11:37 AMtall-airline-16756
10/01/2025, 11:38 AMasync def switch_mode(agent_session, mode):
if mode == "voice":
# Configure for voice mode
agent_session.llm = openai.realtime.RealtimeModel(
model="gpt-4o-mini-realtime-preview",
modalities=["text"],
temperature=0.7,
)
agent_session.tts = elevenlabs.TTS(
voice_id="resolved_elevenlabs_voice",
model="eleven_flash_v2_5",
)
elif mode == "chat":
# Configure for chat mode
agent_session.llm = openai.LLM(
model="gpt-4",
temperature=0.7,
)
agent_session.tts = None # Disable TTS for chat mode
1. Dynamic Switching: When your backend receives the mode switch signal, just call the switch_mode function to update the agent’s settings on the fly.
2. Optional Metadata: If it helps, you can also pass metadata like mode details to the LiveKit agent using job metadata or participant attributes, making the switch even smoother.
This way, your LiveKit agent can adapt effortlessly between chat and voice modes based on what your users choose. If you’d like, I’m here to help you with any part of this implementation or answer any questions you might have!loud-apple-6481
10/01/2025, 11:48 AMtall-airline-16756
10/01/2025, 11:48 AMif mode == "voice":
play_audio(response.audio) # Play the audio response
display_text(response.text) # Optionally display the text
elif mode == "chat":
display_text(response.text) # Display the text response
If anything feels unclear or you want a hand with the implementation, please don’t hesitate to ask—I’m here to help!loud-apple-6481
10/01/2025, 12:06 PMtall-airline-16756
10/01/2025, 12:07 PMllm, tts, and other parts of the agent on the fly. If you'd like, I’m here to help with more details or specific examples to get this set up smoothly!loud-apple-6481
10/01/2025, 12:09 PMtall-airline-16756
10/01/2025, 12:09 PMloud-apple-6481
10/01/2025, 12:10 PMtall-airline-16756
10/01/2025, 12:10 PMllm and tts properties in the LiveKit SDK are read-only, which means you can’t directly reconfigure an existing AgentSession to switch from a real-time LLM to a text-only LLM. Instead, you’d need to end the current session and start a new one with the settings you want.
• Frontend Mode State: If the mode (voice or chat) is only tracked on the frontend and not shared with the backend, the backend will keep running the real-time LLM and TTS pipeline. This means costs stay the same even if the user switches to chat mode.
• Chat Messages in Voice Session: When chat messages go through the LiveKit room, they’ll still be handled by the real-time LLM pipeline unless the backend is specifically set up to treat chat mode differently.
• Plumbing for Mode Switching: To support a more cost-effective chat LLM, you’d want to add some logic for switching modes. This might look like:
1. Sending a signal (like a data message or REST call) from the frontend to the backend whenever the mode changes.
2. On the backend, you could either:
• End the current voice session and start a new AgentSession with a text-only LLM and no TTS.
• Or bypass LiveKit for chat mode entirely, routing chat requests to a separate text-only endpoint.
Both options will need some coordinated updates on both frontend and backend to make the mode switch smooth and effective. Please feel free to reach out if you'd like help or more detailed guidance on making these changes — I’m here to support you!loud-apple-6481
10/01/2025, 12:13 PMtall-airline-16756
10/01/2025, 12:13 PMllm and tts properties in the LiveKit SDK are actually read-only. This means you won’t be able to directly switch an existing AgentSession between a real-time LLM and a text-only LLM without ending the current session and starting a new one.
To get the hybrid functionality you’re looking for, the best approach would be to create a process that cleanly ends the current session and initiates a new one with the updated configuration whenever the mode changes. If you'd like, I’d be happy to walk you through the steps to set this up—just let me know!loud-apple-6481
10/01/2025, 12:15 PMtall-airline-16756
10/01/2025, 12:15 PM