Skip to content

AG-UI (Agent-User Interaction)

How the AG-UI protocol bridges AI agents and frontend applications, enabling real-time streaming of agent activity to user interfaces.


Modern AI systems communicate across three boundaries, each served by a dedicated protocol:

ProtocolConnectionPurpose
MCPAgent ↔ ToolsStructured tool discovery and execution
A2AAgent ↔ AgentsInter-agent task delegation and collaboration
AG-UIAgent ↔ FrontendsReal-time agent activity streaming to user interfaces

MCP gives agents access to tools. A2A lets agents collaborate with each other. AG-UI closes the loop by connecting agents to the humans who use them, providing a standard way for frontends to observe and interact with agent execution in real time.


Without AG-UI, every frontend that displays agent activity needs custom integration code: polling endpoints, proprietary WebSocket protocols, or framework-specific bindings. AG-UI standardizes this into a single request/response pattern:

  1. The frontend sends a RunAgentInput request describing the conversation state
  2. The server responds with a Server-Sent Events (SSE) stream of typed events
  3. The frontend renders events as they arrive — text tokens, tool calls, state changes, workflow steps

This decouples agent logic from UI rendering. Any AG-UI-compatible frontend can connect to any AG-UI-compatible backend.


The frontend sends a JSON payload describing the current conversation:

{
"threadId": "thread-abc123",
"runId": "run-xyz789",
"messages": [
{
"id": "msg-1",
"role": "user",
"content": "What is the status of order #1234?"
}
],
"tools": [],
"context": []
}

Key fields:

FieldDescription
threadIdIdentifies the conversation thread
runIdUnique identifier for this execution run
messagesConversation history in AG-UI message format
toolsFrontend-defined tools the agent can call
contextAdditional context values for the agent

The server responds with Content-Type: text/event-stream and emits a sequence of typed events:

data: {"type":"RUN_STARTED","threadId":"thread-abc123","runId":"run-xyz789"}
data: {"type":"TEXT_MESSAGE_START","messageId":"msg-2","role":"assistant"}
data: {"type":"TEXT_MESSAGE_CONTENT","messageId":"msg-2","delta":"Order #1234 is "}
data: {"type":"TEXT_MESSAGE_CONTENT","messageId":"msg-2","delta":"currently in transit."}
data: {"type":"TEXT_MESSAGE_END","messageId":"msg-2"}
data: {"type":"RUN_FINISHED","threadId":"thread-abc123","runId":"run-xyz789"}

AG-UI defines a rich set of event types covering the full lifecycle of an agent run:

EventDescription
RUN_STARTEDAgent run has begun
RUN_FINISHEDAgent run completed successfully
RUN_ERRORAgent run encountered an error
EventDescription
TEXT_MESSAGE_STARTNew assistant message beginning
TEXT_MESSAGE_CONTENTIncremental text token/chunk
TEXT_MESSAGE_ENDAssistant message complete
EventDescription
TOOL_CALL_STARTAgent is invoking a tool
TOOL_CALL_ARGSIncremental tool call arguments (streamed)
TOOL_CALL_ENDTool invocation complete
TOOL_CALL_RESULTResult returned from tool execution
EventDescription
STATE_SNAPSHOTFull state snapshot
STATE_DELTAIncremental state update (JSON Patch)
EventDescription
STEP_STARTEDWorkflow step has begun
STEP_FINISHEDWorkflow step completed

PromptKit provides the sdk/agui package as a bridge between SDK conversations and the AG-UI protocol. The integration follows a clear separation of concerns:

PromptKit provides:

  • Converters — bidirectional mapping between PromptKit messages/tools and AG-UI types
  • EventAdapter — observes a PromptKit conversation and emits AG-UI events

Your application provides:

  • HTTP endpoint — accepts RunAgentInput requests and writes SSE responses
  • Session management — maps thread IDs to PromptKit conversations

This design means PromptKit does not impose any HTTP framework or server architecture. The EventAdapter produces a channel of events; how you serve them is up to you.

When the EventAdapter observes a PromptKit conversation, it translates internal events to AG-UI events:

PromptKit ActivityAG-UI Event(s)
Send startsRUN_STARTED
Text response beginsTEXT_MESSAGE_START
Text token streamedTEXT_MESSAGE_CONTENT
Text response endsTEXT_MESSAGE_END
Tool call initiatedTOOL_CALL_STARTTOOL_CALL_ARGSTOOL_CALL_END
Tool result returnedTOOL_CALL_RESULT
Workflow step transitionSTEP_STARTED / STEP_FINISHED
Send completesRUN_FINISHED
Error occursRUN_ERROR

AG-UI frontends connect using standard HTTP. The official AG-UI client SDK provides HttpAgent for JavaScript/TypeScript applications:

import { HttpAgent } from "@ag-ui/client";
const agent = new HttpAgent({ url: "http://localhost:8080/ag-ui" });
agent.runAgent({
threadId: "thread-1",
runId: "run-1",
messages: [{ id: "msg-1", role: "human", content: "Hello" }],
tools: [],
context: [],
});

Any HTTP client that can consume SSE streams works with AG-UI — the protocol is not tied to any specific frontend framework.