i'm using the livekit agent now i need to give dif...
# ask-ai
s
i'm using the livekit agent now i need to give different system prompt while starting the room, now how can i do it
t
Thanks for reaching out, Venkateshwara. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to help you set a different system prompt when starting a room in LiveKit! You can achieve this by using the LiveKit Agents framework. Here's a simple way to do it: • Using the LiveKit Agents Framework: You can configure the
ChatContext
with a system message before initializing the agent. For example:
Copy code
initial_ctx = llm.ChatContext().append(
    role="system",
    text="You are a voice assistant created by LiveKit that can both see and hear. Use short and concise responses. Incorporate visual descriptions naturally."
)
This approach lets you shape the AI's behavior, personality, or capabilities exactly how you want them. If you have any questions or a particular scenario in mind, please feel free to share—I’m here to help! Sources: Vision Agent Quickstart | LiveKit Docs | livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti... | models/templates/llama-cpp-deepseek-r1.jinja | web/providers/GameProvider.tsx
s
no i need this while creating a room and adding participant
t
Hi there! Just to clarify, system prompts in LiveKit are connected to AI agents rather than being set directly during room or participant creation. To set a system prompt, you'll want to configure it within the
ChatContext
of an AI agent, like a
VoicePipelineAgent
, before you start the agent in the room. Here’s a friendly example in Python to guide you:
Copy code
initial_ctx = llm.ChatContext().append(
    role="system",
    text="You are a voice assistant created by LiveKit. Keep responses short and concise."
)

agent = VoicePipelineAgent(
    vad=silero.VAD.load(),
    stt=deepgram.STT(),
    llm=openai.LLM(),
    tts=openai.TTS(),
    chat_ctx=initial_ctx  # System prompt is set here
)

agent.start(ctx.room, participant)
Just a heads up, room creation and adding participants don’t include settings for system prompts. If anything’s unclear or you’d like a hand with this, please don’t hesitate to ask—I’m here to help! Sources: VoicePipelineAgent | LiveKit Docs | Recording agent sessions | LiveKit Docs | Vision Agent Quickstart | LiveKit Docs | packages/livekit-server-sdk/src/RoomServiceClient.ts
s
is it possible to set this system prompt and choose the voice dynamically while connecting to agent?
t
Absolutely, you can set both the system prompt and the voice dynamically when connecting to an agent in LiveKit. This is something you can easily handle programmatically during the initialization of the agent or session. For instance, you might pass the system prompt and voice settings as parameters when creating the agent, like this:
Copy code
initial_ctx = llm.ChatContext().append(
    role="system",
    text="You are a helpful assistant."
)

agent = VoicePipelineAgent(
    vad=silero.VAD.load(),
    stt=deepgram.STT(),
    llm=openai.LLM(),
    tts=openai.TTS(voice="en-US-Wavenet-D"),  # Set voice dynamically
    chat_ctx=initial_ctx  # Set system prompt dynamically
)

agent.start(ctx.room, participant)
This way, you have the flexibility to adjust the system prompt and voice based on runtime needs, user preferences, or any other logic your application requires. If you'd like, I’m here to provide more details or walk you through additional examples! Sources: livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti... | docs/index.yaml | agent/main.py
s
actully is it possible while creating a room
t
I totally understand where you're coming from! System prompts and voice settings aren't set directly during room creation because they're not actually properties of the room itself. But don't worry—they can be easily configured when you initialize an agent that works within the room. For instance, you can pass the system prompt and voice settings as parameters while creating the agent, like this:
Copy code
model = openai.realtime.RealtimeModel(
    api_key=config.openai_api_key,
    instructions="You are a helpful assistant.",  # System prompt
    voice="en-US-Wavenet-D",                   # Voice selection
    temperature=0.7,
    max_response_output_tokens=100,
    modalities=["text", "audio"],
    turn_detection=True,
)
These configurations take effect when the agent connects to the room. If you have any questions or want me to walk you through it, just let me know—I'm here to help! Sources: agent/main.py | examples/voice_agents/dynamic_tool_creation.py
s
then how to start multiple instance with single agent
t
Thanks for reaching out! Could you please help me understand a bit more about what you mean by starting multiple instances with a single agent? Are you hoping for one agent to manage multiple rooms, or are you looking to have the agent’s functionality duplicated across different sessions? The more details you can share, the better I can support you.
s
actually i'm hosting one in the railway there only 1 is running and i can connect to that and create many rooms right. now i need the agent to speak different voice with different system prompt how can i do it?
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!
s
ok actually that's not possible. now i just register a livekit agent with different voice and language, how can i connect it using websocket