Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from interrupt_handler.handler import InterruptionHandler

handler = InterruptionHandler()

print("=== DEMO ===")

handler.set_agent_state(True)
print("Speaking + yeah →", handler.handle_input("yeah"))
print("Speaking + stop →", handler.handle_input("stop"))

handler.set_agent_state(False)
print("Silent + yeah →", handler.handle_input("yeah"))
3 changes: 3 additions & 0 deletions interrupt_handler/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
IGNORE_WORDS = ["yeah", "ok", "hmm", "right", "uh-huh"]

INTERRUPT_WORDS = ["stop", "wait", "no", "hold", "pause"]
29 changes: 29 additions & 0 deletions interrupt_handler/handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from interrupt_handler.config import IGNORE_WORDS, INTERRUPT_WORDS
from interrupt_handler.utils import normalize_text, contains_interrupt, is_ignore_word


class InterruptionHandler:
def __init__(self):
self.is_agent_speaking = False

def set_agent_state(self, speaking: bool):
self.is_agent_speaking = speaking

def handle_input(self, user_input: str) -> str:
text = normalize_text(user_input)

if self.is_agent_speaking:

# Mixed input → interrupt
if contains_interrupt(text, INTERRUPT_WORDS):
return "INTERRUPT"

# Only filler → ignore
if is_ignore_word(text, IGNORE_WORDS):
return "IGNORE"

# Default → interrupt
return "INTERRUPT"

else:
return "RESPOND"
13 changes: 13 additions & 0 deletions interrupt_handler/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def normalize_text(text: str) -> str:
return text.lower().strip()


def contains_interrupt(text: str, interrupt_words: list) -> bool:
for word in interrupt_words:
if word in text:
return True
return False


def is_ignore_word(text: str, ignore_words: list) -> bool:
return text in ignore_words