Skip to content

fix(agui): preserve URL media alongside reasoning - #4009

Merged
jujn merged 2 commits into
agentscope-ai:mainfrom
pengmoubuaixuexi:fix/agui-reasoning-url-media
Nov 6, 2026
Merged

jujn merged 2 commits into
agentscope-ai:mainfrom
pengmoubuaixuexi:fix/agui-reasoning-url-media

Conversation

@pengmoubuaixuexi

@pengmoubuaixuexi pengmoubuaixuexi commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.1.0-SNAPSHOT, based on main dc077e7abfc4b2dd1062f2279dad48382256b819.

Description

Fixes #4008.

An assistant message with a ThinkingBlock and supported URL media, but no text/tool call, currently converts to just a reasoning message. toSingleAguiMessage collects the media, then its old reasoning-only fast path returns before emitting it. This also loses media when toAguiMessageList converts a conversation.

Build reasoning and standard content together in buildAguiMessages, as suggested in review. Collect thinking, text, tool calls/results and media in one content traversal, then emit the reasoning message and any remaining content. The reasoning-only return requires the collected media list to be empty, so mixed messages retain their assistant MessageContent.Blocks. This removes toSingleAguiMessage, splitReasoningMessage and the separate thinking scan while retaining public entry points, message order and multiple-tool-result expansion. The change builds on outbound media support in #4003 and is separate from inbound document handling in #3392.

The regression covers all supported URL media categories (image, audio, video, document, and image/document DataBlock routing), checking the serialized type, URL and MIME type plus distinct generated message IDs. A conversation-list case verifies media serialization and preservation of the following user message; a reasoning-only control still yields one reasoning message. EN/ZH protocol docs describe the mixed case.

Validation

Windows, Java 17.0.15, Maven 3.9.12; JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8. All Maven commands ran from the repository root with -B -T1C.

  • Unchanged production code + final regression: 8 tests, 7 failures, 0 errors, with the reasoning-only control passing. The final regression was rechecked against pristine production before restoring the fix.
  • mvn -B -T1C -pl :agentscope-extensions-agui -am -Dtest=AguiReasoningMediaTest,AguiMessageConverterTest -Dsurefire.failIfNoSpecifiedTests=false test: 82 passed, zero failures/errors/skips.
  • mvn -B -T1C -pl :agentscope-extensions-agui -am -DskipTests clean install: passed, building dependencies from this checkout; tests were skipped for this dependency build.
  • mvn -B -T1C -pl :agentscope-extensions-agui clean verify: 563 passed, zero failures/errors/skips. Spotless, Javadoc and packaging passed.
  • From docs/: npm ci --ignore-scripts, npm test (13 passed) and npm run validate: passed. npm run broken-links reports 2,224 links in 328 files on both this change and pristine main; the ordered file/target lists are identical.
  • git diff --check: passed. Upstream main was fetched again before submission and remained at the stated base.
  • Review follow-up bda01f03: reran mvn -B -T1C -pl :agentscope-extensions-agui clean verify after consolidating the builder: 563 passed, zero failures/errors/skips; Spotless, Javadoc, packaging and git diff --check passed. Existing regression assertions were unchanged. The original pre-refactor head passed both Ubuntu and Windows CI; the updated head must run CI again.

This is an offline public-converter and JSON-serialization regression, not a live model, generated-media download or frontend integration test. It does not expand Base64 support or inbound assistant structured-content support. Full-repository tests were not run and no coverage percentage is claimed.

AI assistance was used for investigation, implementation, tests and diff review. The reported checks were executed locally.

Checklist

  • Affected Java code formatted and Spotless checks pass.
  • Relevant AG-UI tests and module clean verify pass; full-repository mvn test was not run.
  • Existing documented conversion contract retained; Javadoc generation passes.
  • Related EN/ZH documentation updated and validated.
  • Complete diff inspected; change ready for maintainer review.

Copilot AI balanced review requested due to automatic review settings November 6, 2026 00:13
@mintlify

mintlify Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit bda01f0.

Approve preview

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@dragondyt

Copy link
Copy Markdown
Contributor

return splitReasoningMessage(msg, toSingleAguiMessage(msg));
的写法有点冗余,List能容纳多种消息,也包括思考消息,要不借着这个机会,合并成一个buildAguiMessages,在一个方法里处理,方便理解

@pengmoubuaixuexi

Copy link
Copy Markdown
Contributor Author

Thanks for the suggestion. Addressed in bda01f0: toAguiMessages now delegates to a single buildAguiMessages method, which collects thinking/text/media/tool content in one traversal and builds the output list directly. I removed toSingleAguiMessage, splitReasoningMessage and the separate thinking-content scan. Reasoning-only messages still yield one message, mixed reasoning/media yields both messages, and multiple tool results retain their existing expansion.

Reran mvn -B -T1C -pl :agentscope-extensions-agui clean verify: 563 tests passed, zero failures/errors/skips; Spotless, Javadoc and packaging passed. The existing regression assertions are unchanged. git diff --check also passed. The PR description has been updated to reflect the final implementation; CI for the new head is pending.

@dragondyt dragondyt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@jujn
jujn merged commit 29963a2 into agentscope-ai:main Nov 6, 2026
7 checks passed
jujn added a commit that referenced this pull request Nov 6, 2026
…nversation lifecycle (#3979)

## Description

### What changed

1. **`fix(core): preserve document references in text sinks`** — new
`DocumentReferenceRenderer` renders a document as a one-line reference
(name, MIME type,
URL/provider file id, or an inline-size description that never leaks
base64 or a local
temp path). Memory flushing, compaction, subagent/task results, session
exports, public
events, telemetry redaction, control-plane and admin projections now
keep that reference
   instead of losing the attachment.
2. **`fix(model): preserve documents across provider formatting`** —
Ollama, OpenAI (and the
GLM/DeepSeek/Kimi/MiniMax compat formatters), OpenAI Official Responses,
and Gemini keep
documents through formatting and merging; the text extractor contract is
"text without document references", and each converter renders
references where
documents can appear, so an assistant-carried document yields exactly
one reference
line. Gemini maps accepted MIME types (aligned with the GenerateContent
reference) to its
   native file data and degrades the rest.
3. **`feat(protocol): preserve documents through AG-UI and A2A`** —
AG-UI gains a document
   content type with URL / inline-data / provider-file sources.
Documents serialize on every role alongside the URL media support from
#4003 and compose
with the reasoning-plus-media split from #4009; only a source the
protocol cannot express
falls back to a text reference. A2A file parts parse back into
`DocumentBlock`s with
   framework metadata markers taking precedence over user keys.
4. **`feat(dashscope): support document inputs and PPT skills`** —
closes #3943: URL
documents map to the native `doc_url` content part (count and streaming
validation),
file-id documents keep the `fileid://` channel, `file_parsing_strategy`
is honored, and
the PPT `skill` parameter (template and creative mode) streams
outline/pages through
thinking blocks with the download URL in the final text content and a
typed
`dashscope.skill` metadata marker. Multimodal example and zh/en docs
included.
5. **`fix(core,protocol,model): degrade unsupported documents instead of
failing`** — a
document block stays in the conversation history, so a formatter that
throws on a source
it cannot deliver breaks every later turn of that session. DashScope now
emits a text
reference for Base64 payloads and file ids issued by another provider
(AG-UI accepts both
on input), references say `unnamed` instead of leaking the block's
internal UUID, A2A
leaves `FilePart.name` unset instead of shipping a UUID as the
attachment name, and the
A2A file parser validates the MIME type before a document marker can
route around it.

Co-authored-by: jujn <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: AG-UI conversion drops URL media from assistant messages with reasoning

4 participants