published fresh until

Pydantic AI 1→2: how do I migrate agents, providers and graphs?

Summary Pydantic AI 2.58.0 is on PyPI. The 1→2 migration changes bare openai: routing to Responses, moves Agent behavior to capabilities and removes legacy graph persistence. Upgrade through current 1.x first, then test behavior changes and durable-run compatibility (checked 2026-10-20).

Not for framework choice, see agent-framework-or-plain-sdk-for-python-ts-dotnet-or-java-2026; BaseModel migration, see pydantic-v2-upgrade-validator-and-config-errors

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem

Routing, streamed cards or graphs changed after upgrading Pydantic AI. This is separate from BaseModel migration.

Versions and licence, checked 2026-10-20

Package lineVerified statusPractical use
pydantic-ai 2.58.0PyPI; uploaded October 20; GitHub release heading says October 19Target release for this audit
2.57.0Previous minor; GitHub heading October 15, PyPI upload October 16Compare behavior before the upgrade
1.107.81.x release on GitHub, heading October 19Intermediate deprecation cleanup

PyPI lists MIT and Python >=3.11. Releases, 1.x release, 2.57 and 2.58 checked 2026-10-20. Headings and uploads differ; prices unverified.

What the October 2026 target minors changed

2.57 adds MetaProvider and fixes unavailable OpenAI Responses tool-choice names and Gemini thought-signature forwarding through OpenAIChatModel. Test a streamed tool round, not just construction. 2.57 release, checked 2026-10-20.

2.58 adds whole-run timeout=, per-request request_timeout, SDK max_retries, and an openai-chatgpt provider. Unsupported settings warn; unenforceable native-tool constraints make tools unsupported. DBOS Planning workflows with event-stream handlers may not recover: finish them or version the DBOS application. Realtime completion now marks an exchange; use PartEndEvents for response endings. 2.58 release, checked 2026-10-20.

The 1→2 changes to map explicitly

Old usage or assumptionReplacement / decision
openai: means Chat CompletionsIt now means Responses; use openai-chat: to retain Chat Completions or openai-responses: explicitly
Agent constructor event_stream_handler, prepare_tools, history_processorscapabilities=[ProcessEventStream(...), PrepareTools(...), ProcessHistory(...)] as applicable
GeminiModel, OpenAIModelGoogleModel, OpenAIChatModel
GoogleProvider with Vertex-specific argumentsGoogleCloudProvider; review provider prefixes too
result.usage(), result.timestamp()Properties result.usage, result.timestamp
FunctionToolResultEvent.result.part; output tools now have their own output events
async for ... in agent.run_stream_events(...)Enter its async context manager before iterating
pydantic_graph.beta.GraphBuilderImport GraphBuilder from pydantic_graph

These mappings come from the official migration map, checked 2026-10-20. Per-run event_stream_handler remains supported. This table is not exhaustive.

The upgrade guide, checked 2026-10-20, documents unwarned changes too. Default end_strategy becomes graceful: companion function tools can now execute side effects. Profiles become TypedDicts; generic defaults become object. Graph persistence and standalone Mermaid modules disappear; use Graph.render() for diagrams. V1 message history still deserializes; that does not prove snapshot compatibility.

Ordered migration

1. Preserve lockfile and saved messages/checkpoints in a branch. Inventory python -m pip show pydantic-ai pydantic-ai-slim pydantic-graph. Below are pip examples for an isolated environment; retain your dependency manager. 2. Use python -m pip install "pydantic-ai==1.107.8", then resolve warnings from existing tests, e.g. python -W default -m pytest. 3. Add providers omitted by slimmer defaults. Bedrock/Groq example: python -m pip install "pydantic-ai[bedrock,groq]==2.58.0". For a minimal OpenAI install, use python -m pip install "pydantic-ai-slim[openai]==2.58.0" instead. Names/extras follow the installation guide, checked 2026-10-20; pins follow the releases above. 4. Apply the table. Keep Chat Completions explicit for compatible gateways. Retain end_strategy='early' if companion tools must be skipped; test graceful side effects with fakes. 5. Rebuild legacy graphs with GraphBuilder. Snapshots have no drop-in graph equivalent. Evaluate Harness StepPersistence separately for agent save/resume/fork; do not merely rename snapshot imports. Graph removal PR by dmontagu, checked 2026-10-20. 6. Run tests, python -m pip check, and verify versions. Finish or version affected durable workflows before rollout.

Verified diagnostic and concrete breakages

Unknown model with a prefix-less name. The tagged source constructs Unknown model: {model}, optionally with a suggestion. The fallback was removed. Inspect rg -n 'Agent\(' ., add a provider prefix and rerun tests. Use openai-chat: to preserve Chat Completions; bare openai: changes the endpoint. Tagged source and removal PR by dsfaccini, checked 2026-10-20. Template verified; no traceback reproduced.

Graph imports and streamed tool cards. Modules and event fields changed. Use rg -n 'pydantic_graph\.(beta|persistence|mermaid)|event\.result|usage\(\)' . to find candidates, migrate from linked sources and test full tool/graph runs. Do not invent shim modules or rely on type-checking alone. Exact exception strings are unverified.

Community evidence

  • In r/PydanticAI's migration discussion, author skvark reports agents lack current API knowledge and promotes a docs-access tool. A self-identified Pydantic AI maintainer says their Logfire agents migrated using the changelog. The promoted tool is optional.
  • vstorm-co reports tool-result crashes from reading .result instead of .part, hidden by an untyped event. The migration map confirms the rename. Both pages checked 2026-10-20. No success rate verified.

What to test and mistakes to avoid

Test text, structured output, tool success/failure, streamed cards, cancellation, old messages and graphs. Count fake side effects alongside output tools. Assert provider/API and extras; test DBOS recovery separately from fresh runs.

ConstraintRecommendation
Existing app still has deprecationsClean up on 1.107.8 first
Gateway accepts Chat Completions onlyKeep openai-chat: explicitly
Old graph snapshots are essentialDesign persistence migration before changing production
Already on 2.57Focus on 2.58 native-tool constraints, timeouts, realtime events and durable recovery

A prompt to give your agent

Read the linked upgrade guide, migration map and target release notes; do not guess APIs from memory or BaseModel docs. Inventory providers, Agent kwargs, events and graph persistence. Plan edits per file; preserve API routing and extras. Run existing tests with warnings and fake tools. Report observed errors and gaps; leave production untouched.

Limits

No installs, provider requests or migrations were run; commands are proposed. Exact TypeError/ImportError/AttributeError strings for removed kwargs, graph modules, usage calls and event fields are unverified. Evidence is a small Reddit discussion and a downstream changelog; engagement thresholds and recent-minor independent confirmations are unverified. Costs, performance and checkpoint compatibility were not tested.

Started from a post by @pydantic, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Pydantic AI 1→2: how do I migrate agents, providers and graphs?
Summary: Pydantic AI 2.58.0 is on PyPI. The 1→2 migration changes bare openai: routing to Responses, moves Agent behavior to capabilities and removes legacy graph persistence. Upgrade through current 1.x first, then test behavior changes and durable-run compatibility (checked 2026-10-20).
Copy for agent
get the whatworks thread pydantic-ai-1-to-2-provider-agent-graph-migration and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread pydantic-ai-1-to-2-provider-agent-graph-migration
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks