You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python: Fix Anthropic server-tool continuation and replay - #9718
Anthropic server-side tool calls are parsed into generic function-call content, but the outgoing adapter previously serialized every generic call as a client tool_use. Completed web-search and web-fetch results were likewise reduced to string function results, and provider-specific raw blocks do not survive persisted history. Mixed local/server tool turns could therefore fail validation immediately, while completed server-tool transcripts could not be replayed faithfully from file history.
The adapter also mapped Anthropic pause_turn to normal completion. Agents returned unfinished server-side work after one request instead of replaying the paused assistant content with the same tools.
This change preserves the minimum plain Anthropic metadata required to reconstruct native server-tool calls and results, and continues bounded paused server turns in both streaming and non-streaming modes.
Description & Review Guide
What are the major changes? The Anthropic parser now records replay-critical server-tool block data in Content.additional_properties["anthropic"]["server_tool_block"]. The serializer reconstructs server_tool_use, web_search_tool_result, and web_fetch_tool_result blocks with their original assistant role, structured content, encrypted payload fields, and optional caller metadata. Streamed server-tool input deltas remain hosted and informational while aggregating into the persisted call. Legacy srvtoolu_ calls are recovered from their reserved ID prefix, while legacy results whose structured data was already lost fail before an invalid request is sent. pause_turn now replays the returned assistant content with unchanged tools for up to 10 continuation requests; bounded exhaustion preserves finish_reason="pause_turn". The regression suite also incorporates Python: Keep pending Anthropic server tool calls as server_tool_use #9513's applicable unique scenarios: in-memory and reloaded pending calls, later occurrences reusing a call ID, MCP/code-execution delta guards, and the full mixed streaming continuation path. The package documentation and function-loop scenario matrix describe the resulting behavior.
What is the impact of these changes? Pending Anthropic server tools remain server-owned when local tool results are returned, completed server-tool transcripts survive JSON or MessagePack history round-trips, and paused hosted-tool work continues instead of being reported as successfully complete. Ordinary local function calls and results retain their existing request shape.
What do you want reviewers to focus on? Please review the provider-owned metadata shape, the explicit fail-closed behavior for unrecoverable legacy server-tool results, the bounded pause-turn continuation semantics, and the end-to-end replay coverage.
#9513 is closed and behaviorally folded into this PR. Its pending server_tool_use fix, transcript-reload coverage, reused-call-ID regression, streamed-input regression, and MCP/code-execution delta guards are included here, while this PR additionally preserves completed native web-search/web-fetch results, encrypted and caller metadata, explicit legacy failure behavior, file-history replay, and Anthropic pause_turn continuation. Shivam Sharma is credited as a co-author on the fold-in commit.
AI Assistance
No material AI assistance was used.
This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.
AI assistance details: investigation, implementation, tests, documentation, and this PR description.
Contribution Checklist
The code builds clean without any errors or warnings
All unit tests pass, and I have added new tests where possible
This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.
The reason will be displayed to describe this comment to others. Learn more.
MAF Automated Review — Iteration 1
Result: Findings reported Scope: full PR (1 commit(s)): 05ba43d363f5 Model:gpt-5.6-sol
Overview
The PR introduces an adapter-owned metadata envelope that survives framework serialization, validates replay types, preserves native server-result roles, and fails closed for unrecoverable legacy results. The end-to-end tests provide strong coverage for non-streaming and persisted web-search history. Two residual gaps remain: streaming drops server-tool arguments before native replay, and the new serializer mistakes any provider-neutral hosted call for an Anthropic server tool.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
2 verified findings remained after source verification (1 high, 1 medium) across 1 file. Details are attached to the affected lines below.
This PR addresses #9478 by preserving Anthropic server-tool identity and structured results in the Python adapter, extending the pending-call approach in #9513 to persisted history replay.
Changes:
Preserve provider metadata and reconstruct native server-tool calls and results.
Reject legacy server-tool results whose replay metadata is missing.
Document adapter-owned metadata and add continuation, persistence, and integration coverage.
MCP calls are not faithfully replayable in streaming mode yet: their opening mcp_tool_use can have input={}, and the parser deliberately discards subsequent input_json_delta events (also asserted by the new MCP delta regression). Whitelisting the resulting mcp_server_tool_call allows a paused turn to continue with empty arguments instead of the original input. Exclude MCP calls from automatic continuation until their streamed arguments are retained, and cover this paused-stream case.
Prevent replay when redacted thinking blocks are discarded
The replayability check only sees parsed Content, but the parser silently drops native redacted_thinking blocks. A paused response containing redacted thinking plus supported content therefore passes this guard in both response modes and is resent without its required reasoning block. Track discarded native blocks and return pause_turn without continuing, or preserve them faithfully; add redacted-thinking regressions for both modes.
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
documentationUsage: [Issues, PRs], Target: documentation in the code base and learn docspythonUsage: [Issues, PRs], Target: Python
3 participants
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
Anthropic server-side tool calls are parsed into generic function-call content, but the outgoing adapter previously serialized every generic call as a client
tool_use. Completed web-search and web-fetch results were likewise reduced to string function results, and provider-specific raw blocks do not survive persisted history. Mixed local/server tool turns could therefore fail validation immediately, while completed server-tool transcripts could not be replayed faithfully from file history.The adapter also mapped Anthropic
pause_turnto normal completion. Agents returned unfinished server-side work after one request instead of replaying the paused assistant content with the same tools.This change preserves the minimum plain Anthropic metadata required to reconstruct native server-tool calls and results, and continues bounded paused server turns in both streaming and non-streaming modes.
Description & Review Guide
Content.additional_properties["anthropic"]["server_tool_block"]. The serializer reconstructsserver_tool_use,web_search_tool_result, andweb_fetch_tool_resultblocks with their original assistant role, structured content, encrypted payload fields, and optional caller metadata. Streamed server-tool input deltas remain hosted and informational while aggregating into the persisted call. Legacysrvtoolu_calls are recovered from their reserved ID prefix, while legacy results whose structured data was already lost fail before an invalid request is sent.pause_turnnow replays the returned assistant content with unchanged tools for up to 10 continuation requests; bounded exhaustion preservesfinish_reason="pause_turn". The regression suite also incorporates Python: Keep pending Anthropic server tool calls as server_tool_use #9513's applicable unique scenarios: in-memory and reloaded pending calls, later occurrences reusing a call ID, MCP/code-execution delta guards, and the full mixed streaming continuation path. The package documentation and function-loop scenario matrix describe the resulting behavior.Related Issue
Fixes #9478
Fixes #9479
#9513 is closed and behaviorally folded into this PR. Its pending
server_tool_usefix, transcript-reload coverage, reused-call-ID regression, streamed-input regression, and MCP/code-execution delta guards are included here, while this PR additionally preserves completed native web-search/web-fetch results, encrypted and caller metadata, explicit legacy failure behavior, file-history replay, and Anthropicpause_turncontinuation. Shivam Sharma is credited as a co-author on the fold-in commit.AI Assistance
AI assistance details: investigation, implementation, tests, documentation, and this PR description.
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.