modern-winter-66316
12/04/2025, 7:45 PMtall-airline-16756
12/04/2025, 7:45 PMtall-airline-16756
12/04/2025, 7:45 PMmodern-winter-66316
12/04/2025, 7:47 PMtall-airline-16756
12/04/2025, 7:47 PMsession.generate_reply() (LLM-generated greeting) or session.say() (fixed greeting).
What to implement
1) Start Lesson button (frontend → agent)
• When the button is clicked, send an RPC from the frontend to the room/agent.
• In the agent, listen for that RPC and call session.generate_reply() or session.say() with your greeting.
Example flow:
1. Frontend: send RPC
room.localParticipant.sendRpc('start_lesson', '', (response) => {
console.log(response);
});
1. Agent: on RPC received, trigger speech
@ctx.room.local_participant.on('rpc_received')
async def on_rpc(method, payload, response_channel):
if method == 'start_lesson':
await session.generate_reply(instructions="Give a warm opening greeting to start the lesson.")
response_channel.send("Agent greeted user")
2) Incoming calls to a LiveKit phone number
• Configure your LiveKit phone number to dispatch to your agent.
• In the agent code, after session.start() and the room connects, immediately call session.generate_reply() or session.say() so the agent speaks first after answering.
Example snippet:
@server.rtc_session(agent_name='lesson-agent')
async def my_agent(ctx: JobContext):
await session.start(room=ctx.room, agent=Assistant())
await ctx.connect()
await session.generate_reply(instructions="Greet the caller and say lesson is starting.")
Key notes
• Use generate_reply() for dynamic, context-aware greetings; use session.say("fixed text") for a fixed message.
• The agent will not speak automatically—you must call generate_reply() or say() in response to the button RPC or after connecting the telephony session.
• LiveKit phone numbers can be assigned to dispatch rules so inbound calls will trigger your agent; after answer, trigger the greeting as shown.
Would you like a tailored example using your existing agent code (language/SDK) or help wiring the RPC from your specific frontend framework?
Sources: Agent Builder | LiveKit docs | Agents telephony integration | LiveKit docs | Agent speech and audio | LiveKit docs | LiveKit Phone Numbers | LiveKit docs | Turn detection and interruptions | LiveKit Docs