Overview
AG-UI (Agent-User Interaction Protocol) is an open, lightweight, event-based protocol for standardizing real-time communication between AI agents and user interfaces. It was initiated and open-sourced by the CopilotKit team in May 2025.
Key points
- Design principles: event-driven (all communication via events, not request-response), streaming-first (latency under ~100ms), "state as stream" (state changes propagate via event streams), framework-agnostic, and transport-agnostic (SSE, WebSocket, HTTP/2).
- Positioning in the agent protocol stack:
- MCP (Anthropic): Agent ↔ tools/data
- A2A (Google): Agent ↔ Agent collaboration
- AG-UI (CopilotKit): Agent ↔ user interface
- Event envelope: every event carries
protocol,type,timestamp,runId,threadId,payload, and optionalextensions. - Incremental state uses JSON Patch (RFC 6902) with operations like
replace,add,remove,move, andtest. Compared to full snapshots, this reduces bandwidth (reported ~92% savings in a genome-alignment use case), lowers latency, supports offline patch queues, and enables audit trails. - State management borrows from event sourcing: current state = fold of all events, enabling time-travel debugging, Google Docs-style collaborative editing, and offline-first apps.
- Frontend pattern: apply
STATE_SNAPSHOTto reset state, applySTATE_DELTAvia a JSON Patch library (e.g.,fast-json-patch), and support time travel by replaying the event log. - SSE is the recommended transport (HTTP-based, built-in auto-reconnect, firewall-friendly, low complexity); WebSocket suits bidirectional high-frequency scenarios; HTTP long-polling serves as a fallback.
- Reference backend implementation uses FastAPI
StreamingResponsewithmedia_type="text/event-stream", encoding events through the AG-UIEventEncoder. - Minimal example: FastAPI backend streams
RUN_STARTED→TEXT_MESSAGE_START→ token-levelTEXT_MESSAGE_CONTENT→TEXT_MESSAGE_END→RUN_FINISHED; a React frontend consumes it via anuseAGUIhook. - Framework integration: LangGraph nodes emit
STEP_STARTED/STEP_FINISHEDandSTATE_DELTAevents as planning/execution progresses. - Human-in-the-loop: agent emits an interrupt event, awaits a response via a keyed
asyncio.Futurewith timeout, then resumes execution. - Error handling: wrap execution in a context manager that emits
RUN_ERRORwith error code, message, and arecoverableflag. - Targets: first-token latency <100ms, per-event frontend handling <10ms, 90%+ bandwidth reduction vs snapshots, 10K+ concurrent connections per server.
- Optimizations: batch small token chunks (e.g., flush every 5 tokens or 50ms), gzip+base64 compress large snapshots, merge high-frequency state deltas in a batcher, reuse frontend connections via a pool.
- Security: validate event types (e.g., Pydantic validator), rate-limit event emission, and redact sensitive keys (
password,token,secret,api_key) from event payloads.
The 17 standard event types
Divided into five categories:
1. Lifecycle events: RUN_STARTED, STEP_STARTED, STEP_FINISHED, RUN_FINISHED, RUN_ERROR — for progress tracking, loading states, and error handling.
2. Text message events: TEXT_MESSAGE_START / TEXT_MESSAGE_CONTENT / TEXT_MESSAGE_END — token-level streaming output.
3. Tool call events: TOOL_CALL_START, TOOL_CALL_ARGS (streamed deltas), TOOL_CALL_END, TOOL_CALL_RESULT — full visibility into agent tool usage in the UI.
4. State management events: STATE_SNAPSHOT (full snapshot), STATE_DELTA (JSON Patch increments), MESSAGES_SNAPSHOT (conversation history) — the protocol's most distinctive design.
5. Special events: HUMAN_IN_THE_LOOP / INTERRUPT, HUMAN_RESPONSE, CUSTOM (e.g., agent handoffs), RAW (passthrough for third-party integration).
State synchronization: JSON Patch + Event Sourcing
Transport layer
AG-UI vs MCP vs A2A (vs A2UI)
| Dimension | AG-UI | MCP | A2A | |---|---|---|---| | Origin | CopilotKit (2025) | Anthropic (2024) | Google (2025) | | Core problem | Agent ↔ UI interaction | Agent ↔ tools/data | Agent ↔ Agent | | Communication | One-way event stream | Request-response | Request-response + push | | Transport | SSE/WebSocket/HTTP | stdio/SSE/HTTP | HTTP/SSE | | State | Event sourcing | Stateless | Stateful tasks |
The protocols are complementary, not competing: use AG-UI for UI interaction, MCP for tool/API access, A2A for multi-agent orchestration — or all three together. Note also A2UI (Google), a UI-description spec ("what to show", analogous to HTML) that AG-UI ("how to transport", analogous to HTTP) can carry in its payload.