Pydantic AI
TL;DR
Pydantic AI is the Pydantic team's MIT-licensed Python agent framework: a typed agent loop with validated structured output, dependency injection and a model string for most providers. Multi-agent work uses delegation through tools, hand-offs in code, or the separate pydantic-graph package. It suits Python teams that want type-checked agents.
Key facts
| Type | Framework |
|---|---|
| Languages / SDKs | Python |
| License | MIT |
| Pricing model | Open core |
| Orchestration pattern | Supervisor |
| GitHub stars | 20,278 (as of 2026-09-30) |
| GitHub forks | 2,828 |
| Last push | 2026-09-30 |
| Latest release | v1.107.7 |
| Repository | pydantic/pydantic-ai |
| Website | pydantic.dev |
| Documentation | pydantic.dev |
| Last verified | 2026-09-30 |
Key features
Agentwith anoutput_type: runs return validated, typed results, and tool arguments are validated before your code runs. (source)- Typed dependency injection: tools and instructions receive a
RunContextcarrying your own dependencies. (source) - Capabilities: reusable bundles of tools, instructions, hooks and model settings attached to an agent. (source)
- Multi-agent options: delegation through tools, programmatic hand-off, graph-based control flow and deep agents. (source)
- Deferred tools: calls that need human approval or run outside the process, resolved inline or by the caller. (source)
- Durable execution on Temporal, DBOS, Prefect, Restate, AWS Lambda and other engines. (source)
- MCP client over Streamable HTTP, SSE or stdio, plus provider-native MCP tools. (source)
- UI adapters for AG-UI and the Vercel AI SDK event stream protocols. (source)
Architecture and orchestration pattern
Pattern: Supervisor
The core object is an Agent: a model (chosen with a provider-prefixed string such as openai:...), instructions, tools, an output type and a dependencies type. A run loops between the model and tools until it can return a validated output. Capabilities package tools, instructions and hooks so they can be reused across agents, and toolsets bring in external tools, including MCP servers.
The multi-agent guide describes increasing levels: agent delegation (a tool on one agent runs another agent and control returns to the caller, optionally via the Harness SubAgents capability), programmatic hand-off (application code decides which agent runs next), graph-based control flow with the separate pydantic-graph package, and deep agents with planning and sandboxed execution. Agents are stateless and meant to be defined once at module level.
Conversation state is not stored by the framework: the docs recommend serializing message history to your own database, with StepPersistence in Pydantic AI Harness as a ready-made option. Durable execution integrations checkpoint model and tool calls so a run survives restarts.
Human in the loop
Human approval goes through deferred tools. A tool registered with requires_approval=True (or one that raises ApprovalRequired) is not executed immediately. Either a HandleDeferredToolCalls capability resolves the pending calls inside the run with your handler, or the run ends with a DeferredToolRequests output; the caller then collects approvals or denials and starts a new run with the previous message history and DeferredToolResults. The same mechanism hands a tool call to a frontend or background worker for external execution. The AG-UI adapter can surface tool approvals in a frontend, and the durable execution guide covers long human waits.
Protocols
| Protocol | Support | Note |
|---|---|---|
| MCP | Yes evidence | Client: agents connect to MCP servers over Streamable HTTP, SSE or stdio and can use provider-native MCP tools; the docs also show agents used inside your own MCP server's tools. |
| A2A | Partial evidence | Only through the separate fasta2a package (github.com/datalayer/fasta2a); V2 removed Agent.to_a2a() and the a2a extra. |
| AG-UI | Yes evidence | Server side: pydantic_ai.ui.ag_ui.AGUIAdapter (pydantic-ai-slim[ag-ui]) streams agent events to CopilotKit and other AG-UI frontends; the AG-UI README lists Pydantic AI as 1st party. |
Best for
- Python services that need validated, typed outputs from LLM calls
- Support or back-office agents with typed dependencies and approval-gated tools
- Long-running agents on an existing Temporal, DBOS or Prefect setup
- Research agents that delegate subtasks to specialist agents through tools
Not for
- Projects that need built-in A2A serving; it now requires the separate fasta2a package
- Teams that want a role-based crew abstraction instead of composing agents in code
- Non-Python stacks
Quickstart
pip install pydantic-ai from pydantic_ai import Agent, RunContext, UsageLimits
researcher = Agent('openai:gpt-5.2', name='researcher',
instructions='Return three short facts about the topic.')
writer = Agent('openai:gpt-5.2', name='writer',
instructions='Write a one-paragraph brief. Call research() first.')
@writer.tool
async def research(ctx: RunContext, topic: str) -> str:
"""Ask the research agent for facts about a topic."""
result = await researcher.run(topic, usage=ctx.usage) # share the usage budget
return result.output
# needs OPENAI_API_KEY
result = writer.run_sync('The Agent2Agent protocol',
usage_limits=UsageLimits(request_limit=6))
print(result.output)
print(result.usage)
Common pitfalls
- Requires Python 3.10+.
- Model strings need a provider prefix (
openai:...); in V2 the prefix-less form raisesUserError. Set the provider key, for exampleOPENAI_API_KEY. - V2 (stable since 2026-06-23 per the upgrade guide) moved many
Agent(...)arguments onto capabilities and removedAgent.to_a2a()andAgent.to_ag_ui(); the docs recommend upgrading through the latest V1 and clearing deprecation warnings first. - A bare
pip install pydantic-aino longer pulls extras such asag-ui,temporal,groqorbedrock; add the ones you use, or installpydantic-ai-slim[...]. - GitHub releases on 2026-09-30 include both v2.52.0 and v1.107.7; the repository's latest-release flag points at the V1 tag, so check which major you pin.
Pros
- Outputs and tool arguments are validated with Pydantic, so type checkers and IDEs see the real result types. (source)
- Switching model providers is a change of model string across a long list of providers. (source)
- Durable execution integrations exist for several engines, five of them co-maintained with the engine vendors. (source)
- AG-UI support is part of the package, including shared state and tool approval. (source)
- Instrumentation is plain OpenTelemetry, so any OTel backend works, not only Logfire. (source)
Cons
- V2 is a breaking release: many
Agent(...)arguments moved to capabilities and several V1 APIs were removed. (source) - A2A is no longer built in;
Agent.to_a2a()was removed in favour of the external fasta2a package. (source) - Some V2 default behaviors changed without deprecation warnings, such as the default
end_strategybecoming'graceful'. (source) - Subagents, memory, planning and step persistence helpers live in the separate
pydantic-ai-harnesspackage. (source) - The framework does not store conversations for you; persistence means serializing message history yourself or adding Harness. (source)
Alternatives
FAQ
Does Pydantic AI support MCP?
Yes, as a client over Streamable HTTP, SSE or stdio, plus provider-native MCP tools. The docs also show calling agents inside tools of an MCP server you write.
Does Pydantic AI support A2A and AG-UI?
AG-UI is built in through AGUIAdapter. A2A only works through the separate fasta2a package, because V2 removed Agent.to_a2a().
Is Pydantic AI free?
The framework is MIT-licensed. Pydantic sells Logfire (observability, with a free tier) and enterprise support for Pydantic AI; neither is required.
Which version should I use?
The upgrade guide lists V2.0.0 as stable since 2026-06-23, and V2 releases continue alongside V1 patch releases. New projects can start on V2; V1 code should follow the migration map.
How does multi-agent work in Pydantic AI?
Mostly by delegation: a tool on one agent runs another agent and returns its output. Hand-offs in application code and typed graphs via pydantic-graph cover more structured flows.
Sources
- Pydantic AI GitHub repository
- Pydantic AI documentation
- Pydantic AI README
- Pydantic AI product page
- Installation (Pydantic AI docs)
- Interfaces, including A2A via fasta2a (Pydantic AI docs)
- Dependencies (Pydantic AI docs)
- Capabilities overview (Pydantic AI docs)
- Multi-agent applications (Pydantic AI docs)
- Pydantic Graph (Pydantic AI docs)
- Deferred tools (Pydantic AI docs)
- Durable execution (Pydantic AI docs)
- Persistence (Pydantic AI docs)
- Model Context Protocol overview (Pydantic AI docs)
- MCP client (Pydantic AI docs)
- AG-UI protocol integration (Pydantic AI docs)
- UI event stream integrations (Pydantic AI docs)
- Models overview (Pydantic AI docs)
- Logfire and OpenTelemetry instrumentation (Pydantic AI docs)
- Pydantic AI Harness
- V1 to V2 migration map (Pydantic AI docs)
- Upgrade guide and changelog (Pydantic AI docs)
- Enterprise support for Pydantic AI
- Pydantic pricing (Logfire)
- Pydantic AI v2.52.0 release
- Pydantic AI v1.107.7 release
- fasta2a repository
- AG-UI README, supported integrations