Support Anthropic `web_search_20260318` and `web_fetch_20260318` via `provider_settings`

Merged
AD
25d ago
+1972-54

Second of three stacked PRs, on top of #7633, which adds provider_settings. #7807 builds on this one.

What this adds

Anthropic's newer web tools have options no other provider has, so they go in provider_settings:

WebSearchTool(provider_settings={'anthropic': {'response_inclusion': 'excluded'}})
WebFetchTool(provider_settings={'anthropic': {'use_cache': False, 'response_inclusion': 'excluded'}})

use_cache=False makes Anthropic fetch fresh content. response_inclusion='excluded' leaves out results that code execution already used. WebFetchTool gets its provider_settings field here, since Anthropic is its only provider with extra options.

Does user behaviour change?

Not for existing code. Nothing changes unless you set one of these options. If you do:

  • The request uses the 20260318 web tool, even if you set an option to its default value. response_inclusion needs that version, and use_cache needs web_fetch_20260309 or later, so one version covers both. The defaults are response_inclusion='full' and use_cache=True.
  • Models without dynamic filtering stay on direct calls. The 20260318 tools otherwise run through code execution, which these models don't opt into in Pydantic AI, so we send allowed_callers=['direct']. anthropic_web_tools_allowed_callers still overrides this.
  • Citations route the 20260318 tools to direct calls, the same as the 20260209 tools today.
  • response_inclusion only picks the newer version when it can matter. It only changes results that code execution consumes. On a model without dynamic filtering, which includes every model on Vertex, the web tools are called directly, so response_inclusion keeps the older version there unless anthropic_web_tools_allowed_callers names a code execution caller. That keeps it from moving Vertex onto web_search_20260318, which Vertex rejected when we checked. use_cache affects direct calls too, so it still selects web_fetch_20260318 everywhere. We don't raise our own error for any client, because a provider can add a version without a Pydantic AI release. The Bedrock clients, and web fetch on Vertex, still raise a UserError as they do today.

Testing

Recorded cassettes cover both 20260318 tools, including allowed_callers and citation routing. The option table from #7633 now also sends every Anthropic option through a real mocked request. The cassette tests check that code execution's results come back and the excluded web_search and web_fetch results don't.

I also ran live calls against Anthropic: streaming, multi-turn history, direct calls on a model without dynamic filtering, token counting, and use alongside CodeExecutionTool.

Vertex was checked live on Sonnet 4.6 and Sonnet 5.5 in the global region. Vertex rejects web_search_20260209, web_search_20260318 and every web fetch version with "does not match any of the expected tags", and lists web_search_20250305 as its only web tool. Foundry wasn't tested live, since we have no credentials for it. Bedrock is unchanged: web search and web fetch raise a UserError there, as on main.

Checklist

  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver. (Not applicable.)
  • PR title is fit for the release changelog.

šŸ¤– Generated with Claude Code


Summary by cubic

Adds Anthropic provider_settings for WebSearchTool and WebFetchTool, exposing response_inclusion and use_cache — options only available on Anthropic's web_search_20260318 and web_fetch_20260318 tool versions. This builds on the provider_settings support from #7633; WebFetchTool gains a provider_settings field since Anthropic is its only provider with extra options.

  • use_cache selects web_fetch_20260318 everywhere, since it also affects direct calls.
  • response_inclusion only selects the 20260318 versions where code execution may call the tool; models without dynamic filtering keep the older versions unless anthropic_web_tools_allowed_callers names a code execution caller.
  • Citations route the 20260318 tools to direct calls; Bedrock clients still raise UserError.
  • No client-specific errors: the version is sent and the provider's API decides.