This topic describes how to interrupt an agent using the AICallKit SDK.
Notes
This example demonstrates how to use API operations to implement this feature in an integration solution that does not have a user interface (UI).
Before you start, integrate the AICallKit SDK. For more information, see Android guide, iOS guide, and Web guide.
This feature and the user interface (UI) are built into the UI-integrated solution. For more information about the UI-integrated solution, see the UI-integrated solution.
Implement agent interruption
You can interrupt an agent in three ways: voice interruption, manual interruption, and interruption by specific words.
Semantic segmentation
Server-side configuration
When starting an agent on the server-side, you must configure the Mode and SemanticWaitDuration parameters in AIAgentConfig when calling the start agent instance or generate AI agent call instance API.
Client-side configuration
When starting an agent on the client-side, you must configure the Mode and SemanticWaitDuration parameters in ARTCAICallAgentTurnDetectionConfig within ARTCAICallAgentConfig.
Manual interruption
Manual interruption sends a command to stop a speaking agent's current response. In the AICallKit SDK, call the interruptSpeaking method to do this.
Voice interruption
Voice interruption allows you to interrupt an agent by speaking. For example, if the agent is answering question A and you ask question B, the agent stops answering A and begins to answer B. In the AICallKit SDK, call enableVoiceInterrupt to enable or disable this feature. When the status of voice interruption changes, the onVoiceInterrupted callback is triggered. This callback confirms the final status.
Sample code
Android
// Voice interruption is enabled by default. Pass false to disable it.
mARTCAICallEngine.enableVoiceInterrupt(false);
// Manually interrupt the agent.
mARTCAICallEngine.interruptSpeaking();
// Callback handling (only relevant callbacks are shown for this example).
ARTCAICallEngine.IARTCAICallEngineCallback mCallEngineCallbackWrapper = new ARTCAICallEngine.IARTCAICallEngineCallback() {
@Override
public void onVoiceInterrupted(boolean enable) {
// A callback that confirms the final status (enabled or disabled) of voice interruption for the current call.
}
}iOS
// Voice interruption is enabled by default. Pass false to disable it.
_ = self.engine.enableVoiceInterrupt(enable: false)
// Manually interrupt the agent.
_ = self.engine.interruptSpeaking()
func onVoiceInterrupted(enable: Bool) {
// A callback that confirms the final voice interruption status (enabled or disabled) for the current call.
}
Web
// Voice interruption is enabled by default. Pass false to disable it.
engine.enableVoiceInterrupt(false);
// Manually interrupt the agent.
engine.interruptSpeaking();
engine.on('voiceInterruptChanged', (ennable) => {
// Fired when the voice interruption status changes. The 'ennable' parameter indicates the final status.
console.log('AICallVoiceInterruptChanged', ennable);
});Specific word interruption
With interruption by specific words, the agent is interrupted whenever a configured word is detected during a call. You typically configure these words when starting the agent.
Sample code
Android
// 1. Set the interruptWords parameter when starting the call.
ARTCAICallEngine.ARTCAICallConfig artcaiCallConfig = new ARTCAICallEngine.ARTCAICallConfig();
artcaiCallConfig.agentConfig.interruptConfig.interruptWords.add("Interrupt");
artcaiCallConfig.agentConfig.interruptConfig.interruptWords.add("Test interruption");
// Omit the call initiation process.
......
// 2. When a specific word triggers an interruption, the onSpeakingInterrupted callback is invoked with the reason ByWords.
@Override
public void onSpeakingInterrupted(ARTCAICallEngine.ARTCAICallSpeakingInterruptedReason reason) {
// The reason is ARTCAICallSpeakingInterruptedReason.ByWords
}iOS
// 1. Set the interruptWords parameter when starting the call.
let agentConfig = ARTCAICallAgentConfig() // Create an ARTCAICallAgentConfig object.
agentConfig.interruptConfig.interruptWords = ["Interrupt", "xxxx"]
// Omit the call initiation process.
......
// 2. When a specific word triggers an interruption, the onSpeakingInterrupted callback is invoked with the reason ByWords.
public func onSpeakingInterrupted(reason: ARTCAICallSpeakingInterruptedReason) {
}Web
// 1. Set the interruptWords parameter when starting the call.
const agentConfig = new AICallAgentConfig(); // Create an AICallAgentConfig object.
agentConfig.interruptConfig.interruptWords = ['Interrupt', 'xxxx'];
// Omit the call initiation process.
......
// 2. When a specific word triggers an interruption, the 'speakingInterrupted' event is emitted with the reason 'byWords'.
engine.on('speakingInterrupted', (reason) => {
});