Pydantic AI is a modern, type-safe framework for building AI agents with native MCP support, perfect for production applications requiring type safety and reliable tool integration.
Structured outputs using Pydantic models with automatic validation
Native MCP (Model Context Protocol) support for tools - no extra configuration needed
Works with OpenAI, Ollama, Anthropic, and 100+ LLMs via LiteLLM
Built-in async support for high-performance applications
Fine-grained control (max_tokens, top_p, frequency_penalty, etc.)
Direct integration with MCP servers for automatic tool discovery
uv tool install superoptix --with "superoptix[frameworks-pydantic-ai]"
Get up and running with Pydantic AI in minutes
super agent pull developer
This pulls the developer agent playbook with:
llama3.1:8b)Uses Ollama by Default! (FREE, no API keys needed!)
# Just install Ollama and run: brew install ollama # macOS ollama pull llama3.1:8b super agent compile developer --framework pydantic-ai super agent run developer --framework pydantic-ai --goal "Implement a user registration API endpoint"
Also Works With Cloud Models: OpenAI GPT-4, Anthropic Claude, Google Gemini, and 100+ providers via LiteLLM
# Compile super agent compile developer --framework pydantic-ai # Evaluate baseline performance super agent evaluate developer # Optimize with GEPA (OPTIONAL) super agent compile developer --framework pydantic-ai --optimize super agent optimize developer --auto light --framework pydantic-ai --reflection-lm ollama/llama3.1:8b # Run your optimized agent super agent run developer --framework pydantic-ai --goal "Your task here"
Pydantic AI has native MCP support! Connect to MCP servers directly in your playbook for automatic tool discovery.
spec: mcp: enabled: true servers: - name: filesystem type: stdio config: command: "npx" args: ["-y", "@modelcontextprotocol/server-filesystem", "/private/tmp"] # Use /private/tmp on macOS (or /tmp on Linux) tool_prefix: "fs_" # Optional: prefix to avoid naming conflicts
Note: On macOS, use /private/tmp instead of /tmp. On Linux, use /tmp.
Choose between plain text (default) or structured output mode
Agent returns natural text responses, which works reliably with smaller models like llama3.1:8b.
# Default mode - no configuration needed # Output is plain text mapped to output fields spec: output_fields: - name: implementation type: str description: Code implementation
Uses Pydantic BaseModel for type-safe, validated responses. Requires larger models (70b+) for reliable results.
# Enable structured output spec: output_mode: structured # Opt-in output_fields: - name: implementation type: str description: Code implementation required: true optimization: optimize_field_descriptions: true # Optimize field descriptions
Fine-grained control over generation parameters
spec: language_model: provider: ollama model: llama3.1:8b max_tokens: 4000 # Default: 4000 (supports detailed responses) top_p: 0.9 # Optional: Nucleus sampling (0.0-1.0) frequency_penalty: 0.0 # Optional: Reduce repetition (-2.0 to 2.0) presence_penalty: 0.0 # Optional: Encourage new topics (-2.0 to 2.0)
Maximum number of tokens in the response
Nucleus sampling threshold (0.0-1.0)
What Gets Optimized & How It Works
The agent's system prompt (built from persona.role, persona.goal, persona.backstory, etc.)
Tool descriptions for better tool selection and usage (if MCP optimization enabled)
Pydantic model field descriptions for structured output (if field optimization enabled)
Example: GEPA typically expands instructions to be more explicit and structured, improving agent behavior consistency.
Minimal metric calls for quick verification
super agent optimize my_agent \ --framework pydantic-ai \ --max-metric-calls 3 \ --reflection-lm ollama/llama3.1:8b
Resource Warning: GEPA optimization is resource-intensive and makes many LLM API calls. Use local ollama/llama3.1:8b to avoid API costs. Cloud models (GPT-4, Claude) will incur significant charges ($5-100+ per optimization run).
| Option | Command | Time | API Calls | Use Case |
|---|---|---|---|---|
| Ultra Fast | --max-metric-calls 3 | ~30s-1m | ~3 | Verify it works |
| Super Light | --max-metric-calls 10 | ~1-2 min | ~10 | Quick test |
| ⭐ Light | --auto light | ~5-10 min | ~50-100 | Recommended |
| Medium | --auto medium | ~15-30 min | ~150-300 | Better results |
| Heavy | --auto heavy | ~30-60 min | ~300-600 | Production ready |
💡 Save money: Use --reflection-lm ollama/llama3.1:8b for free local optimization! Cloud models (GPT-4, Claude) will incur charges (~$0.50-100+ per optimization run).
Optimize Pydantic model field descriptions for better structured output
GEPA optimizes Pydantic model field descriptions (Field(description=...)) for structured output. This improves the model's understanding of what each output field should contain.
Requires: Structured output mode enabled (output_mode: structured) to use optimized descriptions.
spec: output_fields: - name: implementation type: string description: The code implementation of the feature required: true optimization: optimize_field_descriptions: true # Enable field description optimization optimizer: name: GEPA params: auto: light reflection_lm: ollama/llama3.1:8b
description: "The code implementation of the feature"
description: "Complete, production-ready code implementation with proper imports, error handling, and documentation. Include full function/class definitions, not pseudocode or descriptions."
Works with local Ollama models (FREE) or cloud providers
spec: language_model: provider: ollama model: llama3.1:8b # or llama3.1:70b for better quality api_base: http://localhost:11434 max_tokens: 4000 # Adjust based on response length needs top_p: 0.9 # Optional: Control output diversity
Setup:
# Install Ollama brew install ollama # macOS # or download from https://ollama.com # Pull model ollama pull llama3.1:8b # The pipeline automatically: # - Adds 'ollama:' prefix if missing # - Sets OLLAMA_BASE_URL with /v1 suffix # - Uses Pydantic AI's infer_model() for automatic model creation
Pydantic AI supports 100+ providers via LiteLLM. Just specify the provider and model:
spec: language_model: provider: google # or groq, together, bedrock, etc. model: gemini-pro
Full example with MCP, optimization, and all features
apiVersion: agent/v1 kind: AgentSpec metadata: name: Developer Assistant with MCP id: developer_mcp namespace: software version: 1.0.0 level: genies spec: language_model: provider: ollama model: llama3.1:8b api_base: http://localhost:11434 max_tokens: 4000 top_p: 0.9 input_fields: - name: feature_requirement type: str description: Feature to implement output_fields: - name: implementation type: str description: Code implementation persona: role: Software Developer goal: Write clean, efficient code with file system access backstory: I am an experienced developer with filesystem access through MCP. # MCP Configuration mcp: enabled: true servers: - name: filesystem type: stdio config: command: "npx" args: ["-y", "@modelcontextprotocol/server-filesystem", "/private/tmp"] # Use /private/tmp on macOS tool_prefix: "fs_" # Tool optimization - use actual MCP server tool names (WITHOUT prefix) optimization: optimize_tool_descriptions: true tool_names: ["read_file", "write_file", "list_directory"] feature_specifications: scenarios: - name: read_config_file input: feature_requirement: Read /private/tmp/config.json and extract the database URL expected_output: implementation: read_file config.json database URL extract optimization: optimize_field_descriptions: true # Optional: for structured output optimizer: name: GEPA params: reflection_lm: ollama/llama3.1:8b # Use forward slash for LiteLLM auto: light
SuperOptiX includes native LogFire integration for Pydantic AI agents
SuperOptiX provides native LogFire integration for Pydantic AI agents, giving you complete visibility into agent executions, LLM calls, tool usage, and performance metrics.
Track agent executions end-to-end
Monitor LLM calls and tool usage
Track token usage and costs
View traces in LogFire dashboard or local backends (Jaeger)
More optimization targets (all signatures), better for focused tasks
Built-in multi-agent handoffs, session management, guardrails support
Multi-agent teams, role-based collaboration, task delegation
Symptom: Unknown provider: llama3.1 or ModelHTTPError: 404
Solution: Ensure model string has provider prefix: ollama:llama3.1:8b. Check OLLAMA_BASE_URL includes /v1: http://localhost:11434/v1. Verify Ollama is running: curl http://localhost:11434/api/tags
Symptom: Evaluation scenarios failing
Solution: Check BDD scenario keywords are realistic. Lower threshold in evaluate() method (default is 0.6). Run GEPA optimization to improve instructions. Try different model (llama3.1:70b for more capability). Adjust model settings (max_tokens, top_p).
Symptom: Failed to initialize MCP server or tools not available
Solution: For stdio servers: Verify command exists (which npx). Check args are correct. Ensure MCP server package is installed. For remote servers: Verify URL is accessible. Check network connectivity. General: Check server logs, verify mcp package is installed (uv pip install mcp).
Symptom: None of the specified tools found. Available: ['read_file', 'write_file', ...]
Solution: Use actual MCP server tool names WITHOUT prefix. The optimizer queries the MCP server directly, which returns unprefixed tool names. The tool_prefix only affects runtime naming in the agent.
Symptom: ModuleNotFoundError: No module named 'pydantic_ai'
Solution: uv tool install superoptix --with "superoptix[frameworks-pydantic-ai]" or uv pip install "pydantic-ai>=2.31,<2.32"
Symptom: Optimization never completes or takes too long
Solution: Use --max-metric-calls 20 for quick test (~1-2 minutes). Use --auto light for balanced speed/quality (~5-10 minutes). Use smaller reflection model: --reflection-lm ollama/llama3.1:8b. Reduce training dataset size (fewer BDD scenarios).
Symptom: Agent returns JSON like {'action': 'do_something', 'params': {...}} instead of actual content
Solution: This was fixed in SuperOptiX 0.2.1. The template now uses plain text output mode. Update: uv pip install --upgrade superoptix. Recompile: super agent compile your_agent --framework pydantic-ai
Symptom: No '🛠️ Initialized MCP stdio server' message during run
Solution: Check playbook filename uses underscores: my_agent_playbook.yaml (not hyphens). Verify mcp.enabled: true in playbook. Check MCP server command is correct (command: npx, args: ['-y', '@modelcontextprotocol/server-filesystem', '/private/tmp']).