Add pydantic_ai bridge submodule (port from pydantic-ai _a2a.py)#55
Add pydantic_ai bridge submodule (port from pydantic-ai _a2a.py)#55dsfaccini wants to merge 7 commits into
pydantic_ai bridge submodule (port from pydantic-ai _a2a.py)#55Conversation
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.
|
@dsfaccini Please update https://github.com/datalayer/fasta2a#using-pydanticai! |
|
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 A few questions before testing the implementation: 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
Sounds good, for now we don't have intent to introduce support for other frameworks (langchain..) but the classifier
Is that import correct?
also link return 404 - the before/after usage may be there? |
|
Regarding the code, the CI is failing, linting welcome. |
- 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.
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(), thepydantic_ai._a2amodule, and thea2ainstall 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 'installfasta2a[pydantic-ai]and importagent_to_a2a'.What's in the diff
fasta2a/pydantic_ai/__init__.py— re-exportsagent_to_a2a,AgentWorker,worker_lifespanfasta2a/pydantic_ai/_bridge.py— 1-to-1 port ofpydantic_ai._a2a(~241 lines). Imports flipped: this submodule imports frompydantic_ai, not the other way around. The body is unchanged so you can see exactly what shipped today.pyproject.toml— addspydantic-ai = ['pydantic-ai-slim>=1.92']optional extra. Pinned to slim to avoid pulling the full LLM-provider matrix into anyone who installsfasta2a[pydantic-ai].Open for redirection — happy to iterate
This is intentionally a near-verbatim port so you can pick the API shape:
agent_to_a2a()function (current) vs. anAgentApplicationclass? Module layoutfasta2a.pydantic_ai(current) vs.fasta2a.bridges.pydantic_aiif you anticipate more bridges?pydantic-ai-slim>=1.92or the fullpydantic-ai? Slim is the conservative pick.tests/test_a2a.py; happy to port subset, or leave to you to test in your style.Sequencing
Marking this PR as draft because the pydantic-ai-side deprecation PR (a
v2:prepPR adding@deprecatedwarnings onAgent.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