← all repositories
pydantic/pydantic-ai

FastAPI's creators want to fix AI agent frameworks

The Pydantic team built an agent framework that leans on type safety and validation instead of string-magic and hope.

17.6k stars Python AgentsApp Builders
pydantic-ai
Velocity · 7d
+25
★ / day
Trend
steady
star history

What it does Pydantic AI is a Python framework for building LLM agents and workflows. It wraps model calls, tool definitions, structured outputs, and dependency injection in typed, Pydantic-validated constructs. The pitch is straightforward: since half the ecosystem already uses Pydantic under the hood, why not use a framework built by the people who actually maintain it.

The interesting bit The framework treats type hints as a first-class concern, not decoration. Agents are generic over their dependencies and output types—Agent[SupportDependencies, SupportOutput]—so static checkers and IDEs can catch mismatches before runtime. It also bakes in durability: agents can survive restarts and transient API failures, which is the unglamorous part of “production-grade” that most demos skip.

Key highlights

  • Model-agnostic by design: supports OpenAI, Anthropic, Gemini, DeepSeek, Grok, Ollama, Bedrock, and roughly two dozen others, with a custom model interface for the rest.
  • Structured outputs are validated immediately; if the LLM returns malformed JSON, the agent is prompted to retry.
  • Dependency injection via RunContext lets you pass database connections, user sessions, or config into tools and dynamic instructions with full type safety.
  • Built-in observability through Pydantic Logfire (OpenTelemetry-based), plus evals, human-in-the-loop tool approval, and graph-based workflow definitions.
  • MCP and A2A protocol support for interoperability with external tools and other agents.

Caveats

  • The README’s “Hello World” is genuinely minimal—most real value sits in capabilities, graphs, and durable execution, which take more than five minutes to grasp.
  • Tight Logfire integration is advertised heavily; whether third-party OTel backends feel as smooth is less demonstrated.

Verdict Worth a look if you’re building agents that need to survive production traffic, not just demo scripts. Skip it if you want a thin, bring-your-own-everything wrapper or if you’re allergic to the Pydantic ecosystem’s opinions.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.