Move provider-specific native-tool fields to `provider_settings`

Merged
AD
25d ago
+863-136

Third of three stacked PRs, on top of #7633 and #12610. Options that only one provider has move into provider_settings.

ToolMoved fields
ImageGenerationTool → openaiaction, background, input_fidelity, moderation, model, partial_images, quality
AdvisorTool → anthropiccaching
FileSearchTool → xaiinstructions, retrieval_mode
WebFetchTool → anthropicenable_citations, max_content_tokens

Does user behaviour change?

[!WARNING]
Yes, but only by adding a warning. Setting one of these fields directly on a native tool now emits PydanticAIDeprecationWarning. The field keeps working and requests don't change. It goes away in v3.

Why: these fields only ever worked on one provider, yet they looked portable on the tool. Under provider_settings the provider is explicit.

ImageGenerationTool(quality='high')  # warns, still works
ImageGenerationTool(provider_settings={'openai': {'quality': 'high'}})  # new form
  • Setting both forms to different values raises UserError when the tool is built, because neither value is clearly the one you meant. This can't affect existing code, since provider_settings is new on these tools. Matching values only warn.
  • Capability arguments don't warn. ImageGeneration(quality='high'), WebFetch(enable_citations=True) and harness Advisor(caching='5m', max_uses=2) keep working as they are.
  • Tools built by those capabilities are unchanged. tool.quality reads as before and they still equal a directly built tool.
  • When a capability applies its arguments to a tool you pass to native=, they still win, including over the same option in that tool's provider_settings.
  • NativeTool specs warn, rebuilding doesn't. A NativeTool spec using a moved field warns, since its author can change it. Validating a tool from data, as durable execution does between activities, stays quiet.
  • Unknown keys in provider_settings are ignored, the same as in #7633.
  • The spec JSON schema marks the moved fields deprecated, so editors can flag the old form in YAML and JSON specs. Defaults and attribute access are unchanged.
  • A moved field set to its default doesn't warn, because it can't be told apart from leaving the field out.

What moves and what stays. A field moves when only one provider applies it and other models silently ignore it. Restrictions stay top-level even when only one provider applies them natively: allowed_domains, blocked_domains, max_uses on web search and web fetch, and external_web_access=False. A model that can't apply one refuses the tool, so it falls back to a local tool or raises. Under another provider's key it would be silently dropped. AdvisorTool.max_uses also stays: it is a generic cap that Anthropic enforces natively and the harness Advisor enforces itself on its local path, so it is not a single-provider setting. OpenRouter's native advisor still ignores it, as on main.

external_web_access deliberately stays a top-level field. Every model has to honour False or raise an error, and moving it under OpenAI's settings would make other models silently drop that restriction.

Testing

A test table covers every moved option: the warning, the same request in both forms, and the error when they conflict.

To check for regressions, I ran about 2,100 mocked checks on both main and this branch: every tool field and value across each adapter, every capability argument, overrides on tools passed to native=, serialization round trips and the harness advisor. Requests, attributes, equality and errors all match. The only differences were the intended warnings on directly built tools and the new exported names. That run predates moving enable_citations and max_content_tokens, which the test table covers. Dumped tools also gain a provider_settings: null key. Data saved by either version loads on the other, but an older version drops the provider_settings key without an error: a tool saved with provider_settings={'openai': {'quality': 'high'}} loads on main as quality='auto'. Durable-execution workers on mixed versions during a deploy can therefore send the old default for one activity.

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. (No waiver is required because the legacy fields remain in the exact API.)
  • PR title is fit for the release changelog.

šŸ¤– Generated with Claude Code