How does Interruption Work
Overview
The interrupt mechanism in TEN-Agent consists of two main parts: Interrupt Detection and Interrupt Response. This document details both parts and explains how the interrupt command propagates through the AI agent graph.
Part 1: Interrupt Detection
Current Interrupt Detection Implementation
The current (interrupt_detector_python) extension implements a text-based interrupt detection mechanism:
def on_data(self, ten: TenEnv, data: Data) -> None:
text = data.get_property_string(TEXT_DATA_TEXT_FIELD)
final = data.get_property_bool(TEXT_DATA_FINAL_FIELD)
# Trigger interrupt when text is final or reaches threshold length
if final or len(text) >= 2:
self.send_flush_cmd(ten)The interrupt detector triggers in the following cases:
- When receiving final text (
is_final = true) - When text length reaches a threshold (≥ 2 characters)
Customize Interrupt Detection
To implement your own interrupt detection logic, you can refer to the implementation of interrupt_detector_python as an example and customize the interrupt conditions based on your specific needs.
Part 2: Interrupt Response
Chain Processing in AI Agent Graph
In a typical AI agent graph, the interrupt command (flush) follows a chain
processing pattern:
Interrupt Detector
↓
LLM/ChatGPT
↓
TTS
↓
agora_rtcEach extension in the chain follows two key steps when receiving a flush
command:
- Clean up its own resources and internal state
- Forward the
flushcommand 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
Conclusion
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.
Last Updated