Repository navigation
Python: Replay Anthropic redacted_thinking blocks in tool loops - #10106
Merged
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit intoNov 5, 2026
Conversation
Atharva Vichare (atty57)
temporarily deployed
to
github-app-auth
November 4, 2026 20:28 — with
GitHub Actions
Inactive
Atharva Vichare (atty57)
temporarily deployed
to
github-app-auth
November 4, 2026 20:28 — with
GitHub Actions
Inactive
redacted_thinking blocks were parsed through the default branch and recorded as dropped content, so the function-invocation loop replayed the assistant turn without them. Anthropic requires the thinking blocks of the last assistant turn, including redacted ones, to be returned unmodified while tool use continues. Parse redacted_thinking into its own reasoning item carrying the opaque payload in Content.protected_data plus an anthropic namespace marker, following the existing Bedrock redacted-reasoning pattern. Serialize marked items back as redacted_thinking blocks, give each parsed reasoning block its own identity so streaming aggregation keeps thinking and redacted_thinking blocks separate, and fail before the request when a marked item cannot be reconstructed. pause_turn continuations can now replay redacted reasoning instead of stopping early. Fixes microsoft#10104
Atharva Vichare (atty57)
force-pushed
the
fix/anthropic-redacted-thinking
branch
from
November 4, 2026 20:30
783f2ac to
42d6ea8
Compare
Atharva Vichare (atty57)
temporarily deployed
to
github-app-auth
November 4, 2026 20:30 — with
GitHub Actions
Inactive
Atharva Vichare (atty57)
temporarily deployed
to
github-app-auth
November 4, 2026 20:30 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Core-team agreement required by Spec 004 remains unconfirmed for the provider/history serialization and continuation changes, so a maintainer must confirm the intended scope and direction.
No open issues 🎉
What changed in this PR
This PR addresses #10104 by preserving Anthropic redacted_thinking blocks in Agent Framework’s Python integration, allowing tool loops and paused turns to replay assistant reasoning faithfully.
Changes:
- Stores opaque redacted payloads in
Content.protected_datawith provider metadata and separate reasoning identities. - Replays redacted blocks in order, rejects missing payloads, and enables faithful
pause_turncontinuation. - Adds regression coverage for streaming, non-streaming, and persisted-history replay, and updates the related specifications.
| File | Description |
|---|---|
python/packages/anthropic/tests/test_anthropic_client.py |
Adds redacted-reasoning replay, persistence, validation, and continuation tests. |
python/packages/anthropic/agent_framework_anthropic/_chat_client.py |
Preserves and serializes redacted blocks, separates reasoning identities, and updates replay eligibility. |
docs/specs/005-python-content-identity-and-protocol-metadata.md |
Documents the Anthropic redacted-thinking marker and regression coverage. |
docs/specs/004-python-function-calling-loop.md |
Updates pause-turn behavior and test references to reflect supported redacted reasoning. |
Review effort: Balanced
Eduard van Valkenburg (eavanvalkenburg)
approved these changes
Nov 5, 2026
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
agent-framework-anthropicdropsredacted_thinkingcontent blocks while parsing a Claude response. The normal function-invocation loop then replays the assistant turn without that block, so the follow-up request carrying thetool_resultis missing reasoning that Anthropic requires to be returned unmodified. Only thepause_turncontinuation looked at the dropped-content bookkeeping, so ordinary tool loops lost the block silently.Description & Review Guide
What are the major changes?
_parse_contents_from_anthropicnow mapsredacted_thinkingto its own reasoning item:Content.protected_datacarries the opaquedatapayload andadditional_properties["anthropic"]["reasoning_block"]records the native block type. This mirrors the existing Bedrock redacted-reasoning handling and spec 005's rule that opaque provider reasoning payloads useContent.protected_data._prepare_message_for_anthropicserializes a marked item back as{"type": "redacted_thinking", "data": ...}, so[thinking, redacted_thinking, tool_use]and[redacted_thinking, tool_use]are replayed in order. A marked item without its payload raisesContentErrorbefore the request instead of being dropped silently.redacted_thinkingblock into an adjacentthinkingblock when a stream is finalized, and holds its own block in non-streaming responses too.pause_turnreplay guard treats a marked redacted item as replayable only when it has a payload, so continuations over redacted reasoning now proceed instead of stopping early.What is the impact of these changes?
raw_representationis not required).pause_turncontinuations that previously stopped because redacted reasoning was dropped now continue with a faithful transcript.What do you want reviewers to focus on?
The identity assignment on reasoning items (needed so streamed
thinkingandredacted_thinkingblocks stay separate), and the choice to fail loudly rather than skip a redacted item whose payload is missing.Related Issue
Fixes #10104
The issue is triaged, reproduced, and assigned, but I could not confirm a
ready-for-implementationlabel or a maintainer comment agreeing with this direction yet. The change follows the direction proposed in the issue and the existing Bedrock redacted-reasoning implementation; I'm happy to adjust if reviewers prefer a different approach. No other open PR addresses this issue.AI Assistance
AI assistance details:
Implementation, tests, and this PR description were drafted with AI assistance. I reviewed and verified the diff, ran the package test suite, and confirmed the reproduction from the issue now passes.
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.