happy-fall-6105
01/01/2026, 12:06 PMtall-airline-16756
01/01/2026, 12:06 PMtall-airline-16756
01/01/2026, 12:06 PMgenerate_reply works — here's a concise explanation and how to use it.
What it does
• Triggers the agent to produce a response (via the LLM).
• Converts that response to speech with the TTS plugin and plays it in the room.
• Returns a SpeechHandle you can use to monitor playback state or interruptions.
Two ways to call it
1. With instructions (not added to chat history)
◦ Python: session.generate_reply(instructions="Greet the user and ask how you can help.")
◦ TypeScript: session.generateReply({ instructions: 'Greet the user and ask how you can help.' })
1. With user input (added to chat history)
◦ Python: session.generate_reply(user_input="How is the weather today?")
◦ TypeScript: session.generateReply({ userInput: 'How is the weather today?' })
Behavior notes
• If the frontend sends text via the lk.chat topic, the agent interrupts any ongoing speech and internally calls generate_reply.
• Use the returned SpeechHandle to wait for playback to finish or detect interruptions.
If you want, tell me which language (Python or TypeScript) and whether you need an example that checks SpeechHandle state, and I’ll provide a short snippet.
Sources: Agent speech and audio | LiveKit docs | Text and transcriptions | LiveKit docshappy-fall-6105
01/01/2026, 12:07 PMtall-airline-16756
01/01/2026, 12:07 PMgenerate_reply (not session.say()). You can do this by passing that text as either instructions (not added to chat history) or user_input (added to history). Use whichever fits your flow.
If you want the message sent as the agent's normal reply and played via TTS, use generate_reply with the text. Examples:
• Python (as user input):
speech_handle = session.generate_reply(user_input="You've exceeded the maximum call duration.")
# wait for playback or check state on speech_handle as needed
• TypeScript (as user input):
const speechHandle = await session.generateReply({
userInput: "You've exceeded the maximum call duration."
});
// await or monitor speechHandle for playback state
If you prefer the message not be added to chat history (treated as an instruction), pass it as `instructions`:
• Python:
speech_handle = session.generate_reply(instructions="Tell the user they've exceeded the maximum call duration.")
• TypeScript:
const speechHandle = await session.generateReply({
instructions: "Tell the user they've exceeded the maximum call duration."
});
Notes
• generate_reply returns a SpeechHandle to monitor playback or detect interruptions.
• If you need the agent to interrupt ongoing speech before sending this message, generate_reply will handle interruption when called (the agent interrupts current speech and plays the new reply).
• Tell me whether you want the text added to chat history or not, and if you want a snippet showing how to wait for or handle the SpeechHandle state.happy-fall-6105
01/01/2026, 12:22 PMtall-airline-16756
01/01/2026, 12:22 PMinstructions to generate_reply, the agent generates its reply based on those instructions. The instructions are used to guide the LLM but are not added to the chat history.
Example (TypeScript):
const speechHandle = await session.generateReply({
instructions: "Tell the user they've exceeded the maximum call duration."
});
Example (Python):
speech_handle = session.generate_reply(instructions="Tell the user they've exceeded the maximum call duration.")
If you want the response recorded in chat history, pass the text as user_input instead. Would you like a snippet that waits on the returned SpeechHandle or handles interruptions?happy-fall-6105
01/01/2026, 1:25 PMtall-airline-16756
01/01/2026, 1:25 PMinstructions, the agent generates the reply based solely on those instructions (instructions are not added to chat history).
• If you pass user_input, the agent generates a reply that can be influenced by the existing chat history and context (the user_input is added to history).
If you want, I can provide a short Python or TypeScript snippet showing each case and how to wait on the returned SpeechHandle. Which language do you prefer?