Repository navigation
Python: Surface Anthropic citations_delta annotations when streaming and read document_title for char_location - #9898
Open
Zakaria Khchiche (Zakariakhchiche) wants to merge 2 commits into
Conversation
…nt_title for char_location
Zakaria Khchiche (Zakariakhchiche)
temporarily deployed
to
github-app-auth
October 30, 2026 18:25 — with
GitHub Actions
Inactive
Zakaria Khchiche (Zakariakhchiche)
temporarily deployed
to
github-app-auth
October 30, 2026 18:25 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the streamed-citation and document-title changes.
No open issues 🎉
What changed in this PR
This PR addresses #8977 by preserving Anthropic citations in streamed responses and correcting document citation titles in the Python client, without changing the public API.
Changes:
- Handles
citations_deltaevents using empty appended text content to carry annotations. - Reads
document_titleforchar_locationcitations. - Adds regression tests for document citation metadata and streamed document/web citations.
| File | Description |
|---|---|
python/packages/anthropic/tests/test_anthropic_client.py |
Adds regression coverage for citation titles and streamed annotations. |
python/packages/anthropic/agent_framework_anthropic/_chat_client.py |
Parses streamed citation deltas and corrects document title extraction. |
Review effort: Balanced
Zakaria Khchiche (Zakariakhchiche)
temporarily deployed
to
github-app-auth
October 30, 2026 19:03 — with
GitHub Actions
Inactive
Zakaria Khchiche (Zakariakhchiche)
temporarily deployed
to
github-app-auth
October 30, 2026 19:03 — with
GitHub Actions
Inactive
Zakaria Khchiche (Zakariakhchiche)
temporarily deployed
to
github-app-auth
October 30, 2026 19:07 — with
GitHub Actions
Inactive
Zakaria Khchiche (Zakariakhchiche)
marked this pull request as ready for review
October 30, 2026 19:07
Zakaria Khchiche (Zakariakhchiche)
temporarily deployed
to
github-app-auth
October 30, 2026 19:08 — with
GitHub Actions
Inactive
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation & Context
Citations returned by Anthropic are lost or broken in two cases:
citations_deltaevent on the open text block._parse_contents_from_anthropichas no case for it, so streamed responses come back without any annotations, while the same request without streaming has them.char_locationcitations: the parser readscitation.title, butBetaCitationCharLocationexposesdocument_title. Document citations therefore have no title. This is the field issue raised in the review of Python: Surface Anthropic citations_delta annotations when streaming #8978.Description & Review Guide
citations_deltacase: it emits an empty text content withmerge_mode="append"when streaming, carrying the parsed annotation, so it merges into the text it belongs to._parse_citations_from_anthropicaccepts acitations_deltablock, reading its singlecitation.char_locationbranch readsdocument_title.BetaCitationCharLocationand checks the title, snippet and span; one streams a text block with achar_locationand aweb_search_result_locationcitation and checks that both end up as annotations on the final text.Related Issue
Fixes #8977.
No other open PR addresses this issue (#8978 was closed).
AI Assistance
AI assistance details:
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.