Repository navigation
Description
Summary
Step 5 of AG-UI protocol support (see #5066; step 1 in #5067, step 2 in #5087 / #5091, step 3 in #5102 / #5103, step 4 in #5119). Accept multimodal content parts: images, audio, video and documents in user messages, and in the tool messages that answer frontend tool calls.
Today docker agent serve ag-ui rejects any non-text part with 400 (pkg/agui/input.go, contentText: "only text content is supported"; Current limitations: "Text only"). AG-UI 1.0 has a rule against this: a producer that cannot use a content part MUST NOT fail the run because of it. With this step, the server passes the parts it can use to the agent's model. It skips the others, tells the model and the client so, and runs anyway.
Background: what already exists
- AG-UI spec 1.0 (
ag-ui-protocol/ag-uiat5134ca20; the draft has the same text):- Run input › messages.
UserMessage.contentandToolMessage.contentare a string or an ordered list ofContentPart:text,image,audio,video,document. - A media part has a
source, one of three kinds:data: base64value,mimeTyperequired;url:value, optionalmimeType. The JS SDK guide says "HTTP(S) or data URL";file: a provider file handle. Itsvalueis opaque and a peer MUST NOT fetch it, parse it or read a scheme out of it.
- Every part has an optional
idandmetadata. - Two behavioural rules:
- a producer that cannot use a part MUST NOT fail the run: it skips the part and continues;
- a handle it cannot resolve is skipped, and it SHOULD say so.
- Changelog 1.0, item 10:
InputContentis renamedContentPartand the wire is unchanged. The legacybinarypart is retired. The 1.0 Python SDK rejects it atRunAgentInputvalidation (docs/migrating-to-1-0.mdx). The TypeScript client only translates it on an incoming stream.
- Run input › messages.
- Reference client:
@ag-ui/client/@ag-ui/core1.0.5, pinned inexamples/ag-ui/replay/package-lock.json.ContentPartSchemais a discriminated union of the five parts.PartSourceSchemaisdata | url | file.- Every object is a
z.looseObject, so unknown fields pass through. - There is no
binarymember.
- AG-UI Go SDK (pinned
v0.0.0-20261204081916-54e41f736aa7):types.InputContent{Type, Text, MimeType, ID, URL, Data, Filename, Source, Metadata}andInputContentSource{Type, Value, MimeType}. It has noproviderfield and nofileconstant, but afilesource still decodes.- It still knows the legacy
binarytype and themime_typespelling. Message.Contentisany, and the server reads the raw JSON as it does today.- No SDK bump needed.
- Runtime:
- Attachments are
chat.MessagePart{Type: document, Document}with inline bytes (DocumentSource.InlineData) or inline text (InlineText), stored in the session (session.UserMessage(content, multiContent...)). chat.ProcessAttachmentWithMetadata(pkg/chat/attach.go) resizes and transcodes images. It decodesdata:URIs and refuses remote URLs ("download the file locally first").- Providers convert documents per model capability (
attachment.Decide). An unsupported MIME is dropped with a log line. - The
strip_unsupported_modalitiestransform (pkg/runtime/strip_modalities.go) drops the image, audio and video parts that the current model does not support, at debug level and with no event. - Tool results carry media through
MultiContent(chat.BuildToolResultMultiContent).
- Attachments are
- ACP already turns client-supplied inline media into session attachments (
pkg/acp/content.go). The helpers to reuse rather than reinvent:decodePromptData: bounded base64;promptDocument: MIME parsing, text vs binary, UTF-8 checks, an image pixel bound (maxPromptImagePixels) and the resize;promptAudioMIME;- the placeholder text when content is unavailable (
[Attachment: <name> (content unavailable)]).
- AG-UI server:
maxRequestBytes = 8 MiB(pkg/agui/server.go). The reference client resends the whole history on every run, base64 included, although the server reads only the trailing user messages and the last turn's tool messages.serve chatandserve apialready have--max-request-size(default 32 MiB).- The translator already queues warnings that it sends as
CUSTOMdocker-agent.warningonce the run starts (pkg/agui/translator.go).
Threat model
- Caller: an AG-UI client authenticated by
--auth-token(or a loopback caller). It already owns the thread and can send any text to the model. - What this step must keep:
- No outbound fetch. The server never dereferences a client-supplied
urlorfilesource, so there is no SSRF surface and no proxy or redirect handling. - No local file access. No
file://and no path is read from a part. - Bounded decoding: base64 size, decoded size, and image pixel count before allocation (decompression bombs).
- No content in logs: part bytes, text documents and URLs are never logged, at any level. A log line or a warning names the part's index, kind and a reason category only.
- Operator policy unchanged: hooks, deny rules and the safety policy apply as today.
- No outbound fetch. The server never dereferences a client-supplied
Protocol flow
- The client sends a user message whose
contentis a list of parts:{"id": "msg-1", "role": "user", "content": [ {"type": "text", "text": "What is wrong in this screenshot?"}, {"type": "image", "source": {"type": "data", "value": "<base64>", "mimeType": "image/png"}} ]} - The server validates the shape of every part of the new messages (see Input validation), before any session change.
- Each part is then used or skipped:
-
Used:
- a
datasource; - a
urlsource whose value is adata:URI.
Images are sniffed, bounded, resized and transcoded as over ACP. Text-like MIME types (
text/*, JSON, XML) become inline text. Other types become inline bytes. - a
-
Skipped: an
http(s)or otherurlsource, afilesource, or bytes that cannot be used:- an image that does not decode or is over the pixel bound;
- a text document that is not UTF-8;
- an audio MIME that
promptAudioMIMErefuses.
A skipped part becomes the text
[Attachment: <kind> <n> (content unavailable)]in the prompt, and the run gets adocker-agent.warningnaming the part's index, kind and reason category. Afilehandle's value and a URL are never echoed.
-
- The prompt is stored as one session user message: the text joined as today, and the used parts as
documentparts, in wire order. The run proceeds. - When the model of the agent that answers lacks a modality, the runtime's
strip_unsupported_modalitiestransform and the providers drop the part, as for the TUI. The spec allows it: "skipping what it cannot use and continuing is the conforming behaviour". It stays a debug log; see Out of scope.
Tool messages
A tool message answering a frontend tool call (step 4) may carry the same parts. Used parts are stored as the tool result's MultiContent, next to its text, and the same skip rules apply. Today such a message gets 400 ("only text content is supported").
Scope
- No opt-in flag. A client opts in by sending parts, and today those requests fail.
- Several new user messages in one run (a batch): their text is joined as today. Their parts keep wire order, message by message, in the single stored prompt.
- Image-only messages: a user message with no text but at least one media part is accepted. It is not "empty": a used part, or the placeholder of a skipped one, gives the model something to answer.
- History:
- A user message whose
idthe thread already holds is history. Its parts are shape-checked like today's text, but not processed (no image decode or resize, nothing stored). - A later run sends the stored attachments to the model from the session, not from the wire.
- A retried prompt (a thread that still ends on a prompt) resubmits the stored message, attachments included. Today
nextPromptrebuilds a retry from the stored text only, so this needs a change.
- A user message whose
- Hooks:
user_prompt_submitreceives the prompt text: thetextparts and the placeholders of skipped parts.- It does not receive attachment contents, text documents included. The TUI and ACP do the same; this is documented.
- A prompt a hook blocked keeps its attachments out of the model's history on later turns, as for its text.
- Request size:
serve ag-uigets--max-request-size, with the default ofserve chatandserve api(32 MiB) instead of the fixed 8 MiB. Over the limit, the response is still413.- The reference client resends all history, so a long thread with inline media eventually reaches the limit. The docs say so, and say that the server ignores the content of history messages.
- Refactor: the stateless helpers of
pkg/acp/content.gomove to a shared package: bounded base64,promptDocument,promptAudioMIME, the image pixel bound and adata:URI decoder. Both servers use it, aspkg/elicitationformdid in step 3. ACP behaviour is unchanged.
Input validation
All checks run at the protocol boundary, before any session change, on the trailing user messages and the last turn's tool messages only (the content of earlier messages is still not read). Failures return 400 with {"error": …} and leave state unchanged. A valid retry still works.
Shape errors → 400. The request does not match the 1.0 ContentPart schema:
contentthat is not a string or a list, andnullentries in the list;- a part that is not an object;
- an unknown
type, including the retiredbinary(as the 1.0 Python SDK rejects it); textthat is not a string;- a media part without a
source, or with asourcethat is not an object; - an unknown
source.type; - a
valuethat is missing or not a string; - a
datasource withoutmimeType, or with amimeTypethat does not parse; datathat is not valid base64 (the schema leaves "rejecting one" to the decoder);- an encoded or decoded size over
chat.MaxInlineBinarySizefor one part; - a
data:URI in aurlsource that does not parse.
Accepted and ignored: a part's id and metadata, and unknown fields on parts and sources (the reference client's schemas are looseObject).
Skipped with a warning, never 400: everything the spec's "cannot use" rule covers. See Protocol flow, step 3.
Out of scope
- Fetching
urlsources (http(s)). This needs the outbound-HTTP rules: registration checks, dial-time SSRF guard, proxies, redirects and redacted logging. It can be a later opt-in step. - Passing
filehandles to the provider.chat.Documenthas no handle source, and handles are provider-specific. - Warning when the model drops a modality (
strip_unsupported_modalitiesonly logs at debug level). It is listed under Current limitations. - Media in assistant output: AG-UI 1.0 defines none.
- Advertising
multimodal.inputthrough AG-UI capabilities. MESSAGES_SNAPSHOT, shared state.
AG-UI spec conformance
Checked against spec 1.0 at 5134ca20 and @ag-ui/client / @ag-ui/core 1.0.5:
| Rule | Plan |
|---|---|
User and tool message content is a string or an ordered list of ContentPart |
yes, both roles |
Parts: text, image, audio, video, document |
yes; anything else 400 |
data source: base64, mimeType required, a malformed string is the decoder's to reject |
yes, 400 |
url source: "HTTP(S) or data URL" |
data: used; http(s) skipped with a warning, never fetched |
file source: MUST NOT fetch, parse or read a scheme out of it |
not fetched, parsed or logged; skipped with a warning |
| A handle the producer cannot resolve: skip, continue, SHOULD say so | yes, docker-agent.warning |
| A producer that cannot use a part MUST NOT fail the run | skipped parts, undecodable media and unsupported modalities never fail the run |
binary part retired in 1.0 |
400, as the 1.0 Python SDK |
Part id and metadata optional, not read |
accepted, ignored |
| Unknown fields (reference schemas are loose) | accepted, ignored |
Deliverables
- Shared attachment helpers extracted from
pkg/acp/content.go; ACP unchanged. -
decodeRunInput: content parts decoded and validated for new user messages and last-turntoolmessages; image-only messages accepted. - Used parts stored as session
documentparts (user) or tool resultMultiContent(tool), in wire order across a batch. - Skipped parts: placeholder text and a
docker-agent.warningthrough the translator's existing warning queue. - Retry of a prompt with no output keeps the stored attachments (
nextPrompt). -
--max-request-sizeforserve ag-ui(default 32 MiB). - No part content, text document or URL in any log.
Testing
- Exact AG-UI event sequence, and the model request through a real
LocalRuntime, for:- text and image;
- image only;
- a PDF;
- a text document;
- audio;
- a batch of two user messages with parts, in order.
- Skips: an
http(s)URL, afilehandle, an image that does not decode, an image over the pixel bound and non-UTF-8 text. For each, the run proceeds, the placeholder reaches the model and the warning reaches the client. The URL or handle appears in neither, nor in the logs. - A
data:URI in aurlsource is used. - Persistence: a later run, and a restarted server reached through its public API, send the stored attachment to the model. History parts resent on the wire are not processed or stored again.
- Retry of a prompt with no output resubmits its attachments.
- A hook-blocked prompt with an image: the image is absent from the next run's model request.
user_prompt_submitreceives the text only. - A frontend tool answered with an image: the next model request holds it in the tool result.
- Invalid input →
400, state unchanged, valid retry works. Sent as raw JSON on the wire:- unknown or
binarypart,nullpart, missingsource, unknownsource.type; datawithoutmimeType, bad base64, oversize part, baddata:URI.
- unknown or
- Body over
--max-request-size→413, chunked body included. - Interop:
- replay through
@ag-ui/client1.0.5. The client builds the multimodal message; the replay does not hand-write it; - Go SDK client test as in previous steps;
-race.
- replay through
Documentation
-
docs/features/ag-ui/index.md:- a new Attachments section: parts, sources, what is used, skipped or rejected, hooks, history and request size;
- update Input validation, Threads and sessions (image-only messages) and Current limitations ("Text only" goes; URL sources not fetched, file handles skipped, silent modality drop, history size).
-
docs/features/cli/index.md:--max-request-sizeforserve ag-ui. - Demo page (
examples/ag-ui/index.html): attach an image.
Activity
deka commentedon Dec 5, 2026
Implementation: la-fabrique#2 (draft). It is stacked on step 4 (#5122), so it stays a draft PR on the fork until step 4 is merged; it will then be rebased onto
mainand opened here.