Skip to content

[Bug]: AG-UI document input content is not supported — AguiMessageConverter throws "Unhandled InputContent type" #3392

Closed

Description

@xuchaoguo1983

Describe the bug

The AG-UI multimodal-messages spec defines document input content, but AguiMessageConverter.toContentBlock does not handle it. The branch is commented out ("AgentScope currently lacks a native DocumentBlock; falling back to DataBlock"), so a valid request that contains a document part throws:

IllegalStateException: Unhandled InputContent type: DocumentInputContent[...]

The whole run fails. A client cannot tell the difference between a malformed request and a valid spec feature that the converter skips.

Verified on 2.0.3 and on current main:
agentscope-extensions/agentscope-extensions-protocol/agentscope-extensions-agui/src/main/java/io/agentscope/core/agui/converter/AguiMessageConverter.java, toContentBlock, around line 335.

#551 (AG-UI multimodal messages) was closed as covering image/video/audio/document. However, the code that landed only handles image, audio and video.

To Reproduce

POST to an AG-UI endpoint with a user message whose content contains
{"type": "document", "source": {"type": "data", "value": "<base64>", "mimeType": "text/csv"}}.
The run fails with the exception above.

Expected behavior

One of the following:

  1. Convert document content to a block the agent can use. The commented-out code suggests DataBlock, which already exists in core.
  2. If documents are intentionally unsupported for now, reject them with a clear, documented protocol error (for example RUN_ERROR with a message saying document content is not supported), instead of an internal IllegalStateException.

The docs should also say which input content types are supported.

Context / why it matters

We build an assistant where users upload spreadsheets for the agent to process. The mainstream pattern is to upload the file, reference it by id, and let a tool place it in the code-execution sandbox. Today we have to work around the missing document support by sending a plain-text marker in the user message. With document support, or at least a defined rejection, clients could send a structured reference instead.

Environment

  • AgentScope Java 2.0.3 (agentscope-extensions-agui), also present on main
  • Spring Boot 4 / WebFlux AG-UI integration

Activity

  1. oss-maintainer commented on Oct 3, 2026

    @oss-maintainer
    Collaborator

    Issue Evaluation

    Category: bug | Status: Partially confirmed — the failure you hit is real, but the part that is a defect is narrower than "document content is unsupported".

    Verified against main (91550713). All line references below were checked in the current tree.

    Confirmed

    1. Your reproduction is correct. "document" is a registered Jackson subtype (InputContent.java:42-55) and DocumentInputContent deserializes fine, so the failure is in conversion, not parsing. AguiMessageConverter.toContentBlock handles text/image/audio/video; the DocumentInputContent → DataBlock branch is commented out (AguiMessageConverter.java:335-339) and line 340 throws IllegalStateException("Unhandled InputContent type: " + input).
    2. The exception escapes the adapter's own error mapping, so the client never gets a RUN_ERROR. In AguiAgentAdapter.run the conversion happens at AguiAgentAdapter.java:150-152, inside the Flux.defer supplier and before the .onErrorResume(error -> errorEvents(...)) operator is attached to the returned stream (AguiAgentAdapter.java:176-182). When the supplier itself throws, Reactor turns it into an onError signal on the outer flux — the resume handler is never installed, so errorEvents() / mapErrorCode() never run. That is a pity, because mapErrorCode already maps IllegalStateException → INVALID_INPUT_ERROR (AguiAgentAdapter.java:412-420); the clean error code you are asking for exists but is unreachable on this path.
    3. What the client actually receives violates the module's documented contract. Docs state "On errors, the adapter emits a RUN_ERROR" and that RUN_ERROR/RUN_FINISHED are mutually exclusive terminal events (docs/v2/en/integration/protocol/agui.md:85); AguiEvent.RunError's own javadoc calls Raw + RunFinished the legacy pattern it replaces (AguiEvent.java:1128). On the MVC path the escaped error lands in AguiMvcController hookOnError → sendErrorAndComplete (AguiMvcController.java:185-190, 313-331), which sends a legacy AguiEvent.Raw({error: …}) followed by RUN_FINISHED over HTTP 200 — no error code, no RUN_ERROR. The WebFlux starter likewise has no RUN_ERROR mapping for the run stream (AguiWebFluxHandler.java:144-197; its error stream builder emits Raw too, AguiWebFluxHandler.java:262-270). Malformed JSON by contrast returns HTTP 400 with Failed to parse request: … (AguiRestController.java:131-147), so as you said, a client can only tell the two apart by string-matching.
    4. The error message echoes your document bytes. + input stringifies the DocumentInputContent record, so the full base64 value ends up in the Raw error event sent to the client and in logger.error("Error during AG-UI run: {}", error.getMessage()) (AguiMvcController.java:186-188). For a file-upload endpoint that is both a log-volume problem and a content-leak problem — uploaded document bytes leave through the error channel into wherever logs are collected. We consider this the most urgent part of the report.
    5. The code contradicts itself on intent. DocumentInputContent's javadoc says it "Maps to AgentScope's DataBlock during conversion" (DocumentInputContent.java:30-31), while the converter rejects it.

    Not a bug: document input being unsupported is deliberate and already documented

    docs/v2/en/integration/protocol/agui.md:14 — "Multimodal input is supported, but document types are not supported yet" (and the ZH page says the same) — and two tests pin the current throw as intended behavior: AguiMessageConverterTest.testConvertDocumentInputContentIsRejectedForUrlSource / …ForDataSource, asserting an IllegalStateException whose message starts with Unhandled InputContent type: (lines 602-630). So your option 1 ("convert document to a usable block") is a feature decision rather than a fix.

    It is also not a small one. DataBlock exists and is valid on USER messages (agentscope-core/…/message/DataBlock.java, Msg.java:186-199), but provider support for non-image MIME types is inconsistent today:

    • OpenAI: logs a warning and substitutes a text placeholder [Media - unsupported MIME type: …] — the document is silently dropped (OpenAIMessageConverter.java:259-298).
    • DashScope: IllegalArgumentException("Cannot route DataBlock: unrecognised MIME type …") inside the model call (DashScopeMediaConverter.java:219-235).
    • Anthropic: AnthropicMediaConverter.convertDataBlock throws Anthropic API only supports image DataBlocks; got MIME type: … (AnthropicMediaConverter.java:85-108).
    • Gemini: passes any MIME through as inlineData (GeminiConversationMerger.java:147 → GeminiMediaConverter.convertToInlineDataPart) — probably works for PDF, but not covered by a test.

    Uncommenting the converter branch alone would therefore move the failure from a clean early rejection to a provider-dependent late failure or a silently dropped document — worse for clients than what you have now.

    Recommendation

    Take your option 2, and keep it contained:

    1. In AguiMessageConverter.toContentBlock, give DocumentInputContent its own branch that throws a payload-free, explicit error naming the discriminator (e.g. Unsupported AG-UI input content type 'document': document input is not supported yet) — either as-is or as a typed exception next to AguiException.java:21. Never interpolate the content record itself.
    2. Make the conversion failure reach the existing mapping: wrap toMsgList(...) in the same try/catch already used at AguiAgentAdapter.java:162-168 and return errorEvents(threadId, runId, input, error, true). Result: RUN_STARTED + RUN_ERROR with code=INVALID_INPUT_ERROR on both MVC and WebFlux, i.e. the documented contract, with a code clients can distinguish from INTERNAL_ERROR. This also removes the legacy Raw + RUN_FINISHED shape for every other input-validation failure, not just documents.
    3. One sentence in the EN/ZH AG-UI docs listing which InputContent types are accepted and that document returns RUN_ERROR/INVALID_INPUT_ERROR.

    For real document support, we'd suggest a separate enhancement covering converter + per-provider document handling + docs, since the framework side (DataBlock) is ready but the provider side is not.

    Maintainer input needed: confirm whether the clean-rejection change above is the intended direction. We have not opened a PR for it yet because it changes the exception type and the terminal event sequence that two existing tests currently pin (AguiMessageConverterTest.java:602-630, plus AguiRequestProcessorTest which asserts the raw error signal propagates), so it should be a maintainer call rather than an automatic fix.

    Severity: medium. Affected: agentscope-extensions-agui converter/adapter, the AG-UI Spring MVC + WebFlux starters, and any client sending document parts.

    Thanks for the precise report — the file/line pointers and the reproduction payload were accurate, which made verification quick.


    Automated evaluation by github-manager-bot

  2. added
    area/ext/integration
    bug
    on Oct 3, 2026
  3. xihongshichaojidan8 commented on Oct 3, 2026

    @xihongshichaojidan8
    Contributor

    我有兴趣处理这里的错误处理缺陷。已基于 main(915507134)在 Adapter 层本地复现:URL 和 Base64 document 输入各测试 3 次,均能解析,但转换异常包含原始 source 值,且 adapter.run() 直接以异常结束,没有发出 RUN_ERROR;Agent 未被调用。尚未做 HTTP 集成验证。

    拟保持 document 暂不支持的现状,只做以下修复:明确拒绝且不在错误信息中回显文档内容;让消息转换失败进入现有 INVALID_INPUT_ERROR / RUN_ERROR 映射,并保留 emitRunFinishedAfterError 的兼容行为。补充回归测试及中英文说明,不扩展文档解析、模型或沙箱上传支持。

    请维护者确认这个限定方向是否合适,以及是否已有其他人在处理;确认后我愿意提交一个聚焦的小 PR。

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/ext/integrationbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions