acceptable-dream-85180
08/13/2025, 5:57 PMtall-airline-16756
08/13/2025, 5:58 PMtall-airline-16756
08/13/2025, 5:58 PMon_enter
method. Here’s a quick example:
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:
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.