Skip to content

feat(core,model,protocol,dashscope): preserve documents across the conversation lifecycle - #3979

Merged
jujn merged 5 commits into
agentscope-ai:mainfrom
ningmao-hlyz:fix/document-block-propagation
Nov 6, 2026
Merged

jujn merged 5 commits into
agentscope-ai:mainfrom
ningmao-hlyz:fix/document-block-propagation

Conversation

@ningmao-hlyz

@ningmao-hlyz ningmao-hlyz commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.1.0-SNAPSHOT (based on main at 7ad4939f)

Description

Background

#3869 introduced DocumentBlock and #2275 added native Anthropic PDF support, but the block
was handled almost nowhere else: most provider formatters, the history merging/compaction
paths, exports, telemetry, and the AG-UI/A2A protocol boundaries dropped or mangled
documents, in several cases reducing an attachment-only turn to empty text or throwing an
unsupported-block exception. Details are in the linked issue. While fixing this, the
DashScope document surface described in #3943 (native doc_url input and PPT skill
output) is completed on the same propagation foundation.

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 feat(agui): convert URL media blocks to AG-UI input contents #4003 and compose
    with the reasoning-plus-media split from fix(agui): preserve URL media alongside reasoning #4009; only a source the protocol cannot express
    falls back to a text reference. A2A file parts parse back into DocumentBlocks with
    framework metadata markers taking precedence over user keys.
  4. feat(dashscope): support document inputs and PPT skills — closes [Feature]: Support qwen-doc-turbo document input and PPT output #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.

How to test

  • mvn test — new unit tests cover the renderer, every provider converter/merger (including
    formatter-entry tests that assert exactly-once reference rendering), AG-UI JSON round
    trips (name survival, reserved-key conflicts, non-string values, no-name documents), A2A
    parsing/metadata precedence, DashScope doc_url validation and skill DTOs, and blank-line
    fidelity in session exports.
  • DashScope was additionally verified end-to-end against the real service: doc_url
    extraction with qwen-doc-turbo and creative-mode PPT generation with skill metadata
    annotation.
  • Docs checks: npm run check (432 pages, navigation/syntax/local links/anchors/assets) and
    the docs script tests pass.

Closes #3943, closes #3978

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

@mintlify

mintlify Bot commented Nov 4, 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 386466c.

Approve preview

@ningmao-hlyz
ningmao-hlyz force-pushed the fix/document-block-propagation branch from 299ce63 to aa3a0fe Compare November 4, 2026 18:11
@ningmao-hlyz ningmao-hlyz changed the title fix(core,model,protocol,dashscope): preserve documents across the conversation lifecycle feat(core,model,protocol,dashscope): preserve documents across the conversation lifecycle Nov 4, 2026
@ningmao-hlyz
ningmao-hlyz force-pushed the fix/document-block-propagation branch 2 times, most recently from 860134c to 6fbf466 Compare November 6, 2026 06:19
@ningmao-hlyz

Copy link
Copy Markdown
Contributor Author

@jujn could you review this when you get a chance? It closes #3943 and #3978 — DashScope doc_url input + PPT skill output, plus document propagation across core text sinks, provider formatters, AG-UI/A2A, and the harness/export paths.

Four commits, rebased on the latest main; the AG-UI side composes with the URL media conversion from #4003 (media and document parts share the outbound path, non-user documents degrade to a text reference).

Documents arriving in memory flushes, compaction summaries, subagent
payloads, session exports, telemetry attributes, control-plane and admin
projections used to be dropped or embedded as raw payloads. Introduce
DocumentReferenceRenderer as the single renderer every text sink shares:
blocks collapse to a one-line reference (URL, provider file id, or an
inline-size description that never leaks base64 or a local temp path),
and an attachment-only turn keeps its reference instead of being
filtered out. Tool-result text conversion regains its DataBlock source
path, and the session transcript export joins lines like
Msg.getTextContent(), so blank lines survive leading, trailing,
consecutive, and all-blank outputs. Documents without a name or id
render as "unnamed" instead of "null".
Gemini, Ollama, OpenAI, and OpenAI Official formatters dropped or
mangled documents in converter paths that never routed through the
shared base extractor: assistant turns lost returnDirect tool
deliveries, non-user roles silently discarded DocumentBlocks, and the
Gemini MIME allowlist rejected document types the GenerateContent API
actually accepts (markdown, TypeScript, notebooks, JSON, and more).

Each provider now renders document references wherever documents can
appear, Gemini maps accepted documents to its native fileData field and
degrades the rest. The injected text extractor contract now excludes
document references, and each converter renders one reference per
document on top of it, so an assistant-carried document yields exactly
one reference line through the real formatter entry point regardless of
which extractor is injected.
The AG-UI protocol union had no way to express a document beyond a file
handle, so URL and inline-data documents degraded to plain text and
provider file handles lost their names and MIME types. Add a document
content type with URL, data, and file sources; every source variant
carries an optional name extension field, so a document's display name
travels with the source and user metadata is never borrowed for
transport. File handles map onto FileIdSource with the provider naming
who issued the handle.

On the A2A side, file parts and document-bearing metadata now parse back
into DocumentBlocks: the parser router recognizes file parts, framework
markers take precedence over user metadata keys without eating them,
and a JSON-serialized block survives a round-trip as a reference
instead of an opaque payload.
DashScope becomes the first provider with first-class document input:
URL documents map onto the native doc_url content type with count and
streaming validation, file-id documents ride the provider's file
channel, and every formatter path (chat, multi-agent, converter) keeps
document references instead of dropping them on assistant or tool
turns. Document URLs and PPT-generation skills are declared through the
DashScopeSkill DTO and marked in skill metadata, and the multimodal
example plus the zh/en integration docs show the defaultOptions model
default and the per-call form.
@ningmao-hlyz
ningmao-hlyz force-pushed the fix/document-block-propagation branch 2 times, most recently from dfb35a2 to 22acc42 Compare November 6, 2026 11:20
@jujn
jujn force-pushed the fix/document-block-propagation branch from 22acc42 to 386466c Compare November 6, 2026 15:35
@jujn
jujn merged commit 85fa9a6 into agentscope-ai:main Nov 6, 2026
9 checks passed
jujn added a commit that referenced this pull request Nov 21, 2026
## Description

The AG-UI protocol defines three source types for media parts — `url`,
`data` (inline Base64), and `file` (provider-issued handle) — and the
inbound direction accepts all three. The outbound path from #4003,
however, serialized URL sources only: media blocks carrying a
`Base64Source` or `FileIdSource` were dropped silently, with no log or
fallback. Media sent as inline data or a file handle therefore
disappears from `MESSAGES_SNAPSHOT` history on reconnects, refreshes,
and session switches.

This change maps all three AgentScope source types on the outbound path,
mirroring the document handling #3979 established in
`toDocumentInputContent`.

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

2 participants