Why Generative UI Matters for AI Agents
AI agents have evolved from text-only chatbots to complex assistants that plan trips, book flights, and manage workflows. But until recently, the user experience remained stuck in a wall of text. When a user asked for holiday packages, the agent responded with prose — no maps, no date pickers, no selectable lists.
Generative UI changes this by letting agents build interfaces at runtime, shaped by each request. Instead of dumping text, the agent composes interactive components — cards, forms, maps — that users can actually click, fill, and submit.
The challenge? You need two pieces:
- A standard way to describe the UI (so agents can declare intent).
- An agentic stack that connects your agent to your application and renders that UI.
This tutorial walks through building a generative UI app using A2UI (a framework-agnostic standard for declaring UI intent) and CopilotKit (built on the AG-UI protocol). We'll use Google ADK as the agent backend, but the pattern works with LangChain, Mastra, Strands, and other AG-UI-compatible frameworks.
For a broader look at how AI features scale in production, see our analysis of how Spotify generated 1.4 billion personalized stories.

Step-by-Step: Wiring A2UI with CopilotKit
Step 1: Set Up Your Agent Backend (Google ADK Example)
The ag_ui_adk package wraps any ADK agent and serves it as an AG-UI endpoint on FastAPI:
# main.py — FastAPI backend exposing the ADK agent via AG-UI
from fastapi import FastAPI
from google.adk.agents import LlmAgent
from ag_ui_adk import ADKAgent, add_adk_fastapi_endpoint
root_agent = LlmAgent(
name="flight_agent",
model="gemini-3.8-flash",
instruction="Help users find and book flights. Call generate_a2ui to show results.",
)
adk_agent = ADKAgent(
adk_agent=root_agent,
app_name="flights",
user_id="demo_user",
use_in_memory_services=True,
)
app = FastAPI()
add_adk_fastapi_endpoint(app, adk_agent, path="/")
Step 2: Define Your Component Catalog (React/TypeScript)
On the client side, define which components the agent is allowed to render. Use Zod schemas for prop validation:
// catalog.ts — declare allowed components and map to renderers
import { CopilotKit, CopilotChat } from '@copilotkit/react-core/v2';
import {
createCatalog,
type CatalogDefinitions,
type CatalogRenderers,
} from '@copilotkit/a2ui-renderer';
import { z } from 'zod';
// Define the schema the agent must follow
const catalogDefinitions = {
FlightCard: {
description: 'A flight result with airline, times, and stops.',
props: z.object({
airline: z.string(),
departs: z.string(),
arrives: z.string(),
stops: z.number(),
}),
},
} satisfies CatalogDefinitions;
// Map schema names to your actual React components
const catalogRenderers = {
FlightCard: MyFlightCard, // your React component
} satisfies CatalogRenderers;
const catalog = createCatalog(catalogDefinitions, catalogRenderers, {
catalogId: 'flight-catalog',
includeBasicCatalog: true, // includes 18 general-purpose primitives
});
The description field goes directly into the agent's prompt, so the model knows when to use FlightCard instead of a generic card. The Zod schema validates props at runtime.
Step 3: Handle Bi-Directional Inputs (Multi-Step Flow)
For multi-step flows (e.g., booking), bind inputs to data paths and attach actions to buttons:
{
"id": "cabin",
"component": "ChoicePicker",
"variant": "mutuallyExclusive",
"options": [
{ "label": "Economy", "value": "eco" },
{ "label": "Business", "value": "biz" }
],
"value": { "path": "/booking/cabin" }
},
{
"id": "confirm",
"component": "Button",
"child": "confirm_label",
"action": {
"event": {
"name": "confirmBooking",
"context": {
"cabin": { "path": "/booking/cabin" },
"email": { "path": "/booking/email" }
}
}
}
}
Validation runs on the client, so a bad email shows an inline error without a model call. Nothing reaches the agent until the button fires. Then the client sends the bound values, and the agent re-emits against the same surfaceId — keeping the whole flow on one surface.
Step 4: Scaffold a Starter App
npx copilotkit@latest create --name my-app --framework a2ui
This creates a starter A2UI application with CopilotKit Agent integration, ready to run.

Critical Considerations and Limitations
Not a silver bullet. A2UI is deliberately sparse — the Basic Catalog ships only 18 primitives. Most production apps will need to define a custom catalog, which means you must map every component you want the agent to render. This is upfront work.
Security surface. At the open end of the spectrum, agents can return raw UI code (HTML/JS/Dart) that renders inside a sandboxed iframe. That's powerful but risky — you're executing code a model wrote. The declarative mode (pre-declared components) is safer and more popular for production.
Design system drift. Allowing agents to compose arbitrary UIs can break brand consistency. The controlled end (predefined components) is brand-safe but limits personalization. Choose your point on the spectrum deliberately.
One-shot vs. reactive. Most agent-generated UI is one-shot — the agent draws, you read, it goes stale. A2UI surfaces are bi-directional and reactive, which enables multi-step flows, but you must explicitly bind inputs to data paths and define actions. This is not automatic.
Framework lock-in (mild). A2UI is framework-agnostic, but the CopilotKit path is React-first. Flutter, Lit, and Angular renderers exist (@a2ui/react, Flutter, Lit, Angular equivalents), but the ecosystem is less mature outside React.
Next Steps for Learning
- Explore the CopilotKit Dojo — runnable A2UI demos including fixed server-side schema, dynamic schema against a custom catalog, and an error-recovery example where an invalid first render heals into a valid one.
- Try the open-ended mode — experiment with raw UI code generation in a sandboxed iframe to understand the trade-offs.
- Integrate with your existing design system — map your component library to A2UI catalog definitions and test agent composition.
- Read the A2UI documentation — learn how to integrate A2UI with any framework of your choice.
If you're also interested in the infrastructure side of agentic AI, check out our piece on NVIDIA BlueField-4 and scale-in for AI factories.

Conclusion
Generative UI is the layer that turns text-based agents into interactive applications. A2UI gives you a framework-agnostic standard for declaring UI intent, and CopilotKit (built on AG-UI) gives you the stack to render it. The pattern is straightforward: define your catalog once, let the agent compose components per request, and bind inputs to data paths for multi-step flows.
Start with the declarative mode (pre-declared components) for brand safety, and only move toward open-ended code generation when you truly need it. The upfront work of mapping your component catalog pays off in every subsequent agent interaction.