Agent-UI Protocols: Real-Time UI Streaming & Event Envelopes
[!NOTE]
Executive Overview
Attribute Details Status ๐ Architectural Standard What It Is Communication patterns and event envelope contracts that synchronize autonomous AI agents with responsive web frontends. Core Problem & Solution Unstructured markdown streaming causes UI pop-in and cannot trigger interactive controls. This protocol uses strongly typed JSON event envelopes to stream thoughts, tool calls, and dynamic widgets ("AG-UI") over WebSockets and SSE. Tech Stack WebSockets, Server-Sent Events (SSE), Zod Schema Validation, SvelteKit, TypeScript Key Highlights Dynamic widget summoning (approval gates, progress bars, equity curves), transparent reasoning deltas, deterministic error recovery.
When building agentic web applications, raw text streaming is insufficient. Modern agentic UX requires the backend to stream reasoning traces, tool executions, and interactive UI widgets without breaking conversational rhythm.
1. Structured Envelope Messaging Pattern
All agent-to-client communication passes through immutable, typed event envelopes:
interface AgentEventEnvelope<T = unknown> {
id: string; // Unique event UUID
timestamp: string; // ISO 8601 timestamp
sessionId: string; // Client conversation ID
agentName: string; // Emitting specialist agent
eventType: 'thought' | 'tool_call' | 'tool_result' | 'widget_summon' | 'content' | 'done';
payload: T; // Strongly typed payload validated by Zod
}
- Thought Streaming: Passes raw thinking tokens into dedicated reasoning drawers, keeping the main response cleanly formatted.
- Tool Triggers: Emits structured arguments (
tool_call) and status updates (tool_result), allowing the UI to render real-time execution pills.
2. Dynamic Widget Summoning ("AG-UI")
Rather than forcing the user to leave the chat stream to complete an action, agents dynamically "summon" reactive widgets directly into the conversation:
- Human-in-the-Loop Gates: Agents pause execution and summon an approval button before high-stakes operations (e.g. initiating a 50-trial model training run or deploying a game).
- Embedded Visualizations: Streaming SVG line charts, progress meters, and code diff blocks render dynamically within the message bubble.
3. Protocol Resilience & Reconnection Handling
- Idempotent Sequence Keys: Every envelope carries a monotonically increasing sequence counter per session.
- Replay Buffers: Temporary network interruptions trigger an automatic reconciliation request, replaying missed packets from the server's cache.