Skip to content

feat(core): add DocumentBlock and DashScope qwen-long document input - #3869

Merged
jujn merged 5 commits into
agentscope-ai:mainfrom
ningmao-hlyz:feat/document-block
Oct 31, 2026
Merged

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

Conversation

@ningmao-hlyz

@ningmao-hlyz ningmao-hlyz commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.1.0-SNAPSHOT

Description

Fixes #3865.

Background. Document input had no first-class representation. DataBlock carries bytes but no document semantics, and the converters route it as image / audio / video, so a PDF either became placeholder text or disappeared without a trace.

Changes

  • core — DocumentBlock ("document") with id / name / mimeType / optional provider metadata, and FileIdSource ("file_id") as a new Source subtype for documents that already live on the provider side. Registered in the ContentBlock subtype list and the sealed ... permits clause; USER messages accept the block, SYSTEM still accepts text only. Docs block table updated in docs/v2/{en,zh}.
  • dashscope — the chat formatter emits {"role":"system","content":"fileid://<id>"} ahead of the turn that carries the document, which is the qwen-long contract. The injected message is excluded from automatic cache_control placement so the directive list stays aligned. URL and base64 sources are rejected with an explicit error rather than dropped. No model allowlist: an unsupported model surfaces the provider error instead of a list that goes stale.
  • openai / anthropic — both converters dropped unrecognised blocks, and an all-document message collapsed to empty content (Anthropic dropped the message entirely). They now log a warning and send a text placeholder, so the caller can see the document did not reach the model.

Scope. The file upload client, qwen-doc-turbo doc_url, and document parsing / RAG / citations stay out of scope, as agreed in the issue. Multi-agent conversation paths are unchanged across providers (DashScopeMultiAgentFormatter and the per-provider conversation mergers): they merge history into a single prompt, a document block has no representation there yet, and blocks they do not know are already skipped silently - same as any block type added before this one.

How to test

mvn -pl agentscope-core,agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-dashscope,agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-openai,agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-anthropic test

3500 tests, 0 failures. New coverage: DocumentBlockTest (JSON round-trip of block and source, generated id, role validation), DashScopeChatFormatterTest (injected system message, rejected URL source, cache_control alignment), and a placeholder test in each converter.

Four commits: the core block, the DashScope mapping and the converter placeholders can be reviewed or landed independently.

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

Document input had no first-class representation. DataBlock carries bytes
but not document semantics, so converters could only route it as image,
audio or video; anything else was dropped.

DocumentBlock ("document") carries id, name, an optional MIME type and
optional provider metadata, with FileIdSource ("file_id") as a new source
for documents that already live on the provider side.

USER messages accept the block; SYSTEM still accepts text only.
qwen-long reads documents from a fileid:// reference carried by a system
message, not from a content part. Emit one system message per document
block ahead of the turn that carries it, and keep the injected message out
of automatic cache_control placement so the directive list stays aligned.

URL and base64 document sources are rejected with an explicit error rather
than silently dropped. The file upload client stays out of scope.
Both converters ignored blocks they did not recognise, and an all-document
message collapsed to empty content - Anthropic dropped the message
entirely. Emit a warning and a text placeholder so the caller can see that
the document did not reach the model.
@mintlify

mintlify Bot commented Oct 30, 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 689db2b.

Approve preview

ningmao-hlyz and others added 2 commits October 30, 2026 20:50
Role validation lets ASSISTANT/TOOL carry arbitrary blocks for back-compat,
and the formatter was mapping a document block there too. Restrict the
fileid:// injection and the source rejection to USER turns; a document on
any other turn is aberrant input and is now ignored instead of being
injected into the request. Also refresh the stale block list in the
UserMessage javadoc.
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.

[Feature]: Support DocumentBlock and DashScope qwen-long document input

2 participants