AGUIAdapter wraps any Vibes agent and serves it as an AG-UI-compatible HTTP endpoint. CopilotKit frontends using useCoAgent connect directly to this endpoint.
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 thathandleRequest() receives (after handler() parses the HTTP body):
Direct handleRequest() usage
CallhandleRequest() 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
UsegetState 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.
STATE_SNAPSHOT events and can render it via CopilotKit’s useCoAgentStateRender hook.
Event types reference
All 15 event types emitted byAGUIAdapter: