Is there a setup so that my agent speaks first as ...
# ask-ai
a
Is there a setup so that my agent speaks first as soon as they join the room?
t
Thanks for reaching out, Anne. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you want your agent to say something as soon as it joins a LiveKit room, you’ve got a couple of easy ways to do it: 1. Using `session.say()`: This one’s great for having your agent say a set message using Text-to-Speech (TTS). Just call it inside your agent’s
on_enter
method. Here’s a quick example:
Copy code
from livekit.agents import Agent, AgentSession
from livekit.plugins import openai

class GreeterAgent(Agent):
    def __init__(self):
        super().__init__(
            instructions="You are a simple greeter that welcomes users when they join.",
            tts=openai.TTS()
        )
    
    async def on_enter(self):
        self.session.say("Hi there! Welcome to the room.")

async def entrypoint(ctx):
    session = AgentSession()
    await session.start(
        agent=GreeterAgent(),
        room=ctx.room
    )
1. Using `agent.generate_reply()`: If you’re working with realtime models and want your agent to start talking dynamically, this method is your friend. Check it out:
Copy code
from livekit.agents import MultimodalAgent
from livekit.plugins import openai

async def entrypoint(ctx):
    agent = MultimodalAgent(model=openai.realtime.RealtimeModel(...))
    agent.start(ctx.room)
    agent.generate_reply()
Just a quick tip: make sure you have a TTS plugin set up if you’re using
session.say()
. And if you’re going realtime with
generate_reply()
, it’ll help your agent respond smoothly and naturally.