Repository navigation
Python: Preserve Anthropic server-tool history replay - #9718
Eduard van Valkenburg (eavanvalkenburg) wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
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.
Affected areas: python/packages/anthropic/agent_framework_anthropic/_chat_client.py
There was a problem hiding this comment.
🟡 Changes recommended
Streaming still discards server-tool argument deltas, leaving replayed calls without their original queries or URLs.
1 open issue
What changed in this PR
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.
| File | Description |
|---|---|
python/packages/anthropic/tests/test_anthropic_client.py |
Adds mixed-tool continuation and persisted-history replay coverage. |
python/packages/anthropic/README.md |
Documents adapter-owned server-tool replay metadata. |
python/packages/anthropic/agent_framework_anthropic/_chat_client.py |
Preserves native server-tool metadata, serialization, and assistant roles. |
Review effort: Balanced

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.This change preserves the minimum plain Anthropic metadata required to reconstruct native server-tool calls and results across live continuation, streaming finalization, and persisted history reloads.
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. 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. The package documentation describes the adapter-owned metadata, and tests cover mixed local/server tools, pause-turn replay, serialized history, fresh-agent replay, and a live Anthropic integration path.Related Issue
Fixes #9478
#9513 addresses the pending mixed-tool call by preserving unresolved
server_tool_useblocks, but intentionally leaves completed server-tool calls/results in the existing generictool_use/tool_resultrepresentation because the structured result was not retained. This PR additionally preserves and replays completed native web-search/web-fetch result blocks through persisted history, handles encrypted and caller metadata, fails explicitly for unrecoverable legacy results, and adds full fresh-agent history replay coverage.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.