A sophisticated multi-agent research system that conducts comprehensive research with intelligent clarification questions, contextual search planning, and professional report generation using OpenAI's Agents framework.
- Automatically generates 3 targeted clarification questions based on your research query
- Handles partial responses (answer only the questions you want)
- Creates enriched research context for better results
- Clarifier Agent: Generates intelligent clarification questions
- Planner Agent: Creates targeted search strategies based on clarifications
- Search Agent: Performs contextual web searches with enhanced relevance
- Writer Agent: Synthesizes findings into comprehensive reports
- Email Agent: Delivers beautifully formatted reports via email
- Research Manager: Orchestrates all agents with handoff patterns
- Clean, intuitive Gradio web interface
- Step-by-step workflow visualization
- Real-time progress updates
- Mobile-responsive design
- Executive summaries with key findings
- Structured sections with detailed analysis (1000+ words)
- Actionable recommendations
- Areas for further research
- Professional markdown formatting
- HTML email delivery with beautiful styling
- Python 3.12+
- UV package manager (recommended)
- OpenAI API key
- SendGrid API key (for email delivery)
-
Clone or download the project
cd /path/to/deep-research -
Install dependencies with UV (recommended)
uv sync
Or install manually:
pip install openai-agents>=0.0.17 gradio>=5.33.1 python-dotenv>=1.1.0 pydantic>=2.11.5 sendgrid>=6.12.3 certifi>=2025.4.26
-
Set up environment variables
Copy the example environment file and update with your API keys:
cp env.example .env
Then edit
.envwith your actual API keys:OPENAI_API_KEY=your_openai_api_key_here SENDGRID_API_KEY=your_sendgrid_api_key_here FROM_EMAIL=your_email@example.com TO_EMAIL=your_email@example.com
-
Important: API Keys Setup
You'll need to obtain:
- OpenAI API Key: Get from OpenAI Platform
- SendGrid API Key: Get from SendGrid Console
- Email Configuration: Update
FROM_EMAILandTO_EMAILin your.envfile
β οΈ Security Note: Never commit your.envfile to version control. It contains sensitive API keys. -
Run the application
python main.py
Or with UV:
uv run main.py
-
Open your browser The application will automatically open at
http://localhost:7860
For easier deployment and isolation, you can run the application using Docker:
# 1. Set up environment variables
cp env.example .env
# Edit .env with your API keys
# 2. Build and run with Docker Compose
docker-compose up --build
# 3. Access the application at http://localhost:7860# 1. Build the Docker image
docker build -t deep-research .
# 2. Run the container
docker run -p 7860:7860 --env-file .env deep-research- Isolated Environment: No conflicts with system Python
- Easy Deployment: Works consistently across different systems
- Production Ready: Includes health checks and proper user management
- Scalable: Easy to deploy to cloud platforms
Enter your research query (e.g., "Impact of AI on healthcare industry")
The system generates 3 intelligent questions to refine your research:
- Scope: What specific aspects to focus on
- Audience: Who the research is for
- Context: Timeline, geography, or other constraints
Based on your clarifications, the system:
- Plans targeted searches using the Planner Agent
- Executes multiple concurrent searches via the Search Agent
- Analyzes results with context awareness
The Writer Agent creates a comprehensive report with:
- Executive summary
- Detailed sections (1000+ words)
- Key findings and recommendations
- Areas for further research
The Email Agent sends a beautifully formatted HTML email with the complete report
Query: "Future of renewable energy"
β Get clarification questions
β Provide answers or skip
β Receive comprehensive report
Query: "Latest AI developments"
β Answer clarification questions
β Get targeted research
Query: "Marketing strategies for startups"
Clarification Questions:
- What industry or market segment should I focus on?
- What's your target company size (early-stage, growth-stage)?
- Are you looking for digital marketing, traditional marketing, or both?
Your Response:
1. SaaS and tech startups
2. Early-stage with limited budget
3. Primarily digital marketing with focus on content and social media
User Query β Clarifier Agent β Research Manager
β
Research Context β Planner Agent β Search Plan
β
Search Agent (parallel searches) β Search Results
β
Writer Agent β Report Generation β Email Agent
clarifier_agent.py: Intelligent question generation using OpenAI Agentsplanner_agent.py: Context-aware search planning (3 targeted searches)search_agent.py: Enhanced web search with WebSearchToolwriter_agent.py: Comprehensive report synthesis (gpt-4o-mini)email_agent.py: Professional email formatting with SendGridresearch_manager.py: Multi-agent orchestration with Runnerdeep_research.py: Gradio web interfacemain.py: Application entry point with environment checking
- Built on OpenAI Agents framework with Agent Runner
- Uses function_tool decorators for agent communication
- Implements trace functionality for debugging
- Includes fallback workflow for reliability
- All agents use gpt-4o-mini for cost efficiency
| Variable | Required | Description |
|---|---|---|
OPENAI_API_KEY |
β | OpenAI API key for AI agents |
SENDGRID_API_KEY |
β | SendGrid API key for email delivery |
FROM_EMAIL |
β | Sender email address for reports |
TO_EMAIL |
β | Recipient email address for reports |
Email addresses are now configurable through environment variables in your .env file:
FROM_EMAIL=your_email@example.com # Sender email address
TO_EMAIL=your_email@example.com # Recipient email addressNote: Both email addresses can be the same if you want to send reports to yourself.
You can customize the system by modifying:
- Search Strategy: Edit
planner_agent.pyto change search planning logic (currently 3 searches) - Report Structure: Modify
writer_agent.pyto adjust report format and length - UI Layout: Update
deep_research.pyto change interface design - Email Templates: Customize
email_agent.pyfor different email styles - Agent Models: Change model settings in individual agent files
deep-research/
βββ pyproject.toml # UV project configuration with dependencies
βββ uv.lock # UV lock file
βββ main.py # Application entry point
βββ deep_research.py # Gradio web interface
βββ research_manager.py # Multi-agent orchestrator with Runner
βββ clarifier_agent.py # Clarification questions (3 questions)
βββ planner_agent.py # Search planning (3 searches)
βββ search_agent.py # Web search execution with WebSearchTool
βββ writer_agent.py # Report generation (1000+ words)
βββ email_agent.py # Email delivery with SendGrid
βββ README.md # This file
-
Create new agent file following the pattern:
from agents import Agent agent = Agent( name="YourAgent", instructions="Your instructions here", model="gpt-4o-mini", # Add tools, output_type as needed )
-
Import and integrate in
research_manager.py -
Add function_tool wrapper if needed
-
Update workflow in
run_research_workflow() -
Update UI in
deep_research.pyif needed
Key dependencies from pyproject.toml:
openai-agents>=0.0.17- Core agent frameworkgradio>=5.33.1- Web interfacepython-dotenv>=1.1.0- Environment variablespydantic>=2.11.5- Data validationsendgrid>=6.12.3- Email deliverycertifi>=2025.4.26- SSL certificates
The system includes error handling and fallback mechanisms:
- Mock search results when APIs are unavailable
- Fallback workflow when manager agent fails
- Graceful degradation for missing services
- Comprehensive error logging
Run development tools:
# Linting
uv run ruff check
# Formatting
uv run black .
# Type checking
uv run mypy .
# Tests (if you add them)
uv run pytest-
"Missing required environment variables"
- Create
.envfile withOPENAI_API_KEYandSENDGRID_API_KEY - Ensure no extra spaces or quotes around values
- Create
-
"Failed to send email"
- Verify SendGrid API key is valid
- Update hardcoded email addresses in
email_agent.py - Ensure SendGrid account is properly configured
-
"Search failed"
- Check OpenAI API key is valid and has credits
- Verify internet connection
- Check OpenAI Agents framework is properly installed
-
Interface won't start
- Ensure port 7860 is available
- Try changing port in
main.py - Check for conflicting Python environments
- Run
uv syncto ensure dependencies are installed
-
Agent execution fails
- Check OpenAI API quotas and limits
- Verify
openai-agentspackage version (>=0.0.17) - Check trace logs for detailed error information
Enable debug logging by adding to your code:
import logging
logging.basicConfig(level=logging.DEBUG)View execution traces at: https://platform.openai.com/traces/trace?trace_id={trace_id}
- Concurrent Searches: System runs 3 searches in parallel via Search Agent
- Efficient Models: Uses
gpt-4o-minifor cost-effective processing - Fallbacks: Graceful degradation when services are unavailable
- Agent Framework: Optimized with OpenAI Agents Runner for performance
For production deployment:
- Use async/await throughout (already implemented)
- Add Redis for session management
- Implement proper logging and monitoring
- Add rate limiting for API calls
- Use environment-specific configurations
- Consider agent caching strategies
- Fork the repository
- Create a feature branch
- Make your changes following the existing agent patterns
- Test thoroughly with the development tools
- Submit a pull request
This project is for educational purposes. Please ensure you comply with all API terms of service when using OpenAI and SendGrid APIs.
For issues or questions:
- Check the troubleshooting section above
- Review error messages and trace logs
- Verify your environment variables and email configuration
- Test with simple queries first
- Check OpenAI API quotas and SendGrid configuration
Built with β€οΈ using OpenAI Agents, Gradio, and UV Package Manager