Connecting UI to AI Agents

Wire Protocols & Generative UI — The Full Stack

Agent Interface

Two problems. Multiple protocols. One coherent picture.

The Problem

AI agents respond with plain text

  • Complex data (charts, forms, dashboards) can't be expressed as text
  • No real-time interactive interfaces
  • No standardized way for agents to control or generate UI

Key insight

Two separate problems are being conflated. The way agents communicate with UIs is different from what they render.

Two Distinct Problems

Problem 1: Wire Protocol

How do agent and UI communicate?

Like OpenAI's Chat API standardized LLM invocation — we need a standard for agent↔UI messaging.

  • • Streaming events bidirectionally
  • • State synchronization
  • • Tool calls, lifecycle, interrupts

Problem 2: UI Rendering

What does the agent show?

What format describes the UI? How much freedom does the agent have? How is it rendered safely?

  • • Component catalogs vs raw HTML
  • • Sandboxing & security
  • • Cross-platform rendering

Orthogonal concerns. You need BOTH. Different protocols address different layers.

The Agentic Protocol Stack

Three protocols complete the agentic ecosystem — each addressing a distinct layer:

Protocol Stack

AG-UI — The Wire Protocol

Event-driven streaming protocol. 16 standard event types + extensible with custom events. Transport-agnostic.

NOT a generative UI spec — it's the pipe that carries them all.

Top 3 Differentiators

Bidirectional State

Snapshot/delta pattern (RFC 6902 JSON Patch). Agent reads AND writes UI state.

Transport-Agnostic

SSE, binary HTTP, WebSocket. Middleware adapts any agent framework.

Carries All UI Specs

A2UI, Open-JSON-UI, Open GenUI can all be transported over AG-UI events.

CopilotKitStrandsLangGraphMastraCrewAI

AG-UI — Event Categories

Events stream Agent → UI. UI state flows back via RunAgentInput (the POST that starts each run).

Start → Content → End

Streaming content (text, tool args)

Snapshot → Delta

State synchronization (JSON Patch)

CategoryEventsPurpose
LifecycleRunStarted → RunFinished/ErrorTrack run progression
TextStart → Content (δ) → EndStream message content
Tool CallsStart → Args (δ) → End → ResultAgent invokes tools
StateSnapshot / DeltaSync agent ↔ UI state
ActivitySnapshot / DeltaProgress updates
ReasoningStart → Content → EndChain-of-thought visibility
Customname + valueApplication extensions

The Generative UI Spectrum

Developer-Defined UI

Controlled (client-side)
Components in your frontend. Agent selects + provides data.
MCP Apps (server-side)
Full HTML apps on MCP server. Agent triggers, host renders.

Agent-Generated UI

Declarative (constrained)
A2UI / json-render — agent generates JSON from a catalog.
Open-ended (unconstrained)
Open GenUI — agent writes raw HTML. No guardrails.

Key axis: Who controls the UI? Developer (pre-defined) vs Agent (generated at runtime). Within agent-generated, how much freedom: catalog-constrained vs fully open.

A2UI — Declarative GenUI (Google)

Transport-agnostic JSON streaming spec. Agent generates component tree, client renders from catalog.

GoogleJSONL StreamingCross-Platform18 ComponentsTransport-Agnostic

Top 3 Differentiators

Transport-Decoupled

Works over AG-UI, A2A, MCP, SSE, WebSocket. Not tied to any framework.

Bidirectional Actions

Components declare events; user clicks → action sent to agent with data context.

Swappable Catalogs

Use the basic 18-component catalog or define your own design system.

Prompt-first (v0.9): Schema injected into LLM prompt. Agent generates JSON. Validate. Retry if invalid.

A2UI — How It Works

4 message types streamed as JSONL:

createSurface — Initialize surface (ID, catalog, theme)
updateComponents — Flat adjacency-list of components (by ID)
updateDataModel — Populate data via JSON Pointers (RFC 6901)
deleteSurface — Remove the UI

Rendering: Client buffers components until root is defined, then renders the full tree. Dynamic updates arrive as additional messages.

A2UI — Actions: How the UI Talks Back

The action message is the only client→server message type.

① Button declares action with bindings

"context": { "email": { "path": "/formData/email" }, "itemId": "123" }

② On click: client resolves paths against local data model

{ "path": "/formData/email" }  →  "jane@example.com"

③ Sends resolved action to agent

{ "name": "submit_form", "context": { "email": "jane@example.com", "itemId": "123" } }

④ If sendDataModel=true → full data model attached in transport metadata

Server gets concrete values + complete state. Responds with new components/data.

A2UI — sendDataModel

A flag on createSurface, not a message type.

User types, toggles, selects...

Local data model updates reactively. No network calls.


User clicks a Button...

Action fires

Client attaches full data model snapshot in transport metadata alongside the action.

Server receives

Action context (resolved values) + complete data model. Full picture at decision time.

Why: Minimizes network traffic. No keystroke-by-keystroke sync. Server gets consistent state at decision points.

json-render (Vercel)

Schema-constrained generative UI. Library (not protocol). Zod catalog defines guardrails.

VercelZod SchemasMulti-FrameworkStreamingApache-2.0

Top 3 Differentiators

Zod Guardrails

TypeScript-first. AI can ONLY produce specs matching your catalog. Compile-time safety.

Multi-Framework

React, Vue, Svelte, Solid, React Native — same catalog.

Partial JSON Streaming

LLM streams JSON token-by-token. Parser renders components as props complete.

How: defineCatalog() → catalog.prompt() auto-generates system prompt → AI generates constrained JSON → partial parser renders progressively.

A2UI vs json-render

Both: Agent generates JSON spec → client maps to real components from a catalog.

AspectA2UIjson-render
NatureProtocol (multi-vendor, Google)Library (Vercel, Apache-2.0)
SchemaJSON SchemaZod (TypeScript)
TransportAny (AG-UI, A2A, MCP, SSE)Vercel AI SDK
OutputJSONL stream (4 message types)Single JSON tree (partial-parsed)
BidirectionalBuilt-in (actions + events)Actions call local handlers
PlatformsReact, Lit, Angular, FlutterReact, Vue, Svelte, Solid, RN

TL;DR: Same pattern. A2UI = open protocol (multi-vendor). json-render = typed library (Zod DX).

MCP Apps — Open-ended GenUI

Full HTML/CSS/JS apps in sandboxed iframes inside MCP hosts.

Key: Pre-built by the MCP server developer and served from the backend. The client (host) simply renders them — no client-side control over the UI.

ClaudeVS CodeGoosePostmanSandboxed

Key insight: If you don't own the client code, MCP Apps is today the only client-agnostic way to render rich interactive UI from an agent.

Top 3 Differentiators

Full Web Platform

Any JS library (D3, Three.js, CesiumJS). No catalog constraints.

Client-Agnostic

Works in any MCP host. No custom frontend code needed.

Context Preserved

UI lives inside the conversation. No tab switching.

MCP Apps — postMessage Deep Dive

window.postMessage + JSON-RPC = secure tunnel between iframe and host.

① Host renders app in <iframe sandbox>

Sandbox blocks DOM access, cookies, parent navigation

② App sends ui/initialize via postMessage

Establishes JSON-RPC channel. Host confirms capabilities.

③ App → Host: tools/call

{"jsonrpc":"2.0","method":"tools/call","params":{"name":"get_data"},"id":1}

④ Host → App: result

{"jsonrpc":"2.0","result":{"content":[...]},"id":1}

Also: ui/sendMessage, ui/openLink

App can inject messages into conversation or request navigation.

Open Generative UI — The Wild Card

Agent generates raw HTML. Rendered in double-iframe sandbox. Disposable interfaces.

How It Works

  • 1. Frontend registers HTML-render tool via AG-UI
  • 2. Agent writes complete HTML/CSS/JS
  • 3. CopilotKit renders in double-iframe sandbox
  • 4. User interacts; interface is ephemeral

One Flag

<CopilotKit openGenerativeUI={true}>

That's it. No catalog, no schema.

Pros

  • Zero coupling
  • Disposable UIs
  • Lowest dev effort

Cons

  • Unpredictable styling
  • Hard to brand
  • No feedback to agent

Best For

"Show me how electrons work" — throwaway visualizations

Bidirectional — AG-UI

Shared mutable state. Both sides read AND write.

AG-UI Bidirectional

Unique to AG-UI: "If sidebar is closed, open it" — agent reasons about current UI state and acts on it. No server round-trip for state mutations.

Bidirectional — A2UI

Surface-scoped data model + action events. Event-driven, not continuous.

A2UI Bidirectional

Key difference from AG-UI: Agent cannot read UI state on demand. It only receives data when the user explicitly acts (button click). No continuous sync.

Bidirectional — MCP Apps & Others

MCP Apps

Request/response

  • App calls tools/call
  • Host returns MCP App
  • No shared state model
  • App manages own DOM

json-render

One-directional + actions

  • Agent → UI via data binding
  • Actions fire with params
  • Client function calling

Open GenUI

Stateless

  • Agent writes full HTML
  • No incremental updates
  • No feedback to agent
  • Ephemeral by design

Bidirectional Summary

Shared StateAgent Reads UIUI Sends EventsContinuous Sync
AG-UI✅ Snapshot+Delta✅ State in RunAgentInput✅ Frontend tools✅ Agent→UI streaming
A2UI✅ Data model/surface❌✅ Action events✅ Agent→UI streaming
MCP Apps✅ Via postMessage❌✅ Tool calls❌ Req/response
json-render✅ Via local handlers✅ Via local handlers✅ Actions (to local handlers)❌
Open GenUI❌❌❌❌

Takeaway: The richer the bidirectional model, the more the agent can reason about and react to current UI state.

How They Relate

Not a strict stack. Complementary protocols with different transports.

How They Relate

Complementary, not competing. A single app can use multiple.

Two Orthogonal Decisions

Decision 1: Wire Protocol

How do you connect agent ↔ UI?

SituationChoice
Custom agentic frontendAG-UI
MCP host (Claude, VS Code)MCP
Multi-agent, sub-agent UIA2A
Simple, no frameworkRaw SSE

Decision 2: UI Rendering

What does the agent show?

SituationChoice
Branded, recurring flowsControlled
Cross-platform, long-tailA2UI
Design-system-safejson-render
Don't own the clientMCP Apps
Throwaway visualizationsOpen GenUI

Independent choices. AG-UI + A2UI, or MCP + MCP Apps, or AG-UI + Open GenUI. Mix and match.

The Future

Hybrid Apps

Controlled for critical flows + Open-ended for exploration

Agent Steering

Human-in-the-loop via AG-UI interrupts

Platform Convergence

A2UI growing: React, Angular, Flutter, SwiftUI

MCP Apps Expanding

More hosts adopting the standard