Skip to content

feat: AG-UI protocol support, step 5 (multimodal content parts) #5133

Description

@deka

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-ui at 5134ca20; the draft has the same text):
    • Run input › messages. UserMessage.content and ToolMessage.content are a string or an ordered list of ContentPart: text, image, audio, video, document.
    • A media part has a source, one of three kinds:
      • data: base64 value, mimeType required;
      • url: value, optional mimeType. The JS SDK guide says "HTTP(S) or data URL";
      • file: a provider file handle. Its value is opaque and a peer MUST NOT fetch it, parse it or read a scheme out of it.
    • Every part has an optional id and metadata.
    • 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: InputContent is renamed ContentPart and the wire is unchanged. The legacy binary part is retired. The 1.0 Python SDK rejects it at RunAgentInput validation (docs/migrating-to-1-0.mdx). The TypeScript client only translates it on an incoming stream.
  • Reference client: @ag-ui/client / @ag-ui/core 1.0.5, pinned in examples/ag-ui/replay/package-lock.json.
    • ContentPartSchema is a discriminated union of the five parts. PartSourceSchema is data | url | file.
    • Every object is a z.looseObject, so unknown fields pass through.
    • There is no binary member.
  • AG-UI Go SDK (pinned v0.0.0-20261204081916-54e41f736aa7):
    • types.InputContent{Type, Text, MimeType, ID, URL, Data, Filename, Source, Metadata} and InputContentSource{Type, Value, MimeType}. It has no provider field and no file constant, but a file source still decodes.
    • It still knows the legacy binary type and the mime_type spelling.
    • Message.Content is any, 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 decodes data: 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_modalities transform (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).
  • 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 chat and serve api already have --max-request-size (default 32 MiB).
    • The translator already queues warnings that it sends as CUSTOM docker-agent.warning once 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 url or file source, 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.

Protocol flow

  1. The client sends a user message whose content is 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"}}
    ]}
  2. The server validates the shape of every part of the new messages (see Input validation), before any session change.
  3. Each part is then used or skipped:
    • Used:

      • a data source;
      • a url source whose value is a data: 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.

    • Skipped: an http(s) or other url source, a file source, 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 promptAudioMIME refuses.

      A skipped part becomes the text [Attachment: <kind> <n> (content unavailable)] in the prompt, and the run gets a docker-agent.warning naming the part's index, kind and reason category. A file handle's value and a URL are never echoed.

  4. The prompt is stored as one session user message: the text joined as today, and the used parts as document parts, in wire order. The run proceeds.
  5. When the model of the agent that answers lacks a modality, the runtime's strip_unsupported_modalities transform 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 id the 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 nextPrompt rebuilds a retry from the stored text only, so this needs a change.
  • Hooks:
    • user_prompt_submit receives the prompt text: the text parts 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-ui gets --max-request-size, with the default of serve chat and serve api (32 MiB) instead of the fixed 8 MiB. Over the limit, the response is still 413.
    • 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.go move to a shared package: bounded base64, promptDocument, promptAudioMIME, the image pixel bound and a data: URI decoder. Both servers use it, as pkg/elicitationform did 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:

  • content that is not a string or a list, and null entries in the list;
  • a part that is not an object;
  • an unknown type, including the retired binary (as the 1.0 Python SDK rejects it);
  • text that is not a string;
  • a media part without a source, or with a source that is not an object;
  • an unknown source.type;
  • a value that is missing or not a string;
  • a data source without mimeType, or with a mimeType that does not parse;
  • data that is not valid base64 (the schema leaves "rejecting one" to the decoder);
  • an encoded or decoded size over chat.MaxInlineBinarySize for one part;
  • a data: URI in a url source 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 url sources (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 file handles to the provider. chat.Document has no handle source, and handles are provider-specific.
  • Warning when the model drops a modality (strip_unsupported_modalities only logs at debug level). It is listed under Current limitations.
  • Media in assistant output: AG-UI 1.0 defines none.
  • Advertising multimodal.input through 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-turn tool messages; image-only messages accepted.
  • Used parts stored as session document parts (user) or tool result MultiContent (tool), in wire order across a batch.
  • Skipped parts: placeholder text and a docker-agent.warning through the translator's existing warning queue.
  • Retry of a prompt with no output keeps the stored attachments (nextPrompt).
  • --max-request-size for serve 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, a file handle, 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 a url source 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_submit receives 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 binary part, null part, missing source, unknown source.type;
    • data without mimeType, bad base64, oversize part, bad data: URI.
  • Body over --max-request-size → 413, chunked body included.
  • Interop:
    • replay through @ag-ui/client 1.0.5. The client builds the multimodal message; the replay does not hand-write it;
    • Go SDK client test as in previous steps;
    • -race.

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-size for serve ag-ui.
  • Demo page (examples/ag-ui/index.html): attach an image.

Follow-up to #5119 (step 4), under #5066.

Activity

  1. added
    area/api
    area/sessions
    area/cli
    area/docs
    on Dec 5, 2026
  2. changed the issue type fromtoon Dec 5, 2026
  3. changed the issue type fromtoon Dec 5, 2026
  4. deka commented on Dec 5, 2026

    @deka
    ContributorAuthor

    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 main and opened here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/apiarea/cliarea/docsarea/sessions

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions