wooden-beard-26644
07/24/2025, 3:29 PMtall-airline-16756
07/24/2025, 3:29 PMtall-airline-16756
07/24/2025, 3:30 PMawait agent.say("Hi there, how are you doing today?", allow_interruptions=True)
• Using `session.generate_reply()`: This method enables the agent to generate and speak a response based on specific instructions. For example: await session.generate_reply(instructions="say hello to the user")
Implementation Examples:
1. *In the Agent Class (on_enter method):*`class MyAgent(Agent):
async def on_enter(self):
self.session.generate_reply(instructions="say hello to the user")`
2. *After the Agent Starts:*`agent.start(ctx.room)
await agent.say("Hi there, how are you doing today?", allow_interruptions=True)`
3. For Telephony (Inbound Calls): If it’s an inbound call, you can ensure the agent speaks first: if phone_number is None:
await session.generate_reply(
instructions="Greet the user and offer your assistance."
)
Key Notes:
• By default, the agent waits for user input before responding.
• To initiate a conversation, use the above methods to greet users at session start.
• If using session.say(), ensure a TTS plugin is added to your session. Alternatively, use session.generate_reply() for a more flexible approach.
These methods will allow the agent to proactively greet users as soon as the call begins.
Sources: Agent speech and audio | LiveKit Docs | examples/voice_agents/preemptive_generation.py | Agents telephony integration | LiveKit Docswooden-beard-26644
07/24/2025, 3:32 PMtall-airline-16756
07/24/2025, 3:33 PMgenerate_reply() get added to the original instructions, kind of like mixing two ingredients together. Here's how it looks behind the scenes: if instructions:
instructions = "\n".join([self._agent.instructions, instructions])
• For RealtimeModel: In this case, the new instructions go straight to the reply task without mixing with the original instructions.
Some Cool Things to Know:
• When you use generate_reply(), the instructions help create a response that gets added to the chat history. But don't worry - the instructions themselves don't stick around in the history.
• This means the agent keeps its core personality while still being super flexible for different conversations.
Wanna see a quick example? Check this out:
await self.session.generate_reply(
instructions=f"Greet {userdata.user_name} and tell them a joke about being {userdata.age} years old."
)
Pretty neat, right? This approach lets the agent be both consistent and adaptable - just like a good friend! 😊 Sources: Workflows | LiveKit Docs | examples/voice_agents/mcp/mcp-agent.py | Agent speech | LiveKit Docs