What you will learn
Partial output, Cancellation, Barge-in, Backpressure, User state.
Engineering the capability
Interactive agents may stream text or audio before a complete response exists. Keep partial presentation separate from committed task state. A user interrupting a spoken answer should not accidentally approve a pending action or leave a background tool running without visibility.
Give turns identifiers and reject stale events from canceled turns. Propagate cancellation through generation and tool work where supported, while recognizing that an already committed side effect cannot simply be canceled. Explain the resulting state to the user.
Backpressure prevents slow clients from accumulating unlimited buffered output. Bound buffers and define reconnection behavior. For voice systems, distinguish interim transcription from a final user intent; acting on a changing partial transcript can target the wrong resource. Confirm consequential details through the application’s approval flow.
Reject stale streaming events
class TurnBuffer:
def __init__(self):
self.turn = None
self.text = ""
def begin(self, turn_id):
self.turn = turn_id
self.text = ""
def append(self, turn_id, text):
if turn_id != self.turn:
return False
self.text += text
return True
buffer = TurnBuffer()
buffer.begin("turn-1")
assert buffer.append("turn-1", "First")
buffer.begin("turn-2")
assert not buffer.append("turn-1", " stale output")
assert buffer.append("turn-2", "Current")
assert buffer.text == "Current"
This protects presentation state in one process. Add a bounded buffer and authenticated task identity in an actual transport. Ignoring late output does not cancel an already executed tool or reverse a committed action.
Worked case
A user says “update ticket forty… actually fourteen.” Executing from the partial transcript may update ticket 40. Wait for a stable intent and show the exact proposal. If a new turn cancels the old one, late events from the old generation must not overwrite the current interface.
Put it into practice
Continue with the next lab: simulate an interruptible conversation. Build the artifact, record the failure cases, and explain the tradeoff before moving on.