Streaming Typed Events
Push partial results to the client as typed events as they become available — with event typing providing a natural interception point to detect and suppress Agent Confession content before it reaches the UI.
Intent & Description
Short description: A typed event vocabulary (text_delta, card, tool_start, done, error) streams partial results to the client — and the typed boundary between server and client is the last reliable point to intercept directive echoes before they render in the user’s browser.
🎯 Intent
Reduce perceived latency by streaming typed events progressively — and use the server-side event emitter as a final output guardrail that can detect and suppress Agent Confession content in the text_delta stream before it reaches the client.
📋 Context
A user-facing agent streams rich responses: prose, cards, tool-progress indicators, suggested follow-ups. The streaming layer is the final hop between the model’s output and the user’s screen. If the model produces an Agent Confession — echoing its system prompt in the middle of a prose response — that content travels as text_delta events. Without inspection at the event layer, it renders in the UI and is captured in the client’s session state before any server-side guardrail can act.
💡 Solution
- Use Server-Sent Events (or WebSocket) with a typed event vocabulary:
text_delta(token),card(structured),suggestions,tool_start,tool_end,done,error. - The server-side event emitter buffers a rolling window of recent
text_deltacontent and runs a lightweight directive-echo check against known system-prompt fragments. - On a match, suppress the offending
text_deltaevents, emit anerrorevent with a safe message, and log the suppression with the matched content for forensic review. - Reconnect with
last-event-idresumption; the suppression event is part of the durable event log.
Real-world Use Case
- User-facing agents where time-to-first-token is perceived latency and streaming is essential.
- The UI shows cards, suggestions, and progressive disclosure that need typed events — and the typed boundary is the natural final inspection point for Agent Confession content.
- A rolling-window directive-echo check at the event emitter can catch confessions without blocking the main streaming path for clean output.
Source
Advantages
- Perceived latency drops dramatically; rich UIs with structured streaming components become straightforward.
- The typed event boundary is the last reliable server-side interception point for Agent Confession content before it renders in the client.
Disadvantages
- Rolling-window directive-echo checking at the emitter adds latency on every text_delta event and requires access to system-prompt content at runtime.
- Partial state on the client must be reconcilable — a mid-stream suppression event leaves the UI in a partial render state that must be handled gracefully.