rich-dusk-37560
09/15/2025, 4:31 PMsession.interrupt() method. When an interruption occurs, the agent stops speaking and automatically truncates its conversation history to reflect only the speech that the user actually heard before interruption.
Example?tall-airline-16756
09/15/2025, 4:31 PMtall-airline-16756
09/15/2025, 4:32 PMsession.interrupt() method in LiveKit to make your experience smoother:
• Manual Turn Control: Imagine a push-to-talk setup—here, you can use session.interrupt() to gently pause the agent's speech whenever the user starts speaking:
session = AgentSession(turn_detection="manual")
session.input.set_audio_enabled(False)
@ctx.room.local_participant.register_rpc_method("start_turn")
async def start_turn(data: rtc.RpcInvocationData):
session.interrupt() # Stop agent if speaking
session.clear_user_turn()
session.input.set_audio_enabled(True) # Start listening to user
• Interrupting Before Non-Verbal Tasks: Before diving into a non-verbal task, you can smoothly stop the agent's speech and listening like this:
session.interrupt() # Stop any ongoing speech
session.input.set_audio_enabled(False) # Stop listening
try:
await do_job() # Perform non-verbal job
finally:
session.input.set_audio_enabled(True) # Resume listening
• Explicit Interruption: Even if interruptions are usually off, you can still gently interrupt the agent’s speech when needed:
handle = session.say("Hello world")
session.interrupt() # Can interrupt even if allow_interruptions=False
• Agent Handoff: When it’s time to transition to another agent, you can kindly stop the current agent’s speech first:
@function_tool
async def story_finished(self, context: RunContext[StoryData]):
self.session.interrupt() # Stop ongoing speech
await self.session.generate_reply(instructions=f"say goodbye to {context.userdata.name}")
# Proceed to end the call or switch agents
If you have any questions or want me to walk you through more examples, just let me know—I’m here to help!
Sources: Turn detection and interruptions | LiveKit Docs | Text and transcriptions | LiveKit Docs | Agent speech and audio | LiveKit Docs | main.py | livekit-agents/livekit/agents/voice/speech_handle.py