A comprehensive AI-powered deep research system built with Pydantic-AI using an event-driven architecture. This is an AI-assisted project built with the help of claude-code and codex.
- 4-Stage Research Workflow:
- Clarification – Validates and refines the research query (two‑phase flow)
- Query Transformation – Produces a TransformedQuery (SearchQueryBatch + ResearchPlan)
- Research Execution – Executes prioritized search batch and synthesizes findings
- Report Generation – Composes the final ResearchReport with citations
sequenceDiagram
participant User
participant ClarificationAgent
participant QueryTransformationAgent
participant SearchOrchestrator
participant ResearchExecutorAgent
participant ReportGeneratorAgent
User->>ClarificationAgent: Submit research query
activate ClarificationAgent
ClarificationAgent-->>ClarificationAgent: Assess clarity & optionally gather responses
ClarificationAgent-->>User: Clarification prompts (if needed)
deactivate ClarificationAgent
ClarificationAgent->>QueryTransformationAgent: Clarified query & metadata
activate QueryTransformationAgent
QueryTransformationAgent-->>QueryTransformationAgent: Produce TransformedQuery
QueryTransformationAgent-->>SearchOrchestrator: Emit SearchQueryBatch
deactivate QueryTransformationAgent
activate SearchOrchestrator
SearchOrchestrator-->>SearchOrchestrator: Execute prioritized search batch
SearchOrchestrator-->>ResearchExecutorAgent: Aggregated search results
deactivate SearchOrchestrator
activate ResearchExecutorAgent
ResearchExecutorAgent-->>ResearchExecutorAgent: Run synthesis tools (extraction, clustering, contradictions, patterns, quality)
ResearchExecutorAgent-->>ReportGeneratorAgent: `ResearchResults`
deactivate ResearchExecutorAgent
activate ReportGeneratorAgent
ReportGeneratorAgent-->>ReportGeneratorAgent: Compose `ResearchReport`
ReportGeneratorAgent-->>User: Final report delivery
deactivate ReportGeneratorAgent
- Lock-free Event Bus implementation for async coordination
- Immutable events prevent deadlocks
- Support for streaming updates and progress tracking
- FastAPI Web API with Server-Sent Events (SSE) support
- Command-Line Interface with rich formatting and streaming
- Real-time progress updates and interactive sessions
This project uses uv for dependency management. First, ensure you have uv installed:
# Install uv if you haven't already
curl -LsSf https://astral.sh/uv/install.sh | shThen install the project:
# Clone the repository
git clone <your-repo-url>
cd open_deep_research_pydantic_ai
# Install dependencies
uv sync
# Install with development dependencies
uv sync --all-extras
# Or install specific extras
uv sync --extra dev # Development tools
uv sync --extra docs # Documentation tools
uv sync --extra research # Research/data science toolsuv run pytest# Lint
uv run ruff check src tests
# Format (uses ruff format)
uv run ruff format src tests
# Type checking (strict)
uv run pyright srcuv run mkdocs serveopen_deep_research_pydantic_ai/
├── src/
│ ├── api/ # FastAPI app and HTTP endpoints (SSE streaming)
│ ├── agents/ # Agent implementations (clarification, transformation, execution, report)
│ ├── cli/ # Modular CLI (app, runner, http_client, stream, clarification_http, report_io)
│ ├── core/ # Workflow orchestrator, events, logging bootstrap
│ ├── models/ # Pydantic models for state, reports, queries
│ ├── services/ # Search orchestrator, source repository, validation, tools
│ ├── utils/ # Utilities
│ └── __init__.py
├── tests/
├── docs/
├── pyproject.toml
└── README.md
Set your API keys as environment variables:
export OPENAI_API_KEY="your-openai-key"
export TAVILY_API_KEY="your-tavily-key" # Optional for search
export LOGFIRE_TOKEN="your-logifire-token" # For observabilityTwo opt-in improvements are available for synthesis and reporting. They are disabled by default.
- Embedding-based semantic grouping
- Enable:
ENABLE_EMBEDDING_SIMILARITY=1 - Optional threshold:
EMBEDDING_SIMILARITY_THRESHOLD(default 0.55) - Backend: if
OPENAI_API_KEYis set, OpenAI embeddings are used automatically in the workflow.
- Enable:
# Run a single research query
uv run deep-research research "What are the latest advances in quantum computing?"
# Start interactive in direct more
uv run deep-research interactive --mode direct
# With custom API keys
uv run deep-research research "Your query" -k openai:sk-... -k tavily:tvly-...
# Enable verbose logging
uv run deep-research research "Your query" -v
# HTTP mode (client/server)
uv run deep-research-server
uv run deep-research research "Your query" --mode http --server-url http://localhost:8000
Start the FastAPI server:
# Recommended script entry
uv run deep-research-server
# Or directly with uvicorn
uv run uvicorn api.main:app --host 0.0.0.0 --port 8000API Endpoints:
POST /research- Start a new research taskGET /research/{request_id}- Get research statusGET /research/{request_id}/stream- Stream updates via SSEGET /research/{request_id}/report- Get final report
from open_deep_research_pydantic_ai import ResearchWorkflow
# Execute research (async)
state = await ResearchWorkflow().run(
user_query="What are the applications of AI in healthcare?",
)
if state.final_report:
print(state.final_report.title)
print(state.final_report.executive_summary)- Event Bus (
src/core/events.py) – Async event-driven coordination via immutable events - Workflow Orchestrator (
src/core/workflow.py) – Manages the 4-stage research pipeline - Models (
src/models/) – Typed Pydantic models for state, queries, and reports - Base Agent (
src/agents/base.py) – Typed agent base with DI, metrics, tools
- Clarification Agent – Evaluates readiness and triggers interactive clarification when needed
- Query Transformation Agent – Emits TransformedQuery with SearchQueryBatch + ResearchPlan
- Research Executor Agent – Executes prioritized search and synthesizes findings
- Report Generator Agent – Composes the final report with citations
- Dependency Injection: Shared resources passed via
ResearchDependencies - Event-Driven Coordination: Lock-free async communication through the event bus
- Streaming Support: Real-time updates via SSE (HTTP) and Rich UI (CLI)
- Framework: Pydantic-AI instead of LangGraph
- Communication: Event Bus pattern for agent coordination
- Streaming: Native SSE and CLI streaming support
- Type Safety: Full Pydantic validation throughout
-
Features
- Generate charts and relevant graphics in the report
- Option to use other search engines, such as Brave Search
- Configurable writing style
- Durable execution with temporal.io
-
Enhancements
- Fix broken tests
- Fix Pyright warnings and errors
- Fix and improve agent evals
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
MIT License
Inspired by the Open Deep Research project from LangChain.