Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

pydantic-ai

> AI 编程
Open source

AI Agent Framework, the Pydantic way

19.0K stars0 likes1 views
WebsiteGitHub

About

AI Agent Framework, the Pydantic way

Agents, realtime voice, image generation, embeddings. Every model, every interface, typed end to end.


Pydantic AI is the Python AI SDK: a typed, extensible agent loop with every model a string swap away. The same agent runs everywhere you need it: behind a web frontend, in the terminal, on a voice call, on a durable background queue, or as a plain object you call run() on. Image generation and embeddings come in the same box.

Pydantic AI Harness has everything an agent needs for complex, long-running work, snapped on as capabilities, from memory, sub-agents, and context management to a complete coding agent.

View the complete documentation at pydantic.dev/docs/ai.

What are you building?

From simple typed data extraction to complex, long-running multi-agent collaboration, Pydantic AI and Pydantic AI Harness have got you covered.

Coding agent

A complete coding agent in your terminal: workspace-rooted file access, allowlisted shell, repo orientation, planning, and context management that survives long sessions. Here with web search and a second-opinion advisor snapped on alongside:

bash
uv add pydantic-ai pydantic-ai-harness
python
from pydantic_ai import Agent
from pydantic_ai.capabilities import WebSearch
from pydantic_ai_harness import Advisor, Coder

agent = Agent(
    'anthropic:claude-fable-5',
    capabilities=[
        Coder(),  # files, shell, repo context, planning, sub-agents, context management
        WebSearch(),  # look up docs and error messages on the web
        Advisor('openai:gpt-5.6-sol'),  # a second opinion from another model when stuck
    ],
)
agent.to_cli_sync()

Coder is a regular combined capability, not a black box: use it whole, or use the blocks it bundles directly; the two are equivalent:

python
capabilities = [
    FileSystem('.'), Shell(cwd='.'), RepoContext(), Planning(), SubAgents(...),
    ClearToolResults(), WarnNearLimits(), ToolOutputLimits(),
]

Run the file and you're chatting with the agent in your terminal. To try it before writing any code, run the exported coder_agent with clai (the Pydantic AI CLI), via uvx:

bash
uvx --with pydantic-ai-harness clai -a pydantic_ai_harness.coder:coder_agent -m anthropic:claude-fable-5

Build this → Coder, from the Harness

Data extraction

Give the agent an output type and tools, and every run comes back validated and typed:

bash
uv add pydantic-ai
…

The @agent.tool function receives a RunContext that carries your dependencies in; the rest of its signature and its docstring become the tool schema, arguments are validated before your code runs, and the run is guaranteed to return a Sentiment, so your IDE, type checker, and the LLM all agree on the returned type.

Build this → Agents, Function Tools, and Structured Output

Durable workflow

Attach TemporalDurability and the same agent runs inside a Temporal workflow under durable execution: every model and tool call becomes a durable activity, so a run working through a background queue survives restarts, failures, and long waits:

bash
uv add "pydantic-ai[temporal]"
…

DBOS and Prefect attach the same way, first-party and co-maintained, with Restate, Kitaru, and Airflow integrations besides.

Build this → Durable Execution

Realtime voice

Put the same agent on a live voice session, tools and capabilities included:

bash
uv add "pydantic-ai[openai-realtime]"
…

The model calls your tools mid-conversation while it keeps talking, and every session is instrumented; voice is just another frontend, on OpenAI Realtime, Gemini Live, Azure, and xAI Grok Voice.

Build this → Realtime Voice

Image generation

Generate an image with a dedicated image model, no agent run required:

bash
uv add pydantic-ai
python
from pathlib import Path

from pydantic_ai import ImageGenerator

generator = ImageGenerator('openai:gpt-image-2')
result = generator.generate_sync('A minimalist logo for a coffee shop called Extract.')
Path('logo.png').write_bytes(result.image.data)

That standalone image API is for when your application decides; when an agent run decides, there is provider-native generation with output_type=BinaryImage for a typed image output, and the ImageGeneration capability with its fallbacks for models that generate no images of their own.

Build this → Image Generation

Why Pydantic AI

  • Any model, one Python API. Virtually every model and provider (OpenAI, Anthropic, Google, Bedrock, Azure AI Foundry, Groq, Mistral, xAI, Ollama, and dozens more), swappable with a string, or through the Pydantic AI Gateway: one key for all of them, with failover and cost monitoring built in. No flagship feature is locked to one vendor.

  • Typed end to end. Structured outputs, typed dependency injection, typed tools: your IDE, type checker, and coding agent all know what your agent returns, moving whole classes of errors from runtime to write-time. When plain control flow isn't enough, Pydantic Graph brings the same typing to graph-based workflows.

  • Measured, not vibes. OpenTelemetry-native instrumentation works with any OTel backend; one line lights up Pydantic Logfire for real-time debugging, tracing, and cost tracking backed by genai-prices. Pydantic Evals tests agent behavior the way pytest tests code.

  • Batteries, composably. One primitive, the capability, bundles tools, instructions, hooks, and model settings into reusable units. Core ships fundamentals like MCP and web search, the Harness ships everything else, and complete agents like Coder and Researcher are just capabilities composed: they come apart the way they went together. Or skip code entirely with YAML/JSON agent specs.

  • Every interface. One agent definition runs as a CLI, a built-in web chat, or realtime speech (OpenAI Realtime, Gemini Live, Azure, xAI Grok Voice); UI event streams (AG-UI, Vercel AI) connect it to your own frontend or anything else; and ACP (experimental) serves it as an editor agent.

  • Durable execution. First-party, co-maintained durable execution on Temporal, DBOS, Prefect, and Restate, plus external SDK integrations for Kitaru and Airflow. Agents survive restarts and run for days on the engine you already operate, with human-in-the-loop approval built in.

Built by the Pydantic team: Pydantic Validation is the validation layer of the OpenAI SDK, the Anthropic SDK, the Google ADK, LangChain, and most of the AI ecosystem (and the foundation FastAPI was built on). Pydantic AI brings that same feeling to agents.

Putting it together: a bank support agent

A typed support agent showing several features working together: dependency injection, function tools, structured output, a reusable capability bundling the customer context, and an [on-demand capability](https://pydantic.dev/docs/ai/capabilities/on

Issues· 1393 open

View all issuesOpen on GitHub
  • #9514

    [aw] CI Review failed

    pydanty:metaagentic-workflowsp:4-lowUpdated Oct 1, 2026
  • #9524

    SnowflakeModel: empty moderation stub in Cortex response causes UnexpectedModelBehavior

    pydanty:bugp:3-midUpdated Oct 1, 2026
  • #8704

    Provider responses with no usage object are recorded as zero tokens, not unknown

    bugpydanty:bugp:2-highneeds-maintainer-actionattention-pingedUpdated Oct 1, 2026
  • #8726

    AG-UI adapter asserts when a model emits reasoning after content

    bugpydanty:bugp:2-highneeds-maintainer-actionattention-pingedUpdated Oct 1, 2026
  • #9459

    feat: support `smolvm` sandboxes

    featurepydanty:featurep:3-midharnessUpdated Oct 1, 2026
  • #9345

    Harness: LLM-reviewed tool approvals (auto-approve low-risk calls, defer the rest to a human)

    pydanty:featurep:3-midharnessUpdated Oct 1, 2026
  • #9279

    InputGuardrail(parallel=True) doesn't cancel a streamed run

    bugpydanty:bugp:1-highestneeds-maintainer-actionUpdated Oct 1, 2026
  • #9248

    CodeMode serializes in-sandbox dispatch under `parallel_ordered_events`, so `asyncio.gather` is inert on every durable run

    Updated Oct 1, 2026
  • #9247

    Add a Daytona sandbox capability

    Updated Oct 1, 2026
  • #9245

    Add usage_update session notification support to ACP adapter

    pydanty:is-workingUpdated Oct 1, 2026

> Tags

Pythonagent-frameworkgenaillmpydantic

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedOct 1, 2026
CategoryAI 编程
PricingOpen source

> Related tools

G
GitHub Copilot
GitHub 官方 AI 编程助手,覆盖补全、Chat 与 Agent 模式。
C
Cursor
AI 原生代码编辑器,对话改代码、多文件 Agent 与规则体系是其核心。
S
skills
Skills for Real Engineers. Straight from my .agents directory.