Migrate common.ai provider to pydantic-ai 2.x and remove the <2 cap#69358
Merged
Merged
Conversation
pydantic-ai 2.x removed the ``instrument`` keyword from the ``Agent()`` and ``Agent.from_file()`` constructors (it is now only the ``agent.instrument`` property), which broke ``PydanticAIHook.create_agent`` when a caller passed ``instrument``. Pop a caller-supplied ``instrument`` out of the constructor kwargs and apply it through the property instead, so the caller still wins over the provider's auto-instrumentation. - Bump the OTel GenAI semantic-convention format to version 5 (formats 2-4 are deprecated in 2.x and warn). Agent-run token usage now reports under ``gen_ai.aggregated_usage.*`` while model-request spans keep ``gen_ai.usage.*``; documented in observability.rst and asserted in the end-to-end span test. - Update ``Agent[None, ...]`` annotations to ``Agent[object, ...]`` to match the 2.x generic-deps default (object, not None). - Raise the floor to ``pydantic-ai-slim>=2.0.0`` and re-lock (slim + pydantic-graph 1.107.0 -> 2.1.0). Closes apache#69122
kaxil
requested review from
Lee-W,
eladkal,
pierrejeambrun,
potiuk and
vatsrahul1001
July 3, 2026 17:51
gopidesupavan
approved these changes
Jul 3, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Migrates
apache-airflow-providers-common-aito pydantic-ai 2.x and removes the temporary<2cap added in #68933.pydantic-ai 2.x removed the
instrumentkeyword from theAgent()andAgent.from_file()constructors; it is now only theagent.instrumentproperty.PydanticAIHook.create_agentforwarded a caller-suppliedinstrumentstraight into the constructor, socreate_agent(..., instrument=...)raisedTypeError: got an unexpected keyword argument 'instrument'on 2.x. The hook now pops a caller-suppliedinstrumentout of the constructor kwargs and applies it through the property, so a caller still overrides the provider's auto-instrumentation.Changes
hooks/pydantic_ai.py): popinstrumentbefore constructing the agent, then apply it via theagent.instrumentproperty.observability.py): formats 2 to 4 are deprecated in 2.x and emit a warning; v5 is the current default.Agent[None, ...]becomesAgent[object, ...]in the hook overloads and operators, matching the 2.x generic-deps default (object, notNone). Type-checking only; runtime unchanged.pydantic-ai-slim>=1.99.0,<2becomes>=2.0.0; re-locked (pydantic-ai-slimandpydantic-graph1.107.0 to 2.1.0).Behavior changes (from pydantic-ai 2.x, surfaced through the provider)
gen_ai.aggregated_usage.*, while per-model-call spans keepgen_ai.usage.*. This avoids double-counting in backends that sum a parent span and its children. Documented inobservability.rstand asserted in the end-to-end span test. Dashboards or alerts reading run-level usage fromgen_ai.usage.*should switch togen_ai.aggregated_usage.*. Tracing is opt-in ([common.ai] otel_export_enabled) and off by default.end_strategydefault flipped fromearlytograceful: function tools requested in the same response as a successful output tool now run instead of being skipped.Design notes
>=2.0.0rather than keeping 1.x/2.x dual support: format v5 does not exist on 1.x, dual-version branches would be untestable in CI (the lock resolves a single version), and the provider is pre-1.0. Raising a third-party floor is allowed; the release-manager-only rule applies toapache-airflow-providers-*dependencies.Known follow-up
code-modeandskillsextras still carry their pre-2.x adapter floors (pydantic-ai-harness>=0.3.0,pydantic-ai-skills>=0.11.0). The 2.x-nativepydantic-ai-harness(0.5.0, which requirespydantic-ai-slim>=2.1.0) currently falls outside the repository'sexclude-newerwindow, so raising those extra floors is left as a follow-up once it resolves.Closes #69122