AG-UI — Agent-User Interaction Protocol
You are an expert in AG-UI (Agent-User Interaction Protocol), the open standard by CopilotKit for connecting AI agents to frontend UIs. You help developers stream agent actions, tool calls, state updates, and text generation to React components in real-time — enabling rich agent UIs where users see what the agent is thinking, doing, and can intervene at any step.
Core Capabilities
AG-UI Server (Agent Events)
// server/agent.ts — Stream agent events to UI
import { AgentServer, EventStream } from "@ag-ui/server";
const server = new AgentServer();
server.onRequest(async (request, stream: EventStream) => {
const { messages, context } = request;
// Emit thinking state
stream.emitStateUpdate({ status: "thinking", progress: 0 });
// Stream text generation
stream.emitTextStart();
for (const word of "I'll analyze your data now.".split(" ")) {
stream.emitTextDelta(word + " ");
await sleep(50);
}
stream.emitTextEnd();
// Emit tool call
stream.emitToolCallStart("search_database", { query: context.userQuery });
const results = await searchDatabase(context.userQuery);
stream.emitToolCallEnd("search_database", results);
stream.emitStateUpdate({ status: "analyzing", progress: 50 });
// Stream analysis
stream.emitTextStart();
const analysis = await generateAnalysis(results);
for await (const chunk of analysis) {
stream.emitTextDelta(chunk);
}
stream.emitTextEnd();
// Custom state for UI rendering
stream.emitStateUpdate({
status: "complete",
progress: 100,
charts: [{ type: "bar", data: results.chartData }],
suggestions: ["Run deeper analysis", "Export to CSV", "Schedule report"],
});
stream.end();
});
AG-UI React Client
import { useAgent, AgentProvider } from "@ag-ui/react";
function App() {
return (
<AgentProvider url="https://api.example.com/agent">
<AgentChat />
</AgentProvider>
);
}
function AgentChat() {
const { messages, state, sendMessage, isStreaming, toolCalls } = useAgent();
return (
<div className="flex flex-col h-screen">
{/* Agent state visualization */}
{state.status === "thinking" && (
<div className="bg-blue-50 p-3 rounded-lg animate-pulse">
🤔 Agent is thinking... ({state.progress}%)
<progress value={state.progress} max={100} />
</div>
)}
{/* Tool calls (show what agent is doing) */}
{toolCalls.map((tc) => (
<div key={tc.id} className="bg-gray-50 p-2 rounded text-sm">
🔧 <strong>{tc.name}</strong>: {tc.status === "running" ? "Working..." : "Done"}
{tc.result && <pre className="mt-1">{JSON.stringify(tc.result, null, 2)}</pre>}
</div>
))}
{/* Messages */}
{messages.map((msg) => (
<div key={msg.id} className={msg.role === "user" ? "text-right" : "text-left"}>
<p>{msg.content}</p>
</div>
))}
{/* Dynamic UI from agent state */}
{state.charts?.map((chart, i) => (
<Chart key={i} type={chart.type} data={chart.data} />
))}
{state.suggestions && (
<div className="flex gap-2">
{state.suggestions.map((s) => (
<button key={s} => sendMessage(s)} className="px-3 py-1 bg-blue-100 rounded">
{s}
</button>
))}
</div>
)}
{/* Input */}
<form => { e.preventDefault(); sendMessage(input); }}>
<input placeholder="Ask anything..." disabled={isStreaming} />
</form>
</div>
);
}
Installation
npm install @ag-ui/react @ag-ui/server
Best Practices
- State streaming — Emit state updates for progress, status, UI components; users see agent's thought process
- Tool call transparency — Show tool calls in real-time; builds trust, helps debugging
- Suggestions — Emit suggestion buttons after responses; guide users to next actions
- Custom UI — Use state updates to render charts, tables, forms; richer than plain text
- Human-in-the-loop — Emit confirmation requests before destructive actions; users approve or reject
- Progress tracking — Emit progress percentages for long tasks; prevent user anxiety
- Framework agnostic — AG-UI protocol works with any agent backend (LangGraph, CrewAI, custom)
- CopilotKit integration — AG-UI powers CopilotKit; use CopilotKit for higher-level React components
1---2name: ag-ui3description: >-4 You are an expert in AG-UI (Agent-User Interaction Protocol), the open5 standard by CopilotKit for connecting AI agents to frontend UIs. You help6 developers stream agent actions, tool calls, state updates, and text7 generation to React components in real-time — enabling rich agent UIs where8 users see what the agent is thinking, doing, and can intervene at any step.9license: Apache-2.010compatibility: ''11metadata:12 source: https://skillmd.com/skills/eliferjunior/ag-ui13 author: terminal-skills14 version: 1.0.015 category: AI & Machine Learning16 tags:17 - agent18 - ui19 - protocol20 - streaming21 - react22 - frontend23 - copilotkit24---2526# AG-UI — Agent-User Interaction Protocol2728You are an expert in AG-UI (Agent-User Interaction Protocol), the open standard by CopilotKit for connecting AI agents to frontend UIs. You help developers stream agent actions, tool calls, state updates, and text generation to React components in real-time — enabling rich agent UIs where users see what the agent is thinking, doing, and can intervene at any step.2930## Core Capabilities3132### AG-UI Server (Agent Events)3334```typescript35// server/agent.ts — Stream agent events to UI36import { AgentServer, EventStream } from "@ag-ui/server";3738const server = new AgentServer();3940server.onRequest(async (request, stream: EventStream) => {41 const { messages, context } = request;4243 // Emit thinking state44 stream.emitStateUpdate({ status: "thinking", progress: 0 });4546 // Stream text generation47 stream.emitTextStart();48 for (const word of "I'll analyze your data now.".split(" ")) {49 stream.emitTextDelta(word + " ");50 await sleep(50);51 }52 stream.emitTextEnd();5354 // Emit tool call55 stream.emitToolCallStart("search_database", { query: context.userQuery });56 const results = await searchDatabase(context.userQuery);57 stream.emitToolCallEnd("search_database", results);58 stream.emitStateUpdate({ status: "analyzing", progress: 50 });5960 // Stream analysis61 stream.emitTextStart();62 const analysis = await generateAnalysis(results);63 for await (const chunk of analysis) {64 stream.emitTextDelta(chunk);65 }66 stream.emitTextEnd();6768 // Custom state for UI rendering69 stream.emitStateUpdate({70 status: "complete",71 progress: 100,72 charts: [{ type: "bar", data: results.chartData }],73 suggestions: ["Run deeper analysis", "Export to CSV", "Schedule report"],74 });7576 stream.end();77});78```7980### AG-UI React Client8182```tsx83import { useAgent, AgentProvider } from "@ag-ui/react";8485function App() {86 return (87 <AgentProvider url="https://api.example.com/agent">88 <AgentChat />89 </AgentProvider>90 );91}9293function AgentChat() {94 const { messages, state, sendMessage, isStreaming, toolCalls } = useAgent();9596 return (97 <div className="flex flex-col h-screen">98 {/* Agent state visualization */}99 {state.status === "thinking" && (100 <div className="bg-blue-50 p-3 rounded-lg animate-pulse">101 🤔 Agent is thinking... ({state.progress}%)102 <progress value={state.progress} max={100} />103 </div>104 )}105106 {/* Tool calls (show what agent is doing) */}107 {toolCalls.map((tc) => (108 <div key={tc.id} className="bg-gray-50 p-2 rounded text-sm">109 🔧 <strong>{tc.name}</strong>: {tc.status === "running" ? "Working..." : "Done"}110 {tc.result && <pre className="mt-1">{JSON.stringify(tc.result, null, 2)}</pre>}111 </div>112 ))}113114 {/* Messages */}115 {messages.map((msg) => (116 <div key={msg.id} className={msg.role === "user" ? "text-right" : "text-left"}>117 <p>{msg.content}</p>118 </div>119 ))}120121 {/* Dynamic UI from agent state */}122 {state.charts?.map((chart, i) => (123 <Chart key={i} type={chart.type} data={chart.data} />124 ))}125126 {state.suggestions && (127 <div className="flex gap-2">128 {state.suggestions.map((s) => (129 <button key={s} onClick={() => sendMessage(s)} className="px-3 py-1 bg-blue-100 rounded">130 {s}131 </button>132 ))}133 </div>134 )}135136 {/* Input */}137 <form onSubmit={(e) => { e.preventDefault(); sendMessage(input); }}>138 <input placeholder="Ask anything..." disabled={isStreaming} />139 </form>140 </div>141 );142}143```144145## Installation146147```bash148npm install @ag-ui/react @ag-ui/server149```150151## Best Practices1521531. **State streaming** — Emit state updates for progress, status, UI components; users see agent's thought process1542. **Tool call transparency** — Show tool calls in real-time; builds trust, helps debugging1553. **Suggestions** — Emit suggestion buttons after responses; guide users to next actions1564. **Custom UI** — Use state updates to render charts, tables, forms; richer than plain text1575. **Human-in-the-loop** — Emit confirmation requests before destructive actions; users approve or reject1586. **Progress tracking** — Emit progress percentages for long tasks; prevent user anxiety1597. **Framework agnostic** — AG-UI protocol works with any agent backend (LangGraph, CrewAI, custom)1608. **CopilotKit integration** — AG-UI powers CopilotKit; use CopilotKit for higher-level React components