wooden-megabyte-91316
07/30/2025, 3:20 PMtall-airline-16756
07/30/2025, 3:24 PMtall-airline-16756
07/30/2025, 3:25 PMsession.say()
This method allows the agent to speak a predefined message. For example:
agent.start(ctx.room)
await agent.say("Hey, how can I help you today?", allow_interruptions=True)
This triggers the configured Text-to-Speech (TTS) to synthesize and play the message to the user. You can also provide pre-synthesized audio to skip the TTS step.
2. Using session.generate_reply()
This method allows the agent to generate dynamic responses. You can implement this in the on_enter() method of your Agent class:
class IntroAgent(Agent):
async def on_enter(self):
self.session.generate_reply(instructions="Say hello to the user")
Alternatively, you can initiate the conversation at the session level:
await session.generate_reply(
instructions="Greet the user and offer your assistance."
)
3. For Realtime Models
If you are using a realtime model, you can use the following JavaScript/TypeScript example:
session.conversation.item.create(
llm.ChatMessage.create({
role: llm.ChatRole.ASSISTANT,
text: "Hello, I’m calling to ask you a question about ice cream. Do you prefer chocolate or vanilla?",
}),
);
session.response.create();
Choose the method that best fits your use case. The session.say() method is ideal for fixed messages, while generate_reply() is better for dynamic, context-aware responses.
Sources: Agent speech and audio | LiveKit Docs | delay-handling/agent.py | tests/test_agent_session.py | Voice AI quickstart | LiveKit Docs | packages/sip--make-a-call/src/agent.ts