For critical information that users must hear completely, disable interruption handling:
Copy
class PaymentAgent(OutputAgentNode): def __init__(self): super().__init__( name="payment-agent", is_interruptible=False # User must hear the full message )
class MyAgent(OutputAgentNode): def __init__(self): super().__init__(name="my-agent") self.was_interrupted = False self.pending_message = "" async def _handle_interrupt(self): """Called when the user interrupts.""" self.was_interrupted = True # Clear any pending state self.pending_message = "" # Call parent handler await super()._handle_interrupt() async def generate_response(self): if self.was_interrupted: yield "Sorry, I was saying something. What did you need?" self.was_interrupted = False return # Normal response generation async for chunk in self._generate_normal(): yield chunk
class ResumableAgent(OutputAgentNode): def __init__(self): super().__init__(name="resumable-agent") self.last_topic = None self.interrupted_mid_response = False async def _handle_interrupt(self): self.interrupted_mid_response = True await super()._handle_interrupt() async def generate_response(self): # Get last user message user_msgs = [m for m in self.context.messages if m["role"] == "user"] user_message = user_msgs[-1]["content"] if user_msgs else "" # Check if user wants to continue previous topic if self.interrupted_mid_response and "continue" in user_message.lower(): yield f"Sure, back to {self.last_topic}. " # Resume previous topic self.interrupted_mid_response = False return self.interrupted_mid_response = False # Normal response generation...