{"id":22422887,"url":"https://github.com/pydantic/pydantic-ai","last_synced_at":"2026-07-06T11:28:23.688Z","repository":{"id":263673556,"uuid":"818331198","full_name":"pydantic/pydantic-ai","owner":"pydantic","description":"AI Agent Framework, the Pydantic way","archived":false,"fork":false,"pushed_at":"2026-07-03T00:05:28.000Z","size":200847,"stargazers_count":18164,"open_issues_count":548,"forks_count":2292,"subscribers_count":113,"default_branch":"main","last_synced_at":"2026-07-03T00:17:22.049Z","etag":null,"topics":["agent-framework","genai","llm","pydantic","python"],"latest_commit_sha":null,"homepage":"https://pydantic.dev/pydantic-ai","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pydantic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2024-06-21T15:55:04.000Z","updated_at":"2026-07-03T00:05:30.000Z","dependencies_parsed_at":"2024-11-19T20:39:05.121Z","dependency_job_id":"0ee1cf70-cc08-449f-aed0-8877baf85a88","html_url":"https://github.com/pydantic/pydantic-ai","commit_stats":null,"previous_names":["pydantic/pydantic-ai"],"tags_count":270,"template":false,"template_full_name":null,"purl":"pkg:github/pydantic/pydantic-ai","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pydantic%2Fpydantic-ai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pydantic%2Fpydantic-ai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pydantic%2Fpydantic-ai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pydantic%2Fpydantic-ai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pydantic","download_url":"https://codeload.github.com/pydantic/pydantic-ai/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pydantic%2Fpydantic-ai/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35117336,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-04T02:00:05.987Z","response_time":113,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agent-framework","genai","llm","pydantic","python"],"created_at":"2024-12-05T18:02:11.635Z","updated_at":"2026-07-06T11:28:23.648Z","avatar_url":"https://github.com/pydantic.png","language":"Python","funding_links":[],"categories":["AI Agent Frameworks","Agent Development Frameworks","Agent Categories","A01_文本生成_文本对话","python","Libraries by Language","Agents \u0026 Orchestration","🏗️ Reference Implementations \u0026 Case Studies","Python","Recently Updated","Agent Frameworks","智能体 Agents","🤖 AI Agents","Python Libraries","Design Primitives","Frameworks","Tools","Agentic Framework","Repos","\u003ca id=\"tools\"\u003e\u003c/a\u003e🛠️ Tools","MCP 服务器精选列表","🧱 Agent Frameworks","Agentic AI ![](https://img.shields.io/badge/_-AGENTIC-22d3ee?style=flat-square\u0026logo=openai\u0026logoColor=white)","APIs and HTTP Requests","Agent","Large Language Models (LLMs)","Agentic Frameworks","Tools \u0026 Libraries","Browser Automation","Building","5 · Evaluation infrastructure (the eval stack: datasets, scorers, online/offline, tracing, CI)","Official Resources","Librerías para usar NLP en español","Orchestration Frameworks","AI Frameworks \u0026 SDKs","Agent框架","2024-2026 重要项目","Agent Integration \u0026 Deployment Tools","Agentic Workflow","Machine Learning","1. Agent Frameworks (Production-Ready)","\u003ca name=\"Python\"\u003e\u003c/a\u003ePython","2. Libraries \u0026 Frameworks","Code Execution","Frameworks \u0026 Libraries","Tools and Code","Multi-Agent Orchestration","🔗 Integration \u0026 Utility Tools","4. Agentic AI \u0026 Multi-Agent Systems","Browse The Shelves","📂 By Category","Best starting points","Agent SDKs \u0026 Frameworks","Agent Development Platforms","Catalog","Orchestration","⚡ Quick Picks","Agentic Systems","3）参考实现与开源工具（GitHub）"],"sub_categories":["General Agent Frameworks","\u003ca name=\"Pydantic AI\"\u003e\u003c/a\u003ePydantic AI","大语言对话模型及数据","Python","Agent Frameworks","T11 / T12 · Orchestration \u0026 Multi-Agent","[Dec 04, 2024](/content/2024/12/04/README.md)","Community","Frameworks \u0026 Libraries","Task Runners \u0026 Orchestration","Bleeding Edge ⚗️","💻 开发与代码执行","General Purpose","Agentic frameworks","Autonomous LLM Agents","Voice \u0026 Realtime Agents","Testing","5a · Eval frameworks \u0026 harnesses (code-first test-runners)","Modelos de Embeddings para Sentence Similarity y Semantic Search","AI Application Development","Single Agent","Type-Safe \u0026 Structured LLM Libraries","Local LLM developer tools","🔧 Development \u0026 Version Control","Lightweight \u0026 Typed","Harness Architecture \u0026 Orchestration","Agent Framework","Community Extensions","编码与智能体 Harness"],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://ai.pydantic.dev/\"\u003e\n    \u003cpicture\u003e\n      \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://ai.pydantic.dev/img/pydantic-ai-dark.svg\"\u003e\n      \u003cimg src=\"https://ai.pydantic.dev/img/pydantic-ai-light.svg\" alt=\"Pydantic AI\"\u003e\n    \u003c/picture\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003ch3\u003eGenAI Agent Framework, the Pydantic way\u003c/h3\u003e\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://github.com/pydantic/pydantic-ai/actions/workflows/ci.yml?query=branch%3Amain\"\u003e\u003cimg src=\"https://github.com/pydantic/pydantic-ai/actions/workflows/ci.yml/badge.svg?event=push\" alt=\"CI\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://coverage-badge.samuelcolvin.workers.dev/redirect/pydantic/pydantic-ai\"\u003e\u003cimg src=\"https://coverage-badge.samuelcolvin.workers.dev/pydantic/pydantic-ai.svg\" alt=\"Coverage\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://pypi.python.org/pypi/pydantic-ai\"\u003e\u003cimg src=\"https://img.shields.io/pypi/v/pydantic-ai.svg\" alt=\"PyPI\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/pydantic/pydantic-ai\"\u003e\u003cimg src=\"https://img.shields.io/pypi/pyversions/pydantic-ai.svg\" alt=\"versions\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/pydantic/pydantic-ai/blob/main/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/pydantic/pydantic-ai.svg?v\" alt=\"license\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://logfire.pydantic.dev/docs/join-slack/\"\u003e\u003cimg src=\"https://img.shields.io/badge/Slack-Join%20Slack-4A154B?logo=slack\" alt=\"Join Slack\" /\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n---\n\n**Documentation**: [ai.pydantic.dev](https://ai.pydantic.dev/)\n\n---\n\n### \u003cem\u003ePydantic AI is a Python agent framework designed to help you quickly, confidently, and painlessly build production grade applications and workflows with Generative AI.\u003c/em\u003e\n\n\nFastAPI revolutionized web development by offering an innovative and ergonomic design, built on the foundation of [Pydantic Validation](https://docs.pydantic.dev) and modern Python features like type hints.\n\nYet despite virtually every Python agent framework and LLM library using Pydantic Validation, when we began to use LLMs in [Pydantic Logfire](https://pydantic.dev/logfire), we couldn't find anything that gave us the same feeling.\n\nWe built Pydantic AI with one simple aim: to bring that FastAPI feeling to GenAI app and agent development.\n\n## Why use Pydantic AI\n\n1. **Built by the Pydantic Team**:\n[Pydantic Validation](https://docs.pydantic.dev/latest/) is the validation layer of the OpenAI SDK, the Google ADK, the Anthropic SDK, LangChain, LlamaIndex, AutoGPT, Transformers, CrewAI, Instructor and many more. _Why use the derivative when you can go straight to the source?_ :smiley:\n\n2. **Model-agnostic**:\nSupports virtually every [model](https://ai.pydantic.dev/models/overview) and provider: OpenAI, Anthropic, Gemini, DeepSeek, Grok, Cohere, Mistral, and Perplexity; Azure AI Foundry, Amazon Bedrock, Google Vertex AI, Ollama, LiteLLM, Groq, OpenRouter, Together AI, Fireworks AI, Cerebras, Hugging Face, GitHub, Heroku, Vercel, Nebius, OVHcloud, Alibaba Cloud, SambaNova, and Outlines. If your favorite model or provider is not listed, you can easily implement a [custom model](https://ai.pydantic.dev/models/overview#custom-models).\n\n3. **Seamless Observability**:\nTightly [integrates](https://ai.pydantic.dev/logfire) with [Pydantic Logfire](https://pydantic.dev/logfire), our general-purpose OpenTelemetry observability platform, for real-time debugging, evals-based performance monitoring, and behavior, tracing, and cost tracking. If you already have an observability platform that supports OTel, you can [use that too](https://ai.pydantic.dev/logfire#alternative-observability-backends).\n\n4. **Fully Type-safe**:\nDesigned to give your IDE or AI coding agent as much context as possible for auto-completion and [type checking](https://ai.pydantic.dev/agents#static-type-checking), moving entire classes of errors from runtime to write-time for a bit of that Rust \"if it compiles, it works\" feel.\n\n5. **Powerful Evals**:\nEnables you to systematically test and [evaluate](https://ai.pydantic.dev/evals) the performance and accuracy of the agentic systems you build, and monitor the performance over time in Pydantic Logfire.\n\n6. **MCP, A2A, and UI**:\nIntegrates the [Model Context Protocol](https://ai.pydantic.dev/mcp/overview), [Agent2Agent](https://ai.pydantic.dev/a2a), and various [UI event stream](https://ai.pydantic.dev/ui/overview) standards to give your agent access to external tools and data, let it interoperate with other agents, and build interactive applications with streaming event-based communication.\n\n7. **Human-in-the-Loop Tool Approval**:\nEasily lets you flag that certain tool calls [require approval](https://ai.pydantic.dev/deferred-tools#human-in-the-loop-tool-approval) before they can proceed, possibly depending on tool call arguments, conversation history, or user preferences.\n\n8. **Durable Execution**:\nEnables you to build [durable agents](https://ai.pydantic.dev/durable_execution/overview/) that can preserve their progress across transient API failures and application errors or restarts, and handle long-running, asynchronous, and human-in-the-loop workflows with production-grade reliability.\n\n9. **Streamed Outputs**:\nProvides the ability to [stream](https://ai.pydantic.dev/output#streamed-results) structured output continuously, with immediate validation, ensuring real time access to generated data.\n\n10. **Graph Support**:\nProvides a powerful way to define [graphs](https://ai.pydantic.dev/graph) using type hints, for use in complex applications where standard control flow can degrade to spaghetti code.\n\nRealistically though, no list is going to be as convincing as [giving it a try](#next-steps) and seeing how it makes you feel!\n\n## Hello World Example\n\nHere's a minimal example of Pydantic AI:\n\n```python\nfrom pydantic_ai import Agent\n\n# Define a very simple agent including the model to use, you can also set the model when running the agent.\nagent = Agent(\n    'anthropic:claude-sonnet-4-6',\n    # Register static instructions using a keyword argument to the agent.\n    # For more complex dynamically-generated instructions, see the example below.\n    instructions='Be concise, reply with one sentence.',\n)\n\n# Run the agent synchronously, conducting a conversation with the LLM.\nresult = agent.run_sync('Where does \"hello world\" come from?')\nprint(result.output)\n\"\"\"\nThe first known use of \"hello, world\" was in a 1974 textbook about the C programming language.\n\"\"\"\n```\n\n_(This example is complete, it can be run \"as is\", assuming you've [installed the `pydantic_ai` package](https://ai.pydantic.dev/install))_\n\nThe exchange will be very short: Pydantic AI will send the instructions and the user prompt to the LLM, and the model will return a text response.\n\nNot very interesting yet, but we can easily add [tools](https://ai.pydantic.dev/tools), [dynamic instructions](https://ai.pydantic.dev/agents#instructions), and [structured outputs](https://ai.pydantic.dev/output) to build more powerful agents.\n\n## Tools \u0026 Dependency Injection Example\n\nHere is a concise example using Pydantic AI to build a support agent for a bank:\n\n**(Better documented example [in the docs](https://ai.pydantic.dev/#tools-dependency-injection-example))**\n\n```python\nfrom dataclasses import dataclass\n\nfrom pydantic import BaseModel, Field\nfrom pydantic_ai import Agent, RunContext\n\nfrom bank_database import DatabaseConn\n\n\n# SupportDependencies is used to pass data, connections, and logic into the model that will be needed when running\n# instructions and tool functions. Dependency injection provides a type-safe way to customise the behavior of your agents.\n@dataclass\nclass SupportDependencies:\n    customer_id: int\n    db: DatabaseConn\n\n\n# This Pydantic model defines the structure of the output returned by the agent.\nclass SupportOutput(BaseModel):\n    support_advice: str = Field(description='Advice returned to the customer')\n    block_card: bool = Field(description=\"Whether to block the customer's card\")\n    risk: int = Field(description='Risk level of query', ge=0, le=10)\n\n\n# This agent will act as first-tier support in a bank.\n# Agents are generic in the type of dependencies they accept and the type of output they return.\n# In this case, the support agent has type `Agent[SupportDependencies, SupportOutput]`.\nsupport_agent = Agent(\n    'openai:gpt-5.2',\n    deps_type=SupportDependencies,\n    # The response from the agent will, be guaranteed to be a SupportOutput,\n    # if validation fails the agent is prompted to try again.\n    output_type=SupportOutput,\n    instructions=(\n        'You are a support agent in our bank, give the '\n        'customer support and judge the risk level of their query.'\n    ),\n)\n\n\n# Dynamic instructions can make use of dependency injection.\n# Dependencies are carried via the `RunContext` argument, which is parameterized with the `deps_type` from above.\n# If the type annotation here is wrong, static type checkers will catch it.\n@support_agent.instructions\nasync def add_customer_name(ctx: RunContext[SupportDependencies]) -\u003e str:\n    customer_name = await ctx.deps.db.customer_name(id=ctx.deps.customer_id)\n    return f\"The customer's name is {customer_name!r}\"\n\n\n# The `tool` decorator let you register functions which the LLM may call while responding to a user.\n# Again, dependencies are carried via `RunContext`, any other arguments become the tool schema passed to the LLM.\n# Pydantic is used to validate these arguments, and errors are passed back to the LLM so it can retry.\n@support_agent.tool\nasync def customer_balance(\n        ctx: RunContext[SupportDependencies], include_pending: bool\n) -\u003e float:\n    \"\"\"Returns the customer's current account balance.\"\"\"\n    # The docstring of a tool is also passed to the LLM as the description of the tool.\n    # Parameter descriptions are extracted from the docstring and added to the parameter schema sent to the LLM.\n    balance = await ctx.deps.db.customer_balance(\n        id=ctx.deps.customer_id,\n        include_pending=include_pending,\n    )\n    return balance\n\n\n...  # In a real use case, you'd add more tools and a longer system prompt\n\n\nasync def main():\n    deps = SupportDependencies(customer_id=123, db=DatabaseConn())\n    # Run the agent asynchronously, conducting a conversation with the LLM until a final response is reached.\n    # Even in this fairly simple case, the agent will exchange multiple messages with the LLM as tools are called to retrieve an output.\n    result = await support_agent.run('What is my balance?', deps=deps)\n    # The `result.output` will be validated with Pydantic to guarantee it is a `SupportOutput`. Since the agent is generic,\n    # it'll also be typed as a `SupportOutput` to aid with static type checking.\n    print(result.output)\n    \"\"\"\n    support_advice='Hello John, your current account balance, including pending transactions, is $123.45.' block_card=False risk=1\n    \"\"\"\n\n    result = await support_agent.run('I just lost my card!', deps=deps)\n    print(result.output)\n    \"\"\"\n    support_advice=\"I'm sorry to hear that, John. We are temporarily blocking your card to prevent unauthorized transactions.\" block_card=True risk=8\n    \"\"\"\n```\n\n## Next Steps\n\nTo try Pydantic AI for yourself, [install it](https://ai.pydantic.dev/install) and follow the instructions [in the examples](https://ai.pydantic.dev/examples/setup).\n\nRead the [docs](https://ai.pydantic.dev/agents/) to learn more about building applications with Pydantic AI.\n\nRead the [API Reference](https://ai.pydantic.dev/api/agent/) to understand Pydantic AI's interface.\n\nJoin [Slack](https://logfire.pydantic.dev/docs/join-slack/) or file an issue on [GitHub](https://github.com/pydantic/pydantic-ai/issues) if you have any questions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpydantic%2Fpydantic-ai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpydantic%2Fpydantic-ai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpydantic%2Fpydantic-ai/lists"}