How to make agent speak first as soon as user conn...
# ask-ai
f
How to make agent speak first as soon as user connected?
t
Thanks for reaching out, Taras. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks for reaching out! Just to make sure I understand you correctly, when you say "agent," are you talking about a bot, a human participant, or maybe a particular feature in LiveKit? Also, are you hoping to have the agent automatically play audio or send a message right when the user connects? I’m here to help you figure this out!
f
LiveKit Agent within Agent Session
t
I'd love to help you get your LiveKit Agent to speak first as soon as a user connects within an Agent Session! Here are a couple of friendly ways to do that: 1. Using
session.say()
This is a great option if you want your agent to say a specific message right when the session starts. It uses the Text-to-Speech (TTS) engine to speak directly to the user.
Copy code
await session.say("Hello! How can I assist you today?")
Just a quick note: You'll need to have a TTS plugin set up in your session for this to work smoothly. 2. Using
generate_reply()
If you're working with an LLM-based pipeline,
generate_reply()
is a wonderful way to have your agent start the conversation with a response that's tailored dynamically based on the context or instructions you provide.
Copy code
await session.generate_reply(instructions="Greet the user and offer your assistance.")
This method is especially handy for creating dynamic responses, and if you're using a realtime model, you won’t need a TTS plugin. Some best practices to keep in mind: • For realtime models,
generate_reply()
is usually the way to go unless you add a TTS plugin. • If you're working with telephony, it’s helpful to use guards (like checking if
phone_number
exists) so your agent only speaks first during inbound calls. • You might also want to place your
generate_reply()
or
say()
calls inside the
on_enter()
lifecycle hook of your agent, so it happens automatically when the agent joins. Please feel free to reach out if you'd like me to walk you through any part of this or if you have other questions. I’m here to help! Sources: Docs::Agents | examples/warm-transfer/warm_transfer.py | Agent speech and audio | LiveKit Docs | Agent speech and audio | LiveKit Docs | Docs::Agents