Skip to content

Add pydantic_ai bridge submodule (port from pydantic-ai _a2a.py)#55

Draft
dsfaccini wants to merge 7 commits into
datalayer:mainfrom
dsfaccini:add-pydantic-ai-bridge
Draft

Add pydantic_ai bridge submodule (port from pydantic-ai _a2a.py)#55
dsfaccini wants to merge 7 commits into
datalayer:mainfrom
dsfaccini:add-pydantic-ai-bridge

Conversation

@dsfaccini
Copy link
Copy Markdown
Collaborator

@dsfaccini dsfaccini commented May 8, 2026

Claude here:

Port of pydantic-ai's Agent.to_a2a() integration into this package, in advance of the v2 deprecation on the pydantic-ai side (see pydantic/pydantic-ai card 46).

Why now

After the FastA2A donation, pydantic-ai is deprecating Agent.to_a2a(), the pydantic_ai._a2a module, and the a2a install extra in 1.x — to be removed in v2. Users who hit those deprecation warnings need somewhere to land. This PR brings the bridge code into the FastA2A repo so the migration message can simply be 'install fasta2a[pydantic-ai] and import agent_to_a2a'.

What's in the diff

  • fasta2a/pydantic_ai/__init__.py — re-exports agent_to_a2a, AgentWorker, worker_lifespan
  • fasta2a/pydantic_ai/_bridge.py — 1-to-1 port of pydantic_ai._a2a (~241 lines). Imports flipped: this submodule imports from pydantic_ai, not the other way around. The body is unchanged so you can see exactly what shipped today.
  • pyproject.toml — adds pydantic-ai = ['pydantic-ai-slim>=1.92'] optional extra. Pinned to slim to avoid pulling the full LLM-provider matrix into anyone who installs fasta2a[pydantic-ai].

Open for redirection — happy to iterate

This is intentionally a near-verbatim port so you can pick the API shape:

  1. API shape: flat agent_to_a2a() function (current) vs. an AgentApplication class? Module layout fasta2a.pydantic_ai (current) vs. fasta2a.bridges.pydantic_ai if you anticipate more bridges?
  2. Optional dep target: pydantic-ai-slim>=1.92 or the full pydantic-ai? Slim is the conservative pick.
  3. Tests: not ported. The pydantic-ai side has 1033 lines of A2A tests in tests/test_a2a.py; happy to port subset, or leave to you to test in your style.
  4. README: not touched. Suggested snippet in the card-46 plan doc if useful.

Sequencing

Marking this PR as draft because the pydantic-ai-side deprecation PR (a v2:prep PR adding @deprecated warnings on Agent.to_a2a() etc.) is held until this one lands or has a confirmed merge ETA — the deprecation message will point users here.

Reach out on the donation Slack channel or here — happy to update or hand the PR off.

cc @Kludex

dsfaccini added 2 commits May 8, 2026 16:35
Port of pydantic-ai's `Agent.to_a2a()` integration into this package, in
advance of the v2 deprecation on the pydantic-ai side. This is a near-verbatim
port of `pydantic_ai_slim/pydantic_ai/_a2a.py` so the API can be redesigned
in-tree if the maintainers prefer a different shape.
The previous >=0.5 floor was a typo from copying the plan-doc — pydantic-ai is
on v1.92.0 and the bridge depends on symbols (AbstractAgent, BinaryContent,
VideoUrl, …) that don't exist below 1.x.
@DouweM
Copy link
Copy Markdown

DouweM commented May 11, 2026

@echarles
Copy link
Copy Markdown
Member

General goal sounds good to me, I would add more docs in the README (this repo does not have separated docs yes) to show a before and after usage.

A few questions before testing the implementation:

see pydantic/pydantic-ai card 46).

This link is returning a 404 for me.

Any companion PR to this one in the the https://github.com/pydantic/pydantic-ai repo? the v2:prep is branch is not listed on https://github.com/pydantic/pydantic-ai/branches - The pydantic-ai docs will need to be updated also.

The migration message can simply be 'install fasta2a[pydantic-ai]

Sounds good, for now we don't have intent to introduce support for other frameworks (langchain..) but the classifier [pydantic-ai] can be setup already

...and import `agent_to_a2a'.

Is that import correct?

README: not touched. Suggested snippet in the card-46 plan doc if useful.

also link return 404 - the before/after usage may be there?

@echarles
Copy link
Copy Markdown
Member

Regarding the code, the _bridge.py has 100 less lines than the initial https://github.com/pydantic/pydantic-ai/blob/35d55f926484af7f0ca51884e9b6d4f69a04b620/pydantic_ai_slim/pydantic_ai/_a2a.py - maybe comments, can you confirm?

CI is failing, linting welcome.

dsfaccini added 5 commits May 14, 2026 13:22
- Collapse 3-line ValueError back to one line under fasta2a's 120-char limit
- Rewrite 'Using PydanticAI' to use the new bridge: install 'fasta2a[pydantic-ai]'
  and call 'agent_to_a2a(agent)' instead of 'agent.to_a2a()'
- Add note that 'Agent.to_a2a()' continues to work in pydantic-ai 1.x with a
  deprecation warning, and is removed in v2
pydantic-ai-slim requires Python>=3.10 but fasta2a supports >=3.9; without
the marker uv can't compute a universal lockfile (the resolver tries to pull
pydantic-ai-slim for Python 3.9 too). Added the marker on the optional dep
and regenerated uv.lock.
- README: rename 'Using PydanticAI' section + body to 'Pydantic AI' (two
  words), per Pydantic team's standard wording
- Bump example model openai:gpt-4.1 / gpt-4o -> gpt-5.5 in both README and
  bridge docstring
- pyproject.toml: add executionEnvironments override setting typeCheckingMode
  to 'basic' for the fasta2a/pydantic_ai directory. The bridge is a
  near-verbatim port of pydantic_ai._a2a and inherits its looser typing
  posture (118 strict-mode pyright errors in a 1:1 port). Can be tightened
  in a follow-up.
The strict-mode 'errors' on the bridge aren't a typing posture mismatch — they
are real bugs: the verbatim port is written against fasta2a's pre-A2A-v1-spec
schema (discriminated-union Part with kind/file fields), but upstream
collapsed Part into a single flat TypedDict in PRs datalayer#46/datalayer#47. Pyright is
correctly catching that the imported TextPart/DataPart symbols don't exist
and that part['kind']/part['file'] don't either. Fix is to rewrite the
part-conversion methods, not to silence pyright.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants