How does interrupt work in NYRA-Agent
Overview
The interrupt mechanism in the TEN-Agent framework is composed of two core components: Interrupt Detection and Interrupt Response. This document provides an in-depth explanation of both components and outlines how the interrupt command propagates through the AI agent graph.
Part 1: Interrupt Detection
1. Current Interrupt Detection Implementation
The current (interrupt_detector_python) extension implements a text-based interrupt detection mechanism:
def on_data(self, nyra: NyraEnv, 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(nyra)The interrupt detector is activated under the following conditions:
Upon receiving final text (
is_final = true).When the text length meets or exceeds the defined threshold (≥ 2 characters).
2. Customize Interrupt Detection
To create a custom interrupt detection logic, you can use the implementation of interrupt_detector_python as a reference, tailoring the interrupt conditions to align with your specific requirements.
Part 2: Interrupt Response
Chain Processing in AI Agent Graph
Within a conventional AI agent graph, the interrupt command (flush) is propagated through a structured sequential processing chain.
Interrupt Detector
↓
LLM/ChatGPT
↓
TTS
↓
agora_rtcEach extension within the processing chain executes two critical actions upon receiving a flush command:
Resource Clean up: Clears its own resources and resets its internal state.
Command Propagation: Forwards the flush command to downstream extensions.
This structured approach ensures:
Extensions are cleaned and reset in the proper sequence.
Residual data is effectively eliminated from the system.
Each extension is restored to a pristine state, ready for subsequent operations.
Conclusion
Nyra's interrupt mechanism employs a structured chain-processing paradigm to enforce the systematic cleanup of all extensions within the AI agent graph. Upon an interrupt event, each extension sequentially performs two critical tasks: first, it meticulously cleans its internal state and resources; second, it propagates the flush command to the subsequent extensions in the chain. This rigorous approach guarantees a coherent and pristine system state, enabling seamless execution of subsequent operations.
Last updated