Skip to content

Refeature/interrupt-handler-SirjanSingh#498

Open
SirjanSingh wants to merge 5 commits intoDark-Sys-Jenkins:mainfrom
SirjanSingh:feature/interrupt-handler-SirjanSingh
Open

Refeature/interrupt-handler-SirjanSingh#498
SirjanSingh wants to merge 5 commits intoDark-Sys-Jenkins:mainfrom
SirjanSingh:feature/interrupt-handler-SirjanSingh

Conversation

@SirjanSingh
Copy link

PR: Implement Hybrid Intelligent Interruption Handler

Summary

Refactored the voice agent to implement a hybrid interruption handling strategy that correctly differentiates between filler words and stop commands.

Problem Solved

  • Slow filler words (e.g., "okay" said over 1.5s) were incorrectly interrupting the agent
  • Quick commands (e.g., "stop" said in 0.5s) were not always triggering interrupts

Solution

  • Medium VAD thresholds (0.6s duration, 2 words minimum)
  • Auto-resume on false interruptions via resume_false_interruption=True
  • Transcript-based command detection to force interrupts when VAD misses quick commands
  • Filler suppression to prevent acknowledgments from interrupting speech

Key Changes

  • Simplified import structure
  • Removed @function_tool weather lookup (moving to separate PR)
  • Added state tracking for VAD interruptions (was_interrupted_by_vad)
  • Enhanced logging with emoji indicators for debugging
  • Added speech_created and user_state_changed event handlers

Updated README to reflect intelligent interruption handling implementation for LiveKit Voice Agent, detailing challenges, solutions, and key code changes.
Refactor basic agent to implement a hybrid interruption strategy for better command recognition and filler handling.
Copilot AI review requested due to automatic review settings February 2, 2026 18:28
Refine the hybrid interruption handling strategy to better distinguish between filler words and commands based on timing.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the basic_agent.py voice agent to implement a hybrid interruption-handling strategy that distinguishes filler acknowledgments from explicit stop commands, and adds detailed documentation in examples/voice_agents/README.md explaining the design.

Changes:

  • Implemented IntelligentAgent in basic_agent.py with VAD configuration, filler/command word detection, and event-driven state tracking (speech_created, agent_state_changed, user_state_changed, user_input_transcribed) to realize the hybrid interruption strategy.
  • Tuned AgentSession options (VAD thresholds, interruption settings, endpointing delays) to support the new behavior and added extensive logging for debugging.
  • Rewrote examples/voice_agents/README.md to document the intelligent interruption handler, including requirements, design rationale, configuration parameters, and testing scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
examples/voice_agents/basic_agent.py Replaces the simple basic agent with IntelligentAgent, configuring VAD/interrupt options and transcript-based logic to differentiate fillers from stop commands, and wires up relevant session event handlers with diagnostic logging.
examples/voice_agents/README.md Replaces the generic voice-agents index with a detailed design doc for the intelligent interruption handler implemented in basic_agent.py, covering behavior, configuration, and test scenarios.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 20 to 28
import logging
import re
import asyncio
from typing import Optional
from dotenv import load_dotenv
from livekit.agents import (
Agent,
AgentServer,
AgentSession,
JobContext,
JobProcess,
MetricsCollectedEvent,
RunContext,
cli,
metrics,
room_io,
Agent, AgentServer, AgentSession, JobContext, JobProcess,
cli, UserInputTranscribedEvent, AgentStateChangedEvent,
UserStateChangedEvent
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These imports (asyncio, Optional, UserInputTranscribedEvent, AgentStateChangedEvent, UserStateChangedEvent) are currently unused in this module and can be removed to reduce clutter and keep dependencies minimal, or alternatively used for type annotations on the event handlers if that was the intention.

Copilot uses AI. Check for mistakes.

self.is_speaking = False
self.was_interrupted_by_vad = False
self.last_speech_content = ""
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last_speech_content is written when speech_created fires but never read anywhere, so this state adds complexity without affecting behavior; consider either removing it or wiring it into a concrete resume/use case.

Suggested change
self.last_speech_content = ""

Copilot uses AI. Check for mistakes.
Comment on lines 192 to 193
except:
logger.warning("⚠️ False interruption event not available in this LiveKit version")
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a bare except: here will swallow system-exiting exceptions (e.g., KeyboardInterrupt, SystemExit) and makes debugging harder; it would be safer to catch Exception explicitly or a narrower error type for feature-detection of agent_false_interruption.

Suggested change
except:
logger.warning("⚠️ False interruption event not available in this LiveKit version")
except Exception as exc:
logger.warning(
"⚠️ False interruption event not available in this LiveKit version: %s",
exc,
)

Copilot uses AI. Check for mistakes.
**Requirements:**
1. **When agent is speaking + user says filler** → Agent continues uninterrupted
2. **When agent is speaking + user says command** → Agent stops immediately
3. **When agent is silent** → All user speech is valid input
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The requirements section states that "When agent is silent → All user speech is valid input" (point 3), but later in the document and in basic_agent.py filler input while idle is explicitly suppressed; the requirements text should be updated to match the actual designed behavior (idle fillers are ignored).

Suggested change
3. **When agent is silent**All user speech is valid input
3. **When agent is silent**Non-filler user speech is valid input; idle fillers may be ignored

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +5
# Intelligent Interruption Handling for LiveKit Voice Agent

This directory contains a comprehensive collection of voice-based agent examples demonstrating various capabilities and integrations with the LiveKit Agents framework.
## Overview

## 📋 Table of Contents
This document explains the modifications made to `basic_agent.py` to implement intelligent interruption handling that distinguishes between **filler words** (acknowledgments like "yeah", "okay") and **command words** (interruptions like "stop", "wait").
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This README now focuses solely on the intelligent interruption handler in basic_agent.py, but the examples/voice_agents directory still contains many other example scripts that were previously indexed here; consider restoring or relocating a lightweight table of contents so users can still discover the rest of the voice agent examples from this README.

Copilot uses AI. Check for mistakes.
)
from livekit.agents.llm import function_tool
from livekit.plugins import silero
from livekit.plugins import silero, deepgram, openai, cartesia
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'deepgram' is not used.
Import of 'openai' is not used.
Import of 'cartesia' is not used.

Suggested change
from livekit.plugins import silero, deepgram, openai, cartesia
from livekit.plugins import silero

Copilot uses AI. Check for mistakes.
Refactor IntelligentAgent to improve command and filler detection logic, update logging for clarity, and streamline state management.
Added student details and improved documentation on intelligent interruption handling in voice agents.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant