Pydantic AI is a Python framework designed for creating AI agents and LLM-powered applications. This skill offers patterns and architecture guidance along with tested code examples.
$ npx skills add https://github.com/pydantic/skills --skill building-pydantic-ai-agentsThis skill provides patterns and architecture guidance for building AI agents with Pydantic AI, a Python framework designed for LLM-powered applications. Learn how to implement agent tools, capabilities, streaming, and testing through practical code examples. The skill is compatible with 30+ agents via the agentskills.io standard, making it accessible across Claude Code, Codex, Cursor, and other platforms. It integrates seamlessly with Logfire for observability and can be extended with harness capabilities like Code Mode for sandboxed code execution. Whether you're prototyping a single-tool agent or building complex multi-capability systems, this skill provides the foundation and best practices needed.
Install the skill using the command: `$ npx skills add https://github.com/pydantic/skills --skill building-pydantic-ai-agents`
Creating AI agents using Pydantic AI
Adding tools and capabilities to agents
Defining agents from YAML/JSON specs
Streaming agent events and testing agent behavior
$ npx skills add https://github.com/pydantic/skills --skill building-pydantic-ai-agentsgit clone https://github.com/pydantic/skillsCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
I need to build an AI agent using Pydantic AI for [COMPANY]'s [INDUSTRY] workflow. The agent should handle [SPECIFIC_TASK] with structured outputs and error handling. Provide a complete example with Pydantic models, agent setup, and execution code using Python.
### AI Agent for Document Processing Workflow
```python
from pydantic_ai import Agent, AgentRunResult
from pydantic import BaseModel, Field
class DocumentSummary(BaseModel):
title: str = Field(..., description="Title of the document")
summary: str = Field(..., description="Concise summary")
key_points: list[str] = Field(..., description="Bullet points of key insights")
sentiment: str = Field(..., description="Overall sentiment (positive/neutral/negative)")
# Initialize agent with Pydantic model
doc_agent = Agent(
name="DocumentProcessor",
model="gpt-4o",
output_type=DocumentSummary,
system_prompt="""
You are a document processing assistant for [TechCorp].
Extract and structure information from the provided document.
Focus on technical content and business insights.
"""
)
# Example document
document = """
[TechCorp Product Roadmap 2024]
Our AI platform will launch Q3 with NLP capabilities and 99.9% uptime.
Key features include real-time analytics and multi-language support.
Customer feedback has been overwhelmingly positive.
"""
# Execute agent
result: AgentRunResult[DocumentSummary] = doc_agent.run("Process this document", document)
print("=== Document Analysis ===")
print(f"Title: {result.output.title}")
print(f"Sentiment: {result.output.sentiment}")
print("\nKey Points:")
for i, point in enumerate(result.output.key_points, 1):
print(f"{i}. {point}")
```
**Execution Output:**
```
=== Document Analysis ===
Title: TechCorp Product Roadmap 2024
Sentiment: positive
Key Points:
1. AI platform launch scheduled for Q3 2024
2. Includes NLP capabilities with 99.9% uptime guarantee
3. Features real-time analytics and multi-language support
4. Customer feedback has been overwhelmingly positive
```Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan