Skip to content

chore(ai): support pydantic-ai v2#9973

Draft
Light2Dark wants to merge 7 commits into
mainfrom
chore/pydantic-ai-v2
Draft

chore(ai): support pydantic-ai v2#9973
Light2Dark wants to merge 7 commits into
mainfrom
chore/pydantic-ai-v2

Conversation

@Light2Dark

@Light2Dark Light2Dark commented Jun 24, 2026

Copy link
Copy Markdown
Member

📝 Summary

Motivation: less bugs, capability features, better pydantic-ai support

  • Remove old pydantic-ai v1 compatibility shims (require_vercel_ai_sdk_support, model_dump fallbacks, AnthropicModelProfile.from_profile, explicit Anthropic temperature handling).
  • Adapt to v2 API changes: ModelProfile as TypedDict (.get() access), Agent[object, ...] typing, FunctionToolset without None type param.
  • Fix OpenRouter test model IDs to use documented openrouter/<vendor>/<model> slugs — bare openrouter/gpt-4 breaks under v2 because profile resolution is eager and requires the upstream vendor prefix.
  • Reorder helper cells in the pydantic-ai chat example so underscore-prefixed helpers are defined before custom_model.

📋 Pre-Review Checklist

  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable).
  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
  • Video or media evidence is provided for any visual changes (optional).

✅ Merge Checklist

  • I have read the contributor guidelines.
  • Documentation has been updated where applicable, including docstrings for API changes.
  • Tests have been added for the changes made.

Made with Cursor

Review in cubic

@vercel

vercel Bot commented Jun 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Jun 26, 2026 4:44am

Request Review

@Light2Dark

Light2Dark commented Jun 24, 2026

Copy link
Copy Markdown
Member Author

pydantic-ai-slim: dependency changes (1.54.0 → 2.0.0)

Comparison of declared dependency constraints between pydantic-ai-slim 1.54.0 and 2.0.0.

Sources:

Core deps (always installed with slim)

Dependency 1.54.0 2.0.0
pydantic-graph ==1.54.0 ==2.0.0
pydantic >=2.10 >=2.12 (via pydantic-graph)
genai-prices >=0.0.48 >=0.0.62
Docstring tooling griffe>=1.14.0 griffelib>=2.0 (direct; no griffe CLI stack)
httpx >=0.27 >=0.27 (unchanged)
opentelemetry-api >=1.28.0 >=1.28.0 (unchanged)
typing-inspection >=0.4.0 >=0.4.0 (unchanged)

Extra-specific mins (only if you use that extra)

Extra 1.54.0 min 2.0.0 min Notes
openai openai>=2.11.0 openai>=2.29.0 Biggest practical bump
anthropic anthropic>=0.75.0 anthropic>=0.108.0
google google-genai>=1.56.0 google-genai>=1.70.0 vertexai extra removed; use google
bedrock boto3>=1.42.14 boto3>=1.42.63 Small floor bump
openai tiktoken>=0.12.0 tiktoken>=0.12.0 Unchanged
mcp mcp>=1.25,<2 + fastmcp>=2.14 fastmcp-slim[client]>=3.3.0 Different MCP stack entirely

@akshayka

Copy link
Copy Markdown
Contributor

If Pydantic AI is popular, then increasing the lower bound in this way will prevent users from using other packages that rely on older pydantic-ai < 2.0.0.

@Light2Dark, did you consider adding support for >= 2.0 without removing support for < 2.0?

Light2Dark and others added 5 commits June 26, 2026 12:16
Bump the minimum pydantic-ai version to 2.0 and drop v1 compatibility
shims now that profiles are TypedDicts and model construction validates
profiles eagerly.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Light2Dark

Light2Dark commented Jun 26, 2026

Copy link
Copy Markdown
Member Author

If Pydantic AI is popular, then increasing the lower bound in this way will prevent users from using other packages that rely on older pydantic-ai < 2.0.0.

@Light2Dark, did you consider adding support for >= 2.0 without removing support for < 2.0?

It's possible, and maybe we can support it for some time. However, if v2 makes more changes, we can't guarantee newer versions don't break, and we shouldn't cap it imo, a lot of bug fixes gets shipped as new models, APIs get released. It is an increase in our maintenance cost to support both.

I'll see if we can support both for the time being.

@Light2Dark Light2Dark force-pushed the chore/pydantic-ai-v2 branch from f6a1877 to 2c6089a Compare June 26, 2026 04:36
@Light2Dark Light2Dark changed the title chore(ai): migrate to pydantic-ai v2 chore(ai): support pydantic-ai v2 Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants