# Pydantic AI — Production AI Agent Framework > Build production-ready AI agents in Python with type-safe structured outputs, dependency injection, and multi-model support. By the creators of Pydantic. ## Install Save the content below to `.claude/skills/` or append to your `CLAUDE.md`: ## Quick Use ```bash pip install pydantic-ai ``` ```python from pydantic_ai import Agent agent = Agent('claude-sonnet-4-20250514', system_prompt='Be concise.') result = agent.run_sync('What is the capital of France?') print(result.output) # "Paris" ``` ## What is Pydantic AI? Pydantic AI is a Python agent framework built by the Pydantic team. It brings type safety, structured outputs, and dependency injection to AI agent development — making agents as reliable and testable as regular Python code. **Answer-Ready**: Pydantic AI is a production-grade AI agent framework by the Pydantic team that provides type-safe structured outputs, dependency injection, streaming, and multi-model support for building reliable AI agents in Python. **Best for**: Python developers building production AI agents who need type safety and testability. **Works with**: Claude, GPT, Gemini, Groq, Mistral, Ollama. **Setup time**: Under 2 minutes. ## Core Features ### 1. Structured Outputs with Pydantic Models ```python from pydantic import BaseModel from pydantic_ai import Agent class CityInfo(BaseModel): name: str country: str population: int agent = Agent('claude-sonnet-4-20250514', result_type=CityInfo) result = agent.run_sync('Tell me about Tokyo') print(result.output) # CityInfo(name='Tokyo', country='Japan', population=13960000) ``` ### 2. Tool Definitions ```python from pydantic_ai import Agent, RunContext agent = Agent('claude-sonnet-4-20250514') @agent.tool async def get_weather(ctx: RunContext[str], city: str) -> str: # Fetch weather data return f"Sunny, 22C in {city}" result = agent.run_sync('Weather in London?') ``` ### 3. Dependency Injection ```python from dataclasses import dataclass @dataclass class Deps: db: Database user_id: str agent = Agent('claude-sonnet-4-20250514', deps_type=Deps) @agent.tool async def get_orders(ctx: RunContext[Deps]) -> list: return await ctx.deps.db.get_orders(ctx.deps.user_id) result = agent.run_sync('Show my orders', deps=Deps(db=db, user_id='123')) ``` ### 4. Streaming ```python async with agent.run_stream('Write a poem') as response: async for text in response.stream_text(): print(text, end='', flush=True) ``` ### 5. Multi-Model Support ```python from pydantic_ai.models import OpenAIModel, AnthropicModel agent = Agent(OpenAIModel('gpt-4o')) # OpenAI agent = Agent(AnthropicModel('claude-sonnet-4-20250514')) # Anthropic agent = Agent('gemini-1.5-pro') # Google agent = Agent(OpenAIModel('llama3', base_url='http://localhost:11434/v1')) # Ollama ``` ## FAQ **Q: How does it compare to LangChain?** A: Pydantic AI is more opinionated and type-safe. LangChain is broader but more complex. Pydantic AI focuses on making agents testable and production-ready. **Q: Can I use it with Claude?** A: Yes, Anthropic Claude is a first-class supported provider. **Q: Is it production ready?** A: Yes, built by the Pydantic team (whose validation library is used by 80% of Python AI projects). ## Source & Thanks > Created by [Pydantic Team](https://github.com/pydantic). Licensed under MIT. > > [pydantic/pydantic-ai](https://github.com/pydantic/pydantic-ai) — 10k+ stars ## 快速使用 ```bash pip install pydantic-ai ``` 三行代码创建类型安全的 AI 代理。 ## 什么是 Pydantic AI? Pydantic AI 是 Pydantic 团队打造的 Python 代理框架,将类型安全、结构化输出和依赖注入引入 AI 代理开发。 **一句话总结**:Pydantic AI 是生产级 AI 代理框架,提供类型安全的结构化输出、依赖注入、流式输出和多模型支持。 **适合人群**:需要类型安全和可测试性的 Python 开发者。**支持模型**:Claude、GPT、Gemini、Groq、Ollama。 ## 核心功能 ### 1. Pydantic 结构化输出 用 Pydantic 模型定义输出,自动验证。 ### 2. 工具定义 用装饰器定义工具函数,代理自动调用。 ### 3. 依赖注入 注入数据库、用户上下文等依赖,方便测试。 ### 4. 流式输出 异步流式返回文本或结构化数据。 ## 常见问题 **Q: 和 LangChain 比较?** A: Pydantic AI 更专注类型安全和可测试性,LangChain 更广泛但更复杂。 **Q: 生产就绪?** A: 是,Pydantic 团队出品(其验证库被 80% Python AI 项目使用)。 ## 来源与致谢 > [pydantic/pydantic-ai](https://github.com/pydantic/pydantic-ai) — 10k+ stars, MIT --- Source: https://tokrepo.com/en/workflows/97ebc107-3f1e-4957-ae96-119c42092096 Author: Skill Factory