AG-UI Protocol
Overview
The docker agent serve ag-ui command starts an HTTP server that speaks the
server side of the AG-UI protocol. An application
sends a RunAgentInput and receives the run as a stream of AG-UI events over
Server-Sent Events (SSE): assistant text, reasoning, tool calls and their
results, and the agent of a team that is currently working.
Any AG-UI client can talk to the agent, whatever its language: the AG-UI client SDKs exist for TypeScript, Python, Go and more. You don't write protocol code.
This release covers a streaming chat. Human-in-the-loop, frontend tools, shared state and attachments are not implemented yet. See Current limitations.
Usage
# Start an AG-UI server for an agent
$ docker agent serve ag-ui ./agent.yaml
Listening on 127.0.0.1:8084
AG-UI endpoint: http://127.0.0.1:8084/ag-ui
# Pick one agent of a team as the entry point
$ docker agent serve ag-ui ./team.yaml --agent reviewer
# Use an agent from an OCI registry, on another address
$ docker agent serve ag-ui myorg/agent:tag --listen 127.0.0.1:9090
Flags
See the CLI reference for all flags, defaults, and shared runtime options.
Endpoint
| Method | Path | Description |
|---|---|---|
POST |
/ag-ui |
Takes a RunAgentInput JSON body and answers with text/event-stream |
$ curl -N http://127.0.0.1:8084/ag-ui \
-H 'Content-Type: application/json' \
-d '{
"threadId": "thread-1",
"runId": "run-1",
"messages": [{"id": "msg-1", "role": "user", "content": "Hello"}],
"tools": [], "context": [], "state": {}, "forwardedProps": {}
}'
Each event is one SSE frame. Its data line is the AG-UI event as JSON:
id: RUN_STARTED_1764345600000
data: {"type":"RUN_STARTED","timestamp":1764345600000,"threadId":"thread-1","runId":"run-1"}
id: TEXT_MESSAGE_START_1764345600120
data: {"type":"TEXT_MESSAGE_START","timestamp":1764345600120,"messageId":"56738741-aa2b-4dba-a1be-7f0e005043ce","role":"assistant"}
id: TEXT_MESSAGE_CONTENT_1764345600121
data: {"type":"TEXT_MESSAGE_CONTENT","timestamp":1764345600121,"messageId":"56738741-aa2b-4dba-a1be-7f0e005043ce","delta":"Hello!"}
id: TEXT_MESSAGE_END_1764345600300
data: {"type":"TEXT_MESSAGE_END","timestamp":1764345600300,"messageId":"56738741-aa2b-4dba-a1be-7f0e005043ce"}
id: RUN_FINISHED_1764345600301
data: {"type":"RUN_FINISHED","timestamp":1764345600301,"threadId":"thread-1","runId":"run-1"}
Use an AG-UI client SDK
With the TypeScript client (npm install @ag-ui/client):
import { HttpAgent } from "@ag-ui/client";
const agent = new HttpAgent({
url: "http://127.0.0.1:8084/ag-ui",
threadId: "thread-1",
});
agent.messages = [{ id: "msg-1", role: "user", content: "Hello" }];
await agent.runAgent({}, {
onTextMessageContentEvent: ({ event }) => process.stdout.write(event.delta),
});
Threads and sessions
Each AG-UI thread is a Docker Agent session.
- An unknown
threadIdcreates a session; a known one resumes it. Sessions are stored in the session database (--session-db), so a thread survives a server restart. - The session ID is
ag-ui-followed by the SHA-256 of thethreadId, in hexadecimal. The session ID names files and directories, and twothreadIds that differ only by case must not share them on a case-insensitive filesystem. Events carry thethreadIdthe client sent. - The server-side session is the source of truth. AG-UI clients resend the
whole conversation on every run. The server reads only the user messages
that end
messagesand ignores the rest of that history, including system, assistant and tool messages. - A user message is identified by its
id. Among the user messages that endmessages, those up to the last one the thread already holds are history; the ones after it are new. - The new user messages make the prompt of the run. Several of them are joined
into one prompt, separated by a blank line, so
user_prompt_submithooks check all the text before any of it reaches the model. The thread remembers theidof each of them (session attributeag-ui.batches), so any of them resent later is history. - A prompt a hook blocked stays in the thread but never reaches the model: later runs leave it out of the history they send.
- A run needs something to answer: a request without a new user message is
rejected with
400 Bad Request(no new user message for this thread). The exception is a thread that still ends on a prompt, because its last run stored no output (it failed, or a hook blocked the prompt): resending the same messages submits that prompt again. It goes through theuser_prompt_submithooks again, and the thread keeps both submissions. A run that failed after storing output (for example after a tool call) is not retried this way; send a new user message. - Only one run at a time per thread. A run on a thread that already has a run
in progress is rejected with
409 Conflict. - A thread never resumes a session created another way (the TUI, the API
server, A2A), even when its
threadIdis that session's ID. If the session ID derived from athreadIdis already taken by such a session, the request is rejected with409 Conflictand that session is left untouched. - Closing the connection cancels the run.
Before each resumed run, Docker Agent reapplies the selected agent's
max_iterations, max_consecutive_tool_calls, max_old_tool_call_tokens and
max_tool_result_tokens. The safety policy of a thread is preserved or
tightened to the server's policy, never relaxed.
Event mapping
| Docker Agent runtime event | AG-UI event |
|---|---|
| Run started / stopped | RUN_STARTED / RUN_FINISHED |
| Failed, canceled or cut-short run | RUN_ERROR |
| Assistant text | TEXT_MESSAGE_START / TEXT_MESSAGE_CONTENT / TEXT_MESSAGE_END |
| Reasoning | REASONING_START / REASONING_MESSAGE_START / REASONING_MESSAGE_CONTENT / REASONING_MESSAGE_END / REASONING_END |
| Tool call being streamed by the model | TOOL_CALL_START / TOOL_CALL_ARGS |
| Tool call dispatched / tool result | TOOL_CALL_END / TOOL_CALL_RESULT |
| Hand-over to a sub-agent and back | STEP_STARTED / STEP_FINISHED (stepName is the agent name) |
| Token usage, warning, session title, model fallback | CUSTOM |
Notes:
- Tools run on the server. Tool events show progress; the client is not asked to execute anything.
- The server ends every message, tool call and step it started before
RUN_FINISHEDorRUN_ERROR. Nothing follows either of them. - Every tool call has a
TOOL_CALL_RESULTbeforeRUN_FINISHED, so a client finds no pending call. A call the model started and a provider fallback then withdrew was never executed: its result is(retracted: the call was not executed). - A
toolCallIdnames one call within the run. Models whose tool calls are parsed from text reuse IDs from one turn to the next (call_0): a reused ID gets a suffix (call_0-2). RUN_FINISHEDmeans the run completed normally. A run that was cut short ends withRUN_ERROR, whosecodeis:canceledfor a run canceled on the server. A client that disconnects cancels its run and receives nothing more.- the runtime error code when the runtime reported one;
- the reason the run was stopped:
max_iterations,budget_exceeded,hook_blockedorloop_detected; lengthwhen the model reached its output token limit: the answer streamed so far is incomplete;refusalwhen the model refused to answer;run_failedotherwise.
CUSTOMevents are nameddocker-agent.token_usage,docker-agent.warning,docker-agent.session_title,docker-agent.model_fallbackanddocker-agent.error. Theirvalueis the runtime event, in the format of the API server.docker-agent.errorreports an error the run recovered from; it is sent just beforeRUN_FINISHED.
Input validation
The request is validated before anything is stored or run. An invalid request
gets 400 Bad Request with a JSON body, {"error": "<reason>"}, and changes
nothing: the same threadId still accepts a valid request.
| Field | Rule |
|---|---|
threadId |
Required, at most 256 bytes. Starts with a letter or digit and contains only letters, digits, ., _ and - (a UUID qualifies). |
runId |
Required, at most 256 bytes. |
messages |
Every message needs an id of at most 256 bytes and a known role. The history must end with at least one user message; those trailing user messages need distinct ids and non-empty text content (a string, or a list of text parts). The content of earlier messages is not read. |
tools |
Must be empty: frontend tools are not supported. |
state |
Must be empty (null, {}): shared state is not supported. |
resume |
Must be empty: interrupts are not supported. |
context, forwardedProps |
Accepted and ignored. |
tools, state and resume are rejected rather than silently ignored, so a
client finds out immediately that a feature it relies on is missing.
Other responses:
| Status | When |
|---|---|
401 |
--auth-token is set and the bearer token is missing or wrong. |
403 |
No --auth-token, loopback listener, and the Host header is not a loopback name. |
409 |
The thread has a run in progress, or its session ID is taken by another kind of session. |
413 |
The request body is larger than 8 MiB. |
415 |
Content-Type is not application/json. |
503 |
The server is shutting down. |
Shutdown and restart
When the server is stopped it rejects new runs with 503, closes the client
connections, cancels the runs in progress and waits up to 10 seconds for them
to stop, including the background agents of finished runs, which are stopped
once their run ends. A run that has not stopped by then (typically a tool that
ignores cancellation) is abandoned: the process exits without it.
- A client whose run was interrupted sees its stream end without
RUN_FINISHEDorRUN_ERROR. Treat a stream that ends that way as a failed run. - Runs are not resumed at startup. The thread keeps what was stored before the interruption; output an abandoned run produced after that point is lost.
- After a restart the thread accepts a new run. Send a new user message, or resend the same messages if the interrupted run had stored no output yet (see Threads and sessions).
Authentication and network exposure
Loopback listeners may run without authentication. Non-loopback listeners
require --auth-token. Clients must send Authorization: Bearer <token>.
--insecure-no-auth lifts that requirement: anyone who can reach the address
can then start runs, and their tools execute on the server under its
tool safety policy. Use it only on a network you trust.
Two checks protect a server from web pages the user visits:
- Requests must be sent with
Content-Type: application/json. A browser only sends that header cross-origin after a CORS preflight, which fails unless the page's origin is allowed. - A loopback listener without
--auth-tokenonly accepts a loopbackHost(localhost,127.0.0.1,[::1]), which stops DNS-rebinding pages.
Browser access is off by default. Enable it with --cors-origin; it accepts
comma-separated literal origins or ~-prefixed regular expressions. Allowed
origins may send the Authorization, Content-Type and Accept headers.
Preflight requests are answered without credentials. On a loopback listener
without --auth-token, any page served from an allowed origin can start runs.
$ docker agent serve ag-ui ./agent.yaml --auth-token "$AG_UI_TOKEN" \
--cors-origin http://localhost:3000
Tool safety
AG-UI threads default to the restricted tool safety policy. Precedence is the
--safety flag, then agent YAML, then runtime YAML. YAML may select strict,
balanced, or restricted; --safety autonomous is the only way to opt in to
autonomous tool execution.
Nobody can approve a tool call over AG-UI yet. A tool call that the policy does not allow is denied, and the agent is told so. An elicitation request from an MCP server is declined.
Current limitations
- No human-in-the-loop. Tool approval and elicitation through AG-UI
interrupts are not implemented (
resumeis rejected). - No frontend tools. A non-empty
toolsfield is rejected. - No shared state.
STATE_SNAPSHOTandSTATE_DELTAare never sent, and a non-emptystateis rejected. - Text only. Images and other attachments in user messages are rejected.
- One entry agent per server. Use
--agentto choose it; sub-agents are reached through delegation.
For OpenAI-compatible clients, see Chat Server. For agent-to-agent communication, see A2A. For full control over sessions and runtime events, see API Server.