Pydantic AI
Provide a Python-first, model-agnostic agent framework that brings the 'FastAPI feeling' to GenAI by making Pydantic-validated structured output, type-safe dependency injection, and a graph-based async agent loop the primary surface for production LLM applications.
Description
Pydantic AI is the MIT-licensed Python agent framework from the Pydantic team. The framework is built around an Agent class generic in both a dependency type and an output type, so each agent run is a strongly typed function from inputs to a Pydantic-validated result. Its distinguishing thesis: structured output via Pydantic models is the primary action format. Model-agnostic across major providers (OpenAI, Anthropic, Gemini, DeepSeek, Cohere, Mistral, Bedrock, Ollama, Groq, OpenRouter, …); MCP-first toolset shape; durable execution via TemporalAgent, DBOSAgent, PrefectAgent, RestateAgent wrappers.
Solution
Agent class generic in deps_type and output_type. Agent.run() returns AgentRunResult; Agent.iter() exposes the run as a pydantic-graph of nodes — UserPromptNode → ModelRequestNode → CallToolsNode → End. UsageLimits caps requests/tokens/tool-calls before each request and raises UsageLimitExceeded on breach.
Primary use cases
- type-safe agents with Pydantic-validated final answers
- tool-using agents with dependency injection (deps_type / RunContext.deps)
- MCP-tool integration in Python
- durable agents via Temporal/DBOS/Prefect/Restate wrappers
Open the full interactive page →
Diagram, neighbourhood map, code examples, related patterns and full provenance.