if I want to pass parameters from a react app to l...
# ask-ai
g
if I want to pass parameters from a react app to livekit agent (such as username or language for example), what are some ways to do this?
t
Thanks for reaching out, Oliver. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks for reaching out! Could you please share a bit more about how you’re planning to use these parameters (like username, language) in LiveKit? For example, are you thinking of passing them when creating a room, using them as metadata for participants, or maybe for something else? I’m here to help you figure this out!
g
I would want the agent to use them to configure its context for example or used as parameters in tts, stt, llm?
t
I'm happy to help you pass parameters like username or language from your React app to LiveKit for configuring context or using them in TTS, STT, or LLM. Here are some friendly approaches you can try: • LLM Context: You can use the
ChatContext
object to manage your conversation history and pass it along to the agent. Feel free to dynamically update the context with
update_chat_ctx()
or tweak it just before processing using the
before_llm_cb
callback. • TTS Parameters: When setting up, you can configure parameters like voice, language, and model, or update them on the fly using plugin-specific methods such as
update_options()
. • STT Context: For domain-specific context like vocabulary or translation hints, you can pass them through the
context
parameter for plugins like Soniox or Gladia. • Model Settings: The
ModelSettings
class is a great way to pass parameters like tool choices or other configurations you might need. • Runtime Context: You can also access session state and metadata during runtime by using the
RunContext
parameter in your tools. • Text Preprocessing: If you'd like to customize text before sending it to TTS, try the
before_tts_cb
callback or handle structured output with
transcription_node
. If you'd like, I can provide specific examples or dive deeper into any of these methods—just let me know! I'm here to help you every step of the way. Sources: VoicePipelineAgent | LiveKit Docs | livekit-plugins/livekit-plugins-gladia/livekit/plugins/gladia/stt.py | LMNT TTS integration guide | LiveKit Docs | Soniox STT integration guide | LiveKit Docs | Google integration guide | LiveKit Docs
g
what needs to be read agent side though? what documentation should I look at? let me know if there are multiple ways and their differenceas
t
I'd love to help you understand how to read parameters like username, language, and context on the agent side in LiveKit. Here are the main methods and how they differ: • Job Metadata: This is great for passing static user-specific data (like a username) when you create a job using the
metadata
field in
JobContext
. It’s perfect for setting up the agent with user details right at the start of a session. • Context Variables: You can use a dictionary of variables (such as name and language) to dynamically add them into agent instructions. This works well for simple, dynamic setups. • ChatContext: This helps you manage the conversation history and even pre-populate it with initial prompts. It’s the best choice when you want to guide the dialogue flow and keep context during the session. • RunContext.UserData: This lets you attach custom data to the agent’s session for things like game state or user preferences. It’s accessible throughout the session in tool functions, which can be really handy. • STT Parameters: If you want to automatically detect the spoken language from audio input, enabling language detection in STT plugins (like Soniox) is the way to go. Each of these methods has its own strengths depending on what you need. For static info like usernames, Job Metadata is your friend. For dynamic instructions, go with Context Variables. To manage the flow of conversation, ChatContext is ideal. And for session-specific states, RunContext.UserData really shines. If you’d like, I’m happy to share examples or dive deeper into any of these—just let me know! Sources: Docs::Agents | complex-agents/role-playing/agent.py | examples/voice_agents/realtime_joke_teller.py | Soniox STT integration guide | LiveKit Docs