Add a provider adapter topic guide to `agent_docs` and give capability gating one rule

Merged
DS
1mo ago
+119-4

This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.

Part of #10983

Adds agent_docs/provider-adapters.md: one rule per concern that adapters currently solve several ways, each with a precedent on main. models/AGENTS.md gets a short "Adapter structure" section linking it, profiles/AGENTS.md gets the profile-flag placement rules, and adding-a-provider-api-feature gets a "where the wire mapping goes" step. Docs only.

Capability gating now has one rule. The skill's Step 3 said to set a client-dependent flag in Provider.model_profile(), which is static and sees only the model name; models/AGENTS.md allowed isinstance on the client class. Both now say: check the client class only in the model's _instance_profile_defaults() or profile, and read only the flag where the capability is used.

The placement follows the issue's proposal (rules in models/AGENTS.md, detail in a topic guide). The issue's placement question to maintainers is still open.

Drift on main (0e2df41d3c), which each standard governs from here on. Existing code stays as it is; aligning it is the refactor series in #10983.

StandardCode on main that diverges
One method per part type, one dispatch per message kind3 functions score 281 to 294 on cognitive complexity: OpenAIResponsesModel._map_messages (294), the Responses stream iterator (283), BedrockConverseModel._map_messages (281). #11116 already took AnthropicModel._map_message from 390 to 10
Gate on a profile flag; client check only in profile / _instance_profile_defaults()12 inline gates: Anthropic 6 (_map_tool_search_call_input, _resolve_tool_search_strategy, tool_addition_mode, ...), Google 3 (_get_tool_config, _map_messages, _build_image_config), OpenRouter 2 model-name prefixes, Ollama 1 base_url
API facts in Provider.model_profile(), not a shared family profile2: openai_model_profile sets supports_inline_system_prompts and openai_supports_prompt_cache_breakpoints
Thinking fallback through render_replayed_thinking6 hand-joined thinking_tags in adapters (OpenAI 3, Groq, Hugging Face, xAI)
Native tool kinds through one table; raise on an unknown own kindOnly google.py derives the reverse table and raises on an unknown kind
No sentinel id2 spellings for one concept: 'redacted_thinking' (Anthropic), 'redacted_content' (Bedrock)
Shared cache algorithms in _prompt_cache.pyThe static-instruction breakpoint count: 3 inline copies (Anthropic, Bedrock, OpenRouter) plus openai.py::_cacheable_instruction_count
Tool-result media flag lists MIME typesBedrock's flag lists media kinds (bedrock_supported_media_kinds_in_tool_returns)

Counts come from git grep and an AST pass over models/*.py; scores from complexipy 8.1.0.

Left out on purpose
  • Research drafts that need machinery main lacks: an empty-text adapter declaration, an accepted_provider_names property, a per-file predicate on the tool-return split helper, a generic max_cache_points profile field.
  • Undecided policy: migrating response-scoped tool-call IDs and sentinel IDs, foreign reasoning on unsigned native channels, the Ollama Cloud base_url check, one error class for unsupported media.
  • A rule to mint the tool_call_id when a provider's ID isn't unique: no code on main does that yet.
  • guard_tool_call_id() as a recommendation: it mints a random ID per send, which breaks "Canonicalize on send".
  • The complexity gate, agent_docs/complexity.md and the single-use-helper carve-out: separate PRs in the #10983 series.
  • A CI Review targeted check for these rules: a follow-up PR once this one lands.
PR decisions

2026-10-23 · Data-only mapping context · iter -

  • Decision: Request-wide mapping state goes in a private data-only dataclass; per-part methods live on the model class. _MapModelResponseContext keeps its methods because OpenRouter and Snowflake subclass it.
  • Why: The issue's proposal names a data-only context; the precedent class carries methods only for its subclass hooks.
  • Source: https://github.com/pydantic/pydantic-ai/issues/10983

2026-10-23 · Standards govern added code · iter -

  • Decision: Each standard applies to code a change adds; existing divergences stay until a PR that aligns them.
  • Why: Aligning an adapter changes its request bytes, which the root AGENTS.md scope rules forbid in an unrelated change.
  • Source: https://github.com/pydantic/pydantic-ai/issues/10983

2026-10-23 · No rule that names missing machinery · iter -

  • Decision: Leave out research drafts that need helpers main lacks: rejects_empty_text, accepted_provider_names, a keep_inline split parameter, a generic max_cache_points, and the ban on sharing _-prefixed models/init.py functions.
  • Why: A rule naming a missing helper cannot be followed; #8094 shares _unprepared_part_error from models/init.py on purpose.
  • Source: https://github.com/pydantic/pydantic-ai/pull/8094

2026-10-23 · Thinking standard neutral on unsigned channels · iter -

  • Decision: The thinking rule governs only the fallback rendering and signed channels; it does not say whether another provider's reasoning may ride an unsigned native channel.
  • Why: Research decision 7 (Mistral, Cohere, Gemini) has no answer from David.
  • Source: https://github.com/pydantic/pydantic-ai/issues/10983

2026-10-23 · No guard_tool_call_id recommendation · iter -

  • Decision: The tool-call ID standard does not recommend _utils.guard_tool_call_id at send time.
  • Why: It mints a random ID per send when one is missing, which breaks the 'Canonicalize on send' rule in agent_docs/message-history-and-caching.md.
  • Source: https://github.com/pydantic/pydantic-ai/issues/10983

2026-10-23 · Rules scoped for blocking review · iter -

  • Decision: Ownership rule follows the majority (compare with self.system; a set only when several names); no module-constant requirement for provider_details keys.
  • Why: douwebot treats every agent_docs rule as blocking (.github/workflows/bots.yml), so a rule stricter than current practice would block routine PRs.
  • Source: https://github.com/pydantic/pydantic-ai/blob/main/.github/workflows/AGENTS.md

2026-10-23 · Per-part functions may be module-level · iter -

  • Decision: Per-part mappers live on the model class, or at module level when they read nothing from self; the context dataclass stays data-only.
  • Why: Existing precedents are module functions (anthropic.py _map_server_tool_use_block, google.py _native_tool_call_part_dict); requiring methods would make them diverge.
  • Source: https://github.com/pydantic/pydantic-ai/issues/10983
  • Supersedes: Data-only mapping context

2026-10-23 · Single-call-site arms are methods · iter -

  • Decision: A per-part arm with one call site is a method on the model class, never a nested def; a one-statement arm stays inline. Module-level functions only for wire-item mappers with two call sites.
  • Why: agent_docs/index.md rule 176 allows 'within the class' and forbids module level for single-use helpers; this resolves the CI Review conflict without the gate session's carve-out.
  • Source: https://github.com/pydantic/pydantic-ai/pull/11106#discussion_r4355658397
  • Supersedes: Per-part functions may be module-level

2026-10-23 · Drop the non-unique provider ID rule · iter -

2026-10-23 · Adapter declarations count at use sites · iter -

  • Decision: At a use site, read a profile flag or the adapter's own declaration (_unsupported_file_inputs and similar); the never-list covers the transport, including a client's own mode such as genai.Client.vertexai.
  • Why: models/AGENTS.md puts several wire facts on the adapter on purpose, and GoogleModel._is_google_cloud reads a client attribute, not the class.
  • Source: https://github.com/pydantic/pydantic-ai/pull/11106#discussion_r4355658670

2026-10-23 · CI Review provider-adapters check is a follow-up PR · iter -

2026-10-23 · First-head review was douwebot, not CI Review · iter -

  • Decision: The CHANGES_REQUESTED review on 01f82df7f9 and its six findings came from douwebot (label applied 02:54Z, removed 02:58Z); CI Review's agent has not run on this PR. Earlier entries and the c09d28574c commit message call it CI Review.
  • Why: Run 39892112971 skipped its agent; the issue events show the douwebot label cycle around the review.
  • Source: https://github.com/pydantic/pydantic-ai/pull/11106

2026-10-23 · Alignment is its own PR, byte-identical when structural · iter -

  • Decision: The guide's scope paragraph says aligning existing code is its own PR; a structural alignment keeps request bodies byte-identical, proven by a captured-body diff; a behavioral one is a fix that calls out each change.
  • Why: #10983 item 4 requires byte-identical refactors, so 'aligning changes bytes' was the wrong reason.
  • Source: https://github.com/pydantic/pydantic-ai/pull/11106#discussion_r4355989511
  • Supersedes: Standards govern added code

2026-10-23 · Replay readers: model or type check · iter -

  • Decision: Replay read-back needs one validating function per field, with a Pydantic model or an explicit type check; scattered unvalidated .get() reads are the ban.
  • Why: Google and Anthropic centralize readers with .get() plus isinstance; a Pydantic-only rule would block routine PRs extending them.
  • Source: https://github.com/pydantic/pydantic-ai/pull/11106#issuecomment-6357098964

2026-10-23 · Pydanty review dismissed · iter -

2026-10-23 · No CI Review pass · iter -

Checklist

  • 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.
  • PR title is fit for the release changelog.