Skip to content

feat(anthropic): support PDF documents and citations - #2275

Merged
jujn merged 6 commits into
agentscope-ai:mainfrom
dailingtao:codex/issue-2224-anthropic-pdf-citations
Nov 3, 2026
Merged

jujn merged 6 commits into
agentscope-ai:mainfrom
dailingtao:codex/issue-2224-anthropic-pdf-citations

Conversation

@dailingtao

@dailingtao dailingtao commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Description

Closes #2224.

Adds native Anthropic PDF document input and citation metadata support. PDFs use the provider-neutral DocumentBlock model rather than DataBlock, so document semantics and provider file IDs stay explicit. Anthropic response citations are preserved as provider-specific response metadata under anthropic.citations.

Changes

  • Convert Anthropic PDF DocumentBlock input to native Anthropic document blocks:
    • Base64Source
    • local file paths and file:// URLs
    • remote HTTP(S) URLs
    • FileIdSource references to files already uploaded to Anthropic
  • Route DocumentBlock through user messages, tool results, and the Anthropic multi-agent formatter.
  • Enable Anthropic citations on every PDF document sent by this integration, matching the API requirement that citations are enabled for all documents or none.
  • Parse page, character, and content-block citations from Anthropic responses into anthropic.citations response metadata. Each entry includes the citation type, source block index, cited text, document index, location fields, and optional title/file ID.
  • Accumulate streaming citation deltas in the Anthropic response parser and emit them with the terminal response metadata. Individual text delta events remain text-only.
  • Preserve prompt caching support for Anthropic document blocks.
  • Infer application/pdf from .pdf extensions in the shared media utility.
  • Keep DataBlock image-only for Anthropic; PDF DataBlock input now fails fast instead of creating a misleading document path.
  • Update the English and Chinese Anthropic integration docs.

Scope

  • PDF documents are represented by DocumentBlock.
  • DataBlock remains a generic media block and is not accepted as PDF input for Anthropic.
  • Files API upload is not included; callers can reference an already uploaded Anthropic file through FileIdSource.
  • Plain-text documents and custom-content documents are not supported yet.
  • Assistant citation metadata is response provenance and is not converted back into Anthropic request blocks on later turns.

@AgentScopeJavaBot AgentScopeJavaBot added enhancement New feature or request area/core/model Model providers and formatters area/docs Documentation labels Jul 18, 2026

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 AI Review

This PR adds PDF document support and native citation handling for the Anthropic integration. The changes are well-architected: a provider-neutral Citation sealed interface in core, TextBlock enhancements with citations and providerBlockIndex, a reworked TextAccumulator that preserves per-provider-block boundaries, and Anthropic-specific converters for PDF sources (base64, local file, file URI, HTTP URL) and citation responses (page, character, content-block — both streaming and non-streaming). The code is clean, backward-compatible, and has good test coverage (135 tests). No critical bugs found. Two minor suggestions below.

(inline comments could not be attached — line numbers fell outside PR hunks. See archived report.)

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 AI Review

This PR adds PDF document support and native citation handling for the Anthropic integration. The changes are well-architected: a provider-neutral Citation sealed interface in core, TextBlock enhancements with citations and providerBlockIndex, a reworked TextAccumulator that preserves per-provider-block boundaries, and Anthropic-specific converters for PDF sources (base64, local file, file URI, HTTP URL) and citation responses (page, character, content-block — both streaming and non-streaming). The code is clean, backward-compatible, and has good test coverage (135 tests). No critical bugs found. Two minor suggestions below.

(inline comments could not be attached — line numbers fell outside PR hunks. See archived report.)

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Summary

This PR contains 2526 lines of changes. Review in progress.


Automated review by github-manager-bot

@dailingtao dailingtao closed this Aug 22, 2026
@jujn jujn reopened this Oct 30, 2026
@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 53d68d3.

Approve preview

@jujn
jujn merged commit 9e98dfa into agentscope-ai:main Nov 3, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core/model Model providers and formatters area/docs Documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Anthropic PDF/document 输入与 citations 缺失

4 participants