This repository contains four standalone demos showcasing Pydantic AI integrated with Temporal's durable execution.
Inspired by the OpenAI cookbook examples, these demos show different patterns of agent orchestration using OpenAI models with Pydantic AI, from simple single-agent workflows to complex multi-agent research systems with interactive user clarifications.
For detailed information about the research agents in this repo, see pydantic_demos/workflows/research_agents/README.md
More Temporal Pydantic AI samples can be found in Temporal's samples-python repository.
- Python 3.10+ - Required for the demos
- Temporal Server - Must be running locally on
localhost:7233
- OpenAI API Key - Set as environment variable
OPENAI_API_KEY
(note, you will need enough quota on in your OpenAI account to run this demo) - PDF Generation Dependencies - Required for PDF output (optional)
# Install Temporal CLI
curl -sSf https://temporal.download/cli.sh | sh
# Start Temporal server
temporal server start-dev
- Clone this repository
- Install dependencies:
uv sync
- Set your OpenAI API key:
export OPENAI_API_KEY="your-api-key-here"
Only used in Demo 4: Multi-Agent Interactive Research Workflow
For PDF generation functionality, you'll need WeasyPrint and its system dependencies:
brew install weasyprint
# OR install system dependencies for pip installation:
brew install pango glib gtk+3 libffi
# For package installation:
sudo apt install weasyprint
# OR for pip installation:
sudo apt install python3-pip libpango-1.0-0 libpangoft2-1.0-0 libharfbuzz-subset0
# For package installation:
sudo dnf install weasyprint
# OR for pip installation:
sudo dnf install python-pip pango
- Install Python from Microsoft Store
- Install MSYS2 from https://www.msys2.org/
- In MSYS2 shell:
pacman -S mingw-w64-x86_64-pango
- Set environment variable:
WEASYPRINT_DLL_DIRECTORIES=C:\msys64\mingw64\bin
Note: PDF generation gracefully degrades when dependencies are unavailable - workflows will still generate markdown reports.
In one terminal, start the worker that will handle all workflows:
uv run pydantic_demos/run_worker.py
Keep this running throughout your demo sessions. The worker registers all available workflows and activities.
In a separate terminal, run any of the demo scripts:
A simple agent that responds only in haikus.
Files:
pydantic_demos/workflows/hello_world_workflow.py
- Simple haiku-generating agentpydantic_demos/run_hello_world_workflow.py
- Client runner
To run:
uv run pydantic_demos/run_hello_world_workflow.py
An agent that uses a weather function as a tool.
Files:
pydantic_demos/workflows/tools_workflow.py
- Workflow using weather toolpydantic_demos/run_tools_workflow.py
- Client runner
To run:
uv run pydantic_demos/run_tools_workflow.py
A research system that processes queries and generates comprehensive markdown reports.
Files:
pydantic_demos/workflows/research_bot_workflow.py
- Main research workflowpydantic_demos/workflows/simple_research_manager.py
- Simple research orchestratorpydantic_demos/workflows/research_agents/
- Research agent componentspydantic_demos/run_research_workflow.py
- Research client
Agents:
- Planner Agent: Plans web searches based on the query
- Search Agent: Performs searches to gather information
- Writer Agent: Compiles the final research report
To run:
uv run pydantic_demos/run_research_workflow.py "Tell me about quantum computing"
Output:
pydantic_research_report.md
- Comprehensive markdown report
Note: The research workflow may take 1-2 minutes to complete due to web searches and report generation.
An enhanced version of the research workflow with interactive clarifying questions to refine research parameters before execution and optional PDF generation.
This example is inspired by the OpenAI Deep Research API cookbook.
Files:
pydantic_demos/workflows/interactive_research_workflow.py
- Interactive research workflowpydantic_demos/workflows/research_agents/
- All research agent componentspydantic_demos/run_interactive_research_workflow.py
- Interactive research clientpydantic_demos/workflows/pdf_generation_activity.py
- PDF generation activitypydantic_demos/workflows/research_agents/pdf_generator_agent.py
- PDF generation agent
Agents:
- Triage Agent: Analyzes research queries and determines if clarifications are needed
- Clarifying Agent: Generates follow-up questions for better research parameters
- Planner Agent: Creates web search plans
- Search Agent: Performs web searches
- Writer Agent: Compiles final research reports
- PDF Generator Agent: Converts markdown reports to professionally formatted PDFs
To run:
uv run pydantic_demos/run_interactive_research_workflow.py "Tell me about quantum computing"
Additional options:
--non-interactive
: Skip clarifying questions and do direct research
Output:
research_report.md
- Comprehensive markdown reportpdf_output/research_report.pdf
- Professionally formatted PDF (if PDF generation is available)
Note: The interactive workflow may take 2-3 minutes to complete due to web searches and report generation.
pydantic-ai-demos/
├── README.md # This file
├── pyproject.toml # Project dependencies
├── pydantic_demos/
│ ├── __init__.py
│ ├── run_worker.py # Worker that registers all workflows
│ ├── run_hello_world_workflow.py # Hello World demo runner
│ ├── run_tools_workflow.py # Tools demo runner
│ ├── run_research_workflow.py # Research demo runner
│ ├── run_interactive_research_workflow.py # Interactive research demo runner
│ └── workflows/
│ ├── __init__.py
│ ├── hello_world_workflow.py # Simple haiku agent
│ ├── tools_workflow.py # Weather tool demo
│ ├── research_bot_workflow.py # Main research workflow
│ ├── interactive_research_workflow.py # Interactive research workflow
│ ├── simple_research_manager.py # Simple research orchestrator
│ ├── interactive_research_manager.py # Interactive research orchestrator
│ ├── pdf_generation_activity.py # PDF generation activity
│ └── research_agents/ # Research agent components
│ ├── __init__.py
│ ├── research_models.py # Data models
│ ├── triage_agent.py # Query analysis agent
│ ├── clarifying_agent.py # Question generation agent
│ ├── planner_agent.py # Research planning agent
│ ├── search_agent.py # Web search agent
│ ├── writer_agent.py # Report writing agent
│ └── pdf_generator_agent.py # PDF generation agent
# Format code
uv run -m black .
uv run -m isort .
# Type checking
uv run -m mypy --check-untyped-defs --namespace-packages .
uv run pyright .
- Temporal Workflows: All demos use Temporal for reliable workflow orchestration
- Pydantic AI: Powered by Pydantic AI for natural language processing with OpenAI models
- Multi-Agent Systems: The research demo showcases complex multi-agent coordination
- Interactive Workflows: Research demo supports real-time user interaction
- Tool Integration: Tools demo shows how to integrate external functions as tools
- PDF Generation: Interactive research workflow generates professional PDF reports alongside markdown
MIT License - see the original project for full license details.