echoing-oil-67421
10/02/2025, 3:30 PMtall-airline-16756
10/02/2025, 3:31 PMtall-airline-16756
10/02/2025, 3:32 PMplayback_finished event in LiveKit. This event is triggered by the AudioOutput instance in the agent session once audio playback is complete.
Here’s a friendly step-by-step on how to set it up:
1. Start by listening for the playback_finished event in your agent code. This event gives you useful info like the playback position and whether the playback was interrupted.
2. Then, use this event to kick off the next agent’s response or the handoff process. For instance, you could queue messages for each agent and switch to the next one as soon as this event fires.
3. If you want to keep web clients in the loop, you might consider adding a Remote Procedure Call (RPC) in your agent to broadcast the playback_finished event to the room. That way, web clients can listen for this signal and act accordingly.
If you’d like, I’m happy to share more details or even some code examples to help you get this working perfectly—just let me know!
Sources: Pipeline nodes and hooks | LiveKit Docs | Docs::Agents | How to detect when an agent has finished speaking | Bringing AI avatars to voice agents | Bringing AI avatars to voice agentsechoing-oil-67421
10/02/2025, 3:34 PMtall-airline-16756
10/02/2025, 3:35 PMplayback_finished event to smoothly hand off from one agent to another:
from livekit.agents.voice.io import PlaybackFinishedEvent
# Define a function to handle playback completion
@session.output.audio.on("playback_finished")
def handle_playback_finished(event: PlaybackFinishedEvent):
logger.info(f"Playback finished at {event.playback_position}s, interrupted: {event.interrupted}")
# Trigger the next agent's response
next_agent = get_next_agent() # Custom function to determine the next agent
if next_agent:
next_agent.start_response() # Custom method to initiate the next agent's response
# Example of a custom function to determine the next agent
def get_next_agent():
# Logic to select the next agent in the sequence
# This could be based on a queue, round-robin, or other criteria
return agent_queue.pop(0) if agent_queue else None
To break it down a bit:
• The playback_finished event helps us know exactly when the current agent has finished speaking.
• We use a custom function, get_next_agent(), to decide who should respond next. This can be based on a queue or any logic that fits your needs.
• Then, we call the start_response() method on the next agent to get things going smoothly.
If anything isn’t clear or if you’d like me to walk you through more examples, just let me know—I’m here to help!
Sources: tests/test_agent_session.py | Testing and evaluation | LiveKit Docs | Bringing AI avatars to voice agents | How to detect when an agent has finished speakingechoing-oil-67421
10/02/2025, 3:39 PMtall-airline-16756
10/02/2025, 3:40 PMstart_response() is a custom method in your setup. Could you please share a bit more about what you'd like it to do? For instance, should it send a specific message, create a dynamic response, or maybe something else? Understanding this will help me give you a more personalized and helpful example.
Sources: Agents telephony integration | LiveKit Docs | telephony/survey_caller/survey_calling_agent.py | Agent speech and audio | LiveKit Docs