I am using the session.interrupt function: ```def...
# ask-ai
d
I am using the session.interrupt function:
Copy code
def interrupt(self) -> asyncio.Future[None]:
        """Interrupt the current speech generation.

        Returns:
            An asyncio.Future that completes when the interruption is fully processed
            and chat context has been updated.
How to prevent chat completion after interruption ? I would like something that stop the current session until session.update_agent is called
t
Thanks for reaching out, W. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Could you clarify what you mean by "prevent chat completion" after using
session.interrupt
? Are you looking to pause all further processing of the session until
session.update_agent
is explicitly called, or is there a specific behavior you want to enforce during this pause? Sources: examples/voice_agents/push_to_talk.py
d
Basically I would like to do a single session with a handoff from Agent 1 to Agent 2. When I call session interrupt I expected Agent 1 to stop speaking until Agent 2 start speaking but in my case Agent 1 stop speaking and then completes the speech generation when the interruption is fully processed before handoff to Agent 2
t
Here’s how you can smoothly hand off a session from Agent 1 to Agent 2 and make sure Agent 1 stops speaking right after `session.interrupt`: 1. First, call
session.interrupt()
to immediately stop Agent 1’s speech and audio playback. This makes sure the interruption is fully handled. 2. Next, use
session.clear_user_turn()
to clear out any leftover audio or transcription from Agent 1. 3. Then, call
session.commit_user_turn()
to wrap up the current user turn and update the conversation context. 4. Finally, switch over to Agent 2 by calling
session.update_agent(new_agent=agent_2)
. Just a quick tip: make sure
allow_interruptions
is set to
True
in your session settings so interruptions can happen smoothly. Following these steps will ensure Agent 1 stops completely before Agent 2 starts talking. If anything’s unclear or you want me to walk you through it, just let me know—I’m here to help! Sources: livekit-agents/livekit/agents/voice/agent_activity.py