Interrupt handling
The interrupt handling extension manages conversation flow by detecting when to stop ongoing processing and clean up system state. Like other TEN Agent extensions, it can be easily added or removed through the designer to customize your agent's behavior. This document explains how the interrupt mechanism works and how to configure or replace it with your own implementation to suit specific use cases.
Understand the tech
TEN Agent's interrupt mechanism uses a chain processing pattern to ensure orderly cleanup of all extensions in the AI agent graph. When an interrupt occurs, each extension first cleans up its own state and then forwards the flush
command to downstream extensions, ensuring a clean system state for subsequent operations.
The interrupt system consists of two main components that work together:
- Interrupt Detection: Monitors input to determine when to trigger an interrupt
- Interrupt Response: Propagates cleanup commands through the extension chain
Interrupt detection
The default interrupt detection mechanism monitors text input to determine when to halt ongoing processing.
Current implementation
The interrupt_detector_python extension implements text-based interrupt detection:
The detector triggers interrupts based on the following conditions:
- When receiving final text with
is_final = true
- When text length reaches a threshold of 2 or more characters
Customize interrupt detection
To create custom interrupt detection:
- Study the Current implementation
- Create your own extension with custom detection criteria
- Replace the default detector in your graph configuration
Common customization scenarios include:
- Voice activity detection
- Keyword-based interrupts
- Gesture or visual triggers
- Time-based thresholds
Interrupt response
When an interrupt is detected, a cleanup command propagates through the extension chain to ensure orderly system reset.
Chain processing pattern
The interrupt command (flush
) follows this typical flow through the AI agent graph:
Each extension in the chain handles the flush
command by:
- Cleaning up internal resources and state
- Forwarding the command to downstream extensions
This pattern ensures:
- Extensions clean up in the correct order
- No residual data remains in the pipeline
- Each component returns to a ready state
Chain Processing in AI Agent Graph
In a typical AI agent graph, the interrupt command (flush
) follows a chain
processing pattern:
Each extension in the chain follows two key steps when receiving a flush
command:
- Clean up its own resources and internal state
- Forward the
flush
command to downstream extensions
This ensures that:
- Extensions are cleaned up in the correct order
- No residual data flows through the system
- Each extension returns to a clean state before the next operation
Best practices
Follow these guidelines when working with interrupts:
- Always forward
flush
commands to maintain chain integrity - Clean up resources before forwarding to prevent memory leaks
- Handle interrupts gracefully to avoid cutting off responses mid-word
- Test interrupt behavior under various conditions