aloof-scooter-47164
11/14/2025, 4:23 AMtall-airline-16756
11/14/2025, 4:23 AMtall-airline-16756
11/14/2025, 4:24 AMasync 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:
await session.generate_reply(
instructions="Greet the user and offer your assistance."
)
Node.js Example:
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:
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 docsaloof-scooter-47164
11/14/2025, 4:26 AMtall-airline-16756
11/14/2025, 4:26 AMsession.say() to Initiate Speech
This method lets the agent speak a predefined message no matter if it’s listening or not:
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:
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:
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:
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.pyaloof-scooter-47164
11/14/2025, 4:27 AMtall-airline-16756
11/14/2025, 4:28 AMsession.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:
await session.generate_reply(
instructions="Greet the user and offer your assistance."
)
And if you’re working with TypeScript, it looks like this:
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:
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:
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:
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.tsaloof-scooter-47164
11/14/2025, 4:32 AMtall-airline-16756
11/14/2025, 4:32 AMctx.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:
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 docsaloof-scooter-47164
11/14/2025, 4:34 AMtall-airline-16756
11/14/2025, 4:35 AMgenerate_reply() for Dynamic Speech
This method gently prompts the agent to create a response based on your instructions:
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:
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:
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:
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.pyaloof-scooter-47164
11/30/2025, 5:27 PMtall-airline-16756
11/30/2025, 5:28 PMYou 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:
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:
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.mdaloof-scooter-47164
11/30/2025, 5:47 PMtall-airline-16756
11/30/2025, 5:47 PMAgentSession 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:
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:
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:
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.pyaloof-scooter-47164
11/30/2025, 7:26 PMtall-airline-16756
11/30/2025, 7:26 PMupdate_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:
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.pyaloof-scooter-47164
11/30/2025, 7:30 PMtall-airline-16756
11/30/2025, 7:31 PMupdate_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
# 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
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 docsaloof-scooter-47164
11/30/2025, 7:34 PMtall-airline-16756
11/30/2025, 7:35 PMinstructions 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:
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 docsaloof-scooter-47164
11/30/2025, 7:41 PMtall-airline-16756
11/30/2025, 7:41 PMupdate_options method. This allows you to modify parameters like language, model, punctuation, or prompts during a session.
For example:
# 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