Skip to main content
AG-UI is CopilotKit’s open protocol for connecting AI agents to user interfaces over Server-Sent Events. AGUIAdapter wraps any Vibes agent and serves it as an AG-UI-compatible HTTP endpoint. CopilotKit frontends using useCoAgent connect directly to this endpoint.
Migrating from older docs? Two API bugs existed in previous versions of this documentation:
  1. The depsFactory option does not exist on AGUIAdapterOptions. Use deps instead.
  2. handleRequest() does not accept a Request object. It accepts an AGUIRunInput object. For Deno HTTP servers, use adapter.handler() which parses the request body for you.
See the corrected API below.

Architecture

Setup

Install @vibesjs/sdk and import AGUIAdapter:

Constructor

AGUIAdapterOptions fields:

Deno HTTP server

One line connects your adapter to a Deno HTTP server:
adapter.handler() returns a standard Deno HTTP handler. It parses the JSON body from POST requests into AGUIRunInput and calls handleRequest().

AGUIRunInput

The shape of the input object that handleRequest() receives (after handler() parses the HTTP body):

Direct handleRequest() usage

Call handleRequest() directly when you parse the request body yourself:

SSE event sequence

Every agent run emits a fixed sequence of SSE events. Understanding the sequence helps you build reliable frontend state machines. On error, RUN_ERROR is emitted instead of RUN_FINISHED.

Multi-turn conversations

Pass the message history from a previous result to continue a conversation across turns:

State management

Use getState to expose a snapshot of server-side state to the frontend on every run. The adapter calls getState at the start and end of each run and emits STATE_SNAPSHOT events.
The frontend receives the state in STATE_SNAPSHOT events and can render it via CopilotKit’s useCoAgentStateRender hook.

Event types reference

All 15 event types emitted by AGUIAdapter:

API reference

AGUIAdapterOptions

AGUIAdapter

AGUIRunInput