copilotkit-agui
Original:🇺🇸 English
Translated
Use when building custom agent backends, implementing the AG-UI protocol, debugging streaming issues, or understanding how agents communicate with frontends. Covers event types, SSE transport, AbstractAgent/HttpAgent patterns, state synchronization, tool calls, and human-in-the-loop flows.
56installs
Sourcecopilotkit/copilotkit
Added on
NPX Install
npx skill4agent add copilotkit/copilotkit copilotkit-aguiTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →AG-UI Protocol Skill
Overview
AG-UI (Agent-User Interaction) is CopilotKit's open event-based protocol for agent-to-UI communication. All agent-frontend interaction flows through typed events streamed over SSE (Server-Sent Events) or binary protobuf transport. Agents implement returning an RxJS , and the client SDK handles event application, state management, and message history.
AbstractAgent.run()Observable<BaseEvent>When to Use
- Building a custom agent backend that needs to speak AG-UI
- Implementing for a new framework integration
AbstractAgent.run() - Debugging why events aren't reaching the frontend or arriving malformed
- Understanding event ordering (lifecycle, text, tool calls, state)
- Working with state synchronization (snapshots vs JSON Patch deltas)
- Implementing human-in-the-loop interrupt/resume flows
- Troubleshooting SSE streaming or encoding issues
When NOT to Use
- For CopilotKit React hooks and frontend components, use
copilotkit-develop - For CopilotKit runtime setup and configuration, use
copilotkit-setup - For framework-specific integration guides (LangGraph, Mastra, CrewAI), use
copilotkit-integrations
Quick Reference
Event Families
| Family | Events | Purpose |
|---|---|---|
| Lifecycle | | Run boundaries and progress |
| Text | | Streaming text messages |
| Tool Calls | | Agent tool invocations |
| State | | State synchronization |
| Reasoning | | Chain-of-thought visibility |
| Activity | | Structured progress updates |
| Custom | | Extension points |
Convenience Chunk Events
TEXT_MESSAGE_CHUNKTOOL_CALL_CHUNKtransformChunksSSE Wire Format
Each event is a JSON object sent as an SSE data line:
data: {"type":"RUN_STARTED","threadId":"t1","runId":"r1"}\n\n
data: {"type":"TEXT_MESSAGE_START","messageId":"m1","role":"assistant"}\n\n
data: {"type":"TEXT_MESSAGE_CONTENT","messageId":"m1","delta":"Hello"}\n\n
data: {"type":"TEXT_MESSAGE_END","messageId":"m1"}\n\n
data: {"type":"RUN_FINISHED","threadId":"t1","runId":"r1"}\n\nPackages
| Package | npm | Purpose |
|---|---|---|
| Events, types, schemas | Protocol definition |
| AbstractAgent, HttpAgent, middleware, event application | Client SDK |
| EventEncoder (SSE + protobuf) | Server-side encoding |
Workflow: Building an AG-UI Backend
- Define your endpoint -- Accept POST with body, respond with
RunAgentInputtext/event-stream - Parse input -- Extract ,
threadId,runId,messages,tools,statefrom the request bodycontext - Emit events in order -- first, then content events, then
RUN_STARTEDorRUN_FINISHEDRUN_ERROR - Encode as SSE -- Use 's
@ag-ui/encoderor manually writeEventEncoder.encode()data: JSON\n\n - Handle tool results -- Client sends back; agent processes and continues
TOOL_CALL_RESULT
See for a complete working example.
references/building-agents.mdKey Protocol Rules
- Every run MUST start with and end with
RUN_STARTEDorRUN_FINISHEDRUN_ERROR - must be non-empty
TEXT_MESSAGE_CONTENT.delta - Tool call events are linked by
toolCallId - uses RFC 6902 JSON Patch operations
STATE_DELTA - Multiple sequential runs are supported -- each must complete before the next starts
- Messages accumulate across runs; state continues unless reset by
STATE_SNAPSHOT
References
- -- Complete event type reference with schemas and examples
references/protocol-spec.md - -- Step-by-step guide to building AG-UI backends
references/building-agents.md - -- ASCII sequence diagrams for common flows
references/event-flow-diagrams.md - -- @ag-ui/client API reference
references/client-sdk.md