how can i make from the client to have the LiveKit...
# ask-ai
a
how can i make from the client to have the LiveKit agent start talking when working with OpenAI Realtime?
t
Thanks for reaching out, Sebastián. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To help your LiveKit agent start talking when using OpenAI Realtime from the client, you’ll want to programmatically trigger the agent’s first speech right after initializing and starting the session. Here’s a simple way to do that: Python Example:
Copy code
async def entrypoint(ctx: agents.JobContext):
    session = AgentSession(
        llm=openai.realtime.RealtimeModel(),
        vad=silero.VAD.load()
    )

    await session.start(
        room=ctx.room,
        agent=Assistant()
    )

    # Trigger the agent to speak first
    await session.generate_reply()
If you’d like, you can also give the agent some specific instructions for its initial message:
Copy code
await session.generate_reply(
    instructions="Greet the user and offer your assistance."
)
Node.js Example:
Copy code
await session.start({
  agent,
  room: ctx.room,
});

session.generateReply({
  instructions: 'Greet the user briefly and confirm you are ready.',
});
Another option is to use
session.say()
if you want to directly specify exactly what the agent should say:
Copy code
session.say('Hello, how can I help you today?');
Just a quick reminder to make sure your OpenAI Realtime API is properly set up in the session, and if you’re using LiveKit’s own turn detection model, be sure to disable
turnDetection
. If you have any questions or need a hand with anything else, feel free to ask—I’m here to help! Sources: realtime/openai-realtime-drive-thru.py | Voice AI quickstart | LiveKit docs | agents/src/voice/agent_activity.ts | agent.py | OpenAI and LiveKit | LiveKit docs
a
not necessarily is as soon as the agent joins. could be an agent already present in the room but that is muted
t
If the LiveKit agent is already present in the room but muted, don’t worry—you can still make it start talking. Here’s a simple guide to help you through it: 1. Use
session.say()
to Initiate Speech
This method lets the agent speak a predefined message no matter if it’s listening or not:
Copy code
await session.say("Hello. How can I help you today?", allow_interruptions=False)
Just make sure you have a TTS plugin configured or that the Realtime model supports audio output. 2. Use
agent.generate_reply()
to Start the Conversation
If you want the agent to respond based on the context, simply use:
Copy code
agent.generate_reply()
This works even if the agent isn’t actively listening. 3. Ensure Output Audio Is Enabled It’s important to check that the agent’s output audio is turned on:
Copy code
session.output.set_audio_enabled(True)
If the output is off, the agent won’t be able to speak no matter what commands you give. 4. Optional: Control Input Audio State If the agent was muted (input disabled) but you want it to listen again, you can re-enable input with:
Copy code
session.input.set_audio_enabled(True)
Just keep in mind that muting the input doesn’t stop the agent from speaking. If anything’s unclear or you’d like a hand with this, please don’t hesitate to ask—I’m here to help! Sources: Agent speech and audio | LiveKit docs | agent.py | livekit-agents/livekit/agents/voice/agent_activity.py
a
but how can you notify the agent to start talking and give it the instructions
t
To get your LiveKit agent started with talking and providing instructions, here’s a simple guide to help you along: 1. Use
session.generate_reply()
for Dynamic Speech
This is a great way to have your agent generate and speak a response based on the instructions you give:
Copy code
await session.generate_reply(
    instructions="Greet the user and offer your assistance."
)
And if you’re working with TypeScript, it looks like this:
Copy code
session.generateReply({
  instructions: 'Greet the user briefly and confirm you are ready.',
});
2. Use
session.say()
for Predefined Messages
If you want your agent to say a specific message, this method is perfect:
Copy code
session.say('Hello, how can I help you today?');
Just a quick note: this requires a TTS plugin unless you’re using the OpenAI Realtime model which can handle audio synthesis directly. 3. Set Agent-Wide Instructions To make sure your agent behaves consistently, you can set default instructions when you initialize it:
Copy code
agent = Agent(instructions="You are a helpful voice AI assistant.")
These instructions help guide the agent’s responses unless you specify otherwise with
generate_reply()
. 4. Ensure Room Connection Before your agent starts speaking, double-check that it’s connected to the LiveKit room:
Copy code
await ctx.connect()
await session.start(room=ctx.room, agent=agent)
await session.generate_reply(instructions="Hello, I'm ready to assist.")
If any part of this feels unclear or if you want to dive deeper into any step, just let me know—I’m here to help! Sources: livekit-agents/README.md | Agent speech and audio | LiveKit docs | agent.py | examples/src/push_to_talk.ts
a
but you're in the client
t
Hi there! To help you notify a LiveKit agent to start talking and provide instructions from the client side, you can use Remote Procedure Calls (RPC) or programmatically trigger the agent's speech. Let me walk you through it: 1. Use RPC to Trigger Agent Actions First, you’ll want to register an RPC method in the agent code so the client can notify the agent easily:
Copy code
ctx.room.local_participant.register_rpc_method('start_turn', async () => {
  session.interrupt();
  session.clear_user_turn();
  return 'ok';
});
Then, the client can call this RPC method whenever it’s time to start the agent’s behavior. 2. Trigger Speech Programmatically Once your agent is up and running, you can prompt it to speak by using: • `agent.generate_reply()`: This generates a response based on the context or instructions you provide. • `agent.say("message")`: This makes the agent speak a specific message right away. Here’s a quick example:
Copy code
await session.generate_reply(
    instructions="Greet the user and offer your assistance."
)
3. Client-Side Setup Just a heads-up: the client needs to be connected to the room and have permission to invoke RPC methods. You can trigger the RPC method with something simple, like a button click or any other UI event. If you’d like, I’m here to help with more details or specific examples tailored to your client-side setup. Just let me know! Sources: examples/voice_agents/push_to_talk.py | agent.py | delay-handling/agent.py | Agent speech and audio | LiveKit docs | Agents v0.x migration guide - Python | LiveKit docs
a
and from the server side?
t
I'm glad you're reaching out! To notify a LiveKit agent to start talking and provide instructions from the server side, here are some helpful methods you can use: 1. Use
generate_reply()
for Dynamic Speech
This method gently prompts the agent to create a response based on your instructions:
Copy code
await session.generate_reply(
    instructions="Greet the user and ask where they are from"
)
You can call this during the agent’s lifecycle event (like
on_enter
) so the agent speaks right when joining the room:
Copy code
async def on_enter(self):
    self.session.generate_reply()
2. Use
say()
for Predefined Messages
If you'd prefer the agent to say a specific message, this is the way to go:
Copy code
await agent.say("Hey, how can I help you today?", allow_interruptions=True)
This is perfect for fixed, predefined speech you want the agent to deliver. 3. Server-Side Integration Workflow Here’s a friendly example of how you might integrate these methods in your server-side entrypoint:
Copy code
async def entrypoint(ctx: JobContext):
    session = AgentSession()
    await session.start(agent=MyAgent(), room=ctx.room)

    # Optionally have the agent speak immediately
    await session.generate_reply(instructions="Welcome the user warmly.")
Key Considerations: •
generate_reply()
doesn’t save instructions in chat history, making it great for dynamic, on-the-fly behavior. • Remember, you can use
session.interrupt()
and
session.commit_user_turn()
to manage turn detection smoothly. • For telephony, it’s best to start speech automatically only on inbound calls; for outbound calls, wait for the user to say something first. Please feel free to ask if you'd like me to clarify anything or share more examples—I’m here to help! Sources: Agents v0.x migration guide - Python | LiveKit docs | Node.js Agents Architecture | livekit/livekit_composite | DeepWiki | examples/voice_agents/email_example.py | Agent speech and audio | LiveKit docs | basics/change_agent_instructions.py
a
the speech is not following the instructiosn as it is, actually is saying different things if i repeat it multiple times
t
The variability in the agent's speech when repeating instructions can occur due to several factors. Here are strategies to improve consistency: 1. Use Structured and Detailed Prompts Define clear agent identity, behavioral rules, and output formatting in the instructions. For example:
Copy code
You are Pixel, a friendly, reliable voice travel agent. Always greet users with "Hello!" and ask how you can assist them.
Explicit rules and examples reduce ambiguity. 2. Pass Consistent Instructions to
generate_reply()
Ensure the
instructions
parameter in
generate_reply()
is precise and consistent across calls:
Copy code
await session.generate_reply(
    instructions="Greet the user and ask where they are from."
)
Dynamic or varying instructions can lead to different outputs. 3. Disable Preemptive Generation If enabled, preemptive generation can cause speculative responses. Disable it for more consistent outputs:
Copy code
session = AgentSession(preemptive_generation=False)
4. Manage Turn-Taking Set
allow_interruptions=False
and configure turn detection settings to prevent disruptions during speech generation. 5. Test and Refine Prompts Use verbose evaluation output (
LIVEKIT_EVALS_VERBOSE=1
) to diagnose inconsistencies and refine prompts iteratively. Focus on improving the prompt rather than adjusting tests. Let me know if you need help applying these strategies or further clarification! Sources: Prompting guide | LiveKit docs | src/agent.ts | livekit-agents/livekit/agents/voice/agent_session.py | Agent speech and audio | LiveKit docs | complex-agents/doheny-surf-desk/tests/AGENTS.md
a
what's the best way to use another model to generate this responses?
t
To use a different model to generate responses for a LiveKit agent, you can configure the LLM during the
AgentSession
initialization. Here are the options: 1. Use LiveKit Inference LiveKit Inference provides access to curated LLMs without requiring additional plugins. Specify the model in the
llm
parameter:
Copy code
session = AgentSession(
    stt="deepgram/nova-3",
    llm="openai/gpt-4.1-mini",  # Replace with your desired model
    tts="cartesia/sonic-2:9626c31c-bec5-4cca-baa8-f8ba9e84c8bc"
)
You can replace
"openai/gpt-4.1-mini"
with other supported models like
"google/gemini-2.5-flash"
. 2. Use Plugins with Custom Providers Connect directly to model providers using plugins. For example, to use OpenAI's GPT-4o-mini:
Copy code
from livekit.plugins import openai

session = AgentSession(
    llm=openai.LLM(model="gpt-4o-mini"),
    stt=deepgram.STT(model="nova-3", language="multi"),
    tts=openai.TTS(model="tts-1", voice="alloy")
)
Install the relevant plugin (e.g.,
livekit-agents[openai]
) and set up the API key (e.g.,
OPENAI_API_KEY
). 3. Use Custom or External Models Integrate external models with OpenAI-compatible endpoints:
Copy code
llm=openai.LLM(
    model="your-custom-model",
    api_key="your-api-key",
    base_url="http://localhost:8080/v1"  # Custom server URL
)
This allows you to use locally hosted or private models while leveraging LiveKit's framework. Let me know if you need further assistance with setup or configuration! Sources: Large language models (LLM) | LiveKit Docs | Introducing LiveKit Inference: A unified model interface for voice AI | Announcing Agent Builder: A Pathway to Code | livekit-agents/livekit/agents/voice/agent.py
a
can i update the TTS instructions after declaring it? similarly to how we can update the realtime session instructions
t
Yes, TTS instructions can be updated after declaration in LiveKit, similar to updating realtime session instructions. Many TTS plugins, such as OpenAI and Hume, support dynamic updates using the
update_options
method. For example, you can modify the TTS settings like voice, description (TTS instructions), or speed during an ongoing session. These changes will take effect on the next utterance:
Copy code
tts.update_options(description="Speak in a calm and friendly tone.")
This is particularly useful when dynamically applying TTS instructions extracted from the LLM’s structured output. For instance, you can adjust the emotional tone or intonation guidance based on the context. Let me know if you need further details or examples for your specific use case! Sources: Hume TTS plugin guide | LiveKit Docs | Tool definition and use | LiveKit docs | livekit-agents/livekit/agents/voice/agent_activity.py
a
but how to do so? because for the realtime, i call update_instructions on the main agent
t
To dynamically update TTS instructions in LiveKit, you can use the
update_options()
method on the TTS instance. This allows you to modify parameters like voice, tone, speed, and description during a session. Here’s how: Example: Updating TTS Instructions
Copy code
# Update TTS settings dynamically
self.tts.update_options(
    voice="new_voice_name",
    speed=1.2,
    description="Speak with urgency and emphasis"
)
await self.session.say("Updated voice message")
Example: Dynamic Voice Switching
Copy code
async def say_phrase_in_voice(self, phrase, voice="Hades"):
    self.tts.update_options(voice=voice)
    await self.session.say(phrase)
    self.tts.update_options(voice="Ashley")  # Restore original voice
Provider-Specific Parameters • Hume TTS:
description
,
speed
,
voice
• Google TTS:
language
,
gender
,
speaking_rate
• Neuphonic TTS:
lang_code
,
voice_id
,
speed
Call
update_options()
before generating speech to ensure the new settings are applied. Let me know if you need further clarification or examples! Sources: livekit-agents/livekit/agents/inference/tts.py | Building an Automated IVR Menu Caller | LiveKit docs | basics/say_in_voice.py | Tool definition and use | LiveKit docs
a
but instructions doesnt seem to be a parameter
t
The availability of the
instructions
parameter for TTS updates depends on the specific TTS plugin being used. Here’s a breakdown: Plugins Supporting
instructions
• OpenAI TTS: Supports
instructions
for tone, style, and other characteristics. Example:
Copy code
tts.update_options(instructions="Adopt a formal and professional tone.")
• Gemini TTS: Uses
instructions
to guide tone and style, but dynamic updates via
update_options
may not be supported. • Azure OpenAI TTS: Similar to OpenAI, supports
instructions
for expressive speech generation. Plugins Without
instructions
• Google Cloud TTS: Uses parameters like
pitch
and
speaking_rate
instead. • Hume AI TTS: Uses
description
, which functions similarly to
instructions
. • NeuPhonic and Minimax: Use voice-specific parameters like
emotion
and
speed
. If you’re using a plugin that doesn’t support
instructions
, you may need to rely on alternative parameters like
description
or voice-specific settings. Let me know which plugin you’re using, and I can provide more specific guidance! Sources: OpenAI TTS plugin guide | LiveKit docs | Gemini TTS plugin guide | LiveKit Docs | livekit-plugins/livekit-plugins-minimax/livekit/plugins/minimax/tts.py | Azure OpenAI TTS plugin guide | LiveKit Docs | Tool definition and use | LiveKit docs
a
and can instructions be updated on the fly for the STT even with a Realtime session?
t
STT (Speech-to-Text) instructions cannot be updated dynamically during a Realtime session in LiveKit. However, you can update STT configuration options on the fly using the
update_options
method. This allows you to modify parameters like language, model, punctuation, or prompts during a session. For example:
Copy code
# Update STT options dynamically
self.stt.update_options(language="en", punctuate=True)
Unlike LLMs, which support dynamic instruction updates via
update_instructions
, STT models are not driven by modifiable system prompts. Instead, their behavior is controlled by configuration settings. Let me know if you need further clarification or examples for your specific use case! Sources: Gladia STT plugin guide | LiveKit Docs | pipeline-tts/changing_language/README.md | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real... | plugins/google/src/beta/realtime/realtime_api.ts