Pydantic AI with PraisonAI
Run PraisonAI agents through Pydantic AI via praisonai-frameworks
from praisonaiagents import Agent
agent = Agent(
name="Calculator",
instructions="Return only the numeric answer.",
llm="openai/gpt-4o-mini",
)
agent.start("What is 3 + 3?")The same agent can run through Pydantic AI when you set framework: pydantic_ai in agents YAML — or use the Agent class directly as above.
Quick Start
- Install
bash pip install "praisonai[pydantic-ai]" export OPENAI_API_KEY=sk-... - Create agents.yaml
yaml framework: pydantic_ai topic: math roles: calculator: role: Calculator goal: Compute exactly backstory: Return only the numeric answer. tasks: add: description: What is 3 + 3? expected_output: "6" - Run
bash praisonai agents.yaml --framework pydantic_ai
Models
| Model | API key |
|---|---|
openai/gpt-4o-mini | OPENAI_API_KEY |
gemini-2.0-flash | GOOGLE_API_KEY or GEMINI_API_KEY |
Supported Patterns
| Phase | Pattern | Status |
|---|---|---|
| 1 | Single role, single task | Supported |
| 2 | Sequential tasks with context: | Supported |
| 3 | handoff.to (single task → delegation tools) | Supported |
Handoffs
Use the same handoff.to pattern as OpenAI Agents — one router role with a single task, specialists without tasks:
framework: pydantic_ai
topic: language help
roles:
triage:
role: Triage Agent
handoff:
to:
- English Agent
tasks:
route:
description: Help with {topic}
english:
role: English Agent
goal: Reply in English only
backstory: English specialist.Multi-task configs with handoff.to fall back to sequential execution (OpenAI parity).
Migrate from Pydantic AI
praisonai migrate converts Pydantic AI code to PraisonAI automatically.
- Point migrate at your Pydantic AI project
bash praisonai migrate ./my-pydantic-ai-app - What gets rewritten
Pydantic AI PraisonAI from pydantic_ai import Agentfrom praisonaiagents import Agentagent.run_sync("...")agent.start("...") - Apply the changes
bash praisonai migrate ./my-pydantic-ai-app --apply
Doctor Check
The Pydantic AI runtime card reports:
| Capability | Status |
|---|---|
agent_creation | ✅ Supported |
tool_execution | ✅ Supported |
sequential_execution | ✅ Supported |
handoff_support | ✅ Supported |
Limitations
| Feature | Status |
|---|---|
| pydantic-graph workflows | Not used |
| Agent spec YAML bridge | Not supported |
| Built-in capabilities (WebSearch, Thinking) | Not mapped |
Workflow YAML with framework: pydantic_ai | Not supported — raises ValueError |
output_schema / structured deps | Not mapped in v1 |
| A2A broker | Not supported |
Best Practices
Use Phase 1 for simple tasks
Start with a single role and single task to validate your setup before adding complexity.
Use Phase 2 for dependent steps
Add context: to tasks when each step needs output from the previous one.
Use Phase 3 for routing
Keep the router role to a single task with handoff.to; multi-task routers fall back to sequential.
Match model to API key
Set OPENAI_API_KEY for openai/ prefixed models and GOOGLE_API_KEY for Gemini models to avoid auth errors.
Migrate existing Pydantic AI code
Use praisonai migrate ./your-app to preview conversion before applying with --apply.