flaky-hospital-13625
08/11/2025, 11:53 PMtall-airline-16756
08/11/2025, 11:53 PMtall-airline-16756
08/11/2025, 11:53 PMsession.interrupt()
Method: This will pause the agent’s current speech so the user can jump in.
• Resume Speaking with `session.generate_reply()`: Once the interruption is over, you can have the agent pick up by generating a new reply. This usually happens inside an event handler that listens for interruptions.
• Adjust Interruption Settings: You can tweak parameters like min_interruption_duration
and min_interruption_words
in AgentSession
to decide what counts as an interruption.
Here’s a little example showing how to get the agent talking again after an interruption:
# Inside your agent's event handler
@session.on("agent_state_changed")
async def handle_agent_state(ev: AgentStateChangedEvent):
if ev.new_state == "listening" and ev.old_state == "speaking":
# Generate a new reply to resume speaking
session.generate_reply(instructions="Thank you for interrupting. Please continue.")
Also, you can fine-tune how interruptions work by setting these parameters when you create the `AgentSession`:
session = AgentSession(
agent_false_interruption_timeout=4.0,
min_interruption_duration=0.5,
min_interruption_words=3,
)
This way, the agent knows exactly when to pause and when to jump back in, making the conversation flow smoothly based on what your app needs.