A sophisticated terminal-based Deep Research Agent built with OpenAI AI Agents SDK, powered by Google's Gemini API and enhanced with Rich CLI formatting. This agent performs thorough research by analyzing queries, browsing the web, and synthesizing insights into clear, well-structured reports.
The Deep Research Agent is an advanced AI-powered research tool that:
- Breaks down complex research queries into focused search topics
- Performs intelligent web searches using DuckDuckGo
- Analyzes and summarizes search results
- Makes decisions about follow-up research needs
- Synthesizes findings into comprehensive markdown reports
- Presents all information with a beautiful terminal interface
- Python 3.7 or higher
- UV package manager (install from https://github.com/astral/uv)
- Clone the repository:
git clone https://github.com/DevHammad0/Deep_Research_Agent.git
cd deep_research_agent
- Install dependencies using UV:
uv pip install -r requirements.txt
- Set up your Gemini API key:
Copy `.env.example` to `.env` and fill in your values:
- `GEMINI_API_KEY`: Your Google Gemini API key
DEEP_RESEARCH_AGENT/
βββ src/
β βββ deep_research_agent/
β βββ research_agents/ # Specialized agent implementations
β β βββ follow_up_agent.py # Research completion decisions
β β βββ query_agents.py # Query analysis and generation
β β βββ search_agent.py # Web content analysis
β β βββ synthesis_agent.py # Report generation
β βββ coordinator.py # Research workflow orchestrator
β βββ main.py # Entry point
β βββ model_setup.py # GEMINI model configurations
β βββ models.py # Data models and types
βββ README.md # Project documentation
βββ requirements.txt # Project dependencies
βββ pyproject.toml
The central orchestrator that:
- Manages the research workflow
- Coordinates between different specialized agents
- Handles web searches using DuckDuckGo
- Controls the research iteration process
- Manages the final report synthesis
- Analyzes the initial research query
- Breaks down complex topics into searchable components
- Generates focused search queries
- Provides reasoning for the query strategy
- Processes search results
- Scrapes and analyzes web content
- Generates concise summaries of findings
- Filters out irrelevant information
- Evaluates research completeness
- Decides if more research is needed
- Generates follow-up queries for gaps in knowledge
- Provides reasoning for decisions
- Combines all research findings
- Creates structured markdown reports
- Includes source citations
- Generates table of contents
-
Query Analysis
- User inputs a research query
- Query Agent breaks it down into focused search queries
- System displays the analysis and generated queries
-
Research Process
- Performs DuckDuckGo searches for each query
- Search Agent analyzes and summarizes each result
- Progress is displayed in real-time with Rich formatting
-
Iterative Research
- Follow-up Agent evaluates findings
- Decides if more research is needed
- Generates additional queries if necessary
- Maximum of 3 research iterations
-
Report Generation
- Synthesis Agent combines all findings
- Creates a structured markdown report
- Includes citations and sources
- Presents the final report with Rich formatting
Run the agent from the terminal:
uv run src/deep_research_agent/main.py
The project leverages Rich for enhanced terminal output:
-
Status Updates
- Real-time progress indicators
- Colored status messages
- Spinners for ongoing operations
-
Content Formatting
- Markdown rendering for reports
- Panels for sectioning content
- Colored output for different types of information
- Tables for structured data
-
User Interaction
- Styled prompts for user input
- Error messages with appropriate styling
- Clear visual hierarchy of information
-
Modular Agent Design
- Each agent has a specific, focused responsibility
- Clear separation of concerns
- Easy to extend or modify individual components
-
Iterative Research Approach
- Maximum of 3 research iterations
- Smart decision-making about when to stop
- Prevents endless research loops
-
Error Handling
- Robust web scraping with timeouts
- Graceful handling of failed requests
- Clear error messaging
-
Performance Considerations
- Text content truncation for large web pages
- Concurrent processing where possible
- Efficient text processing with BeautifulSoup
openai-agents
: Core agent functionalityrich
: Terminal formatting and UIduckduckgo-search
: Web search capabilitybs4
: Web content parsingpydantic
: Data validation and modelingrequests
: HTTP requestspython-dotenv
: Environment management