This project aims to implement a simple DeepSearch agent, leveraging Large Language Models (LLMs) to automate and enhance research tasks. The agent will drive multi-step reasoning, large-scale online retrieval, cross-source evidence merging, and structured writing to produce research-grade results with citations.
Deep Research (deep research/deep search) technology is an application system built around large language models (LLMs), aiming to automate and enhance research tasks. It drives large-scale online retrieval through multi-step reasoning, merges evidence across sources, and performs structured writing, producing research-grade results with citations.
A Deep Research Agent is an AI agent driven by LLMs, integrating dynamic reasoning, adaptive planning, multi-iterative external data retrieval and tool use, and the ability to generate comprehensive analytical reports for information research tasks.
For a more detailed technical deep dive, please refer to deepsearch_summary_en.md.
- LangChain Integration: Advanced agent orchestration with ReAct prompting and tool usage
- Multi-LLM Support: Seamlessly switch between Ollama (local) and OpenAI-compatible APIs
- Modular Architecture: Clean separation between LLM clients, search engines, and core logic
- Extensible Design: Easy to add new LLM providers and search engines
- Environment-based Configuration: Secure management of API keys and settings
- Modern Python: Uses OpenAI SDK v1.0.0+ and best practices
- Dynamic Engine Discovery: Automatically discovers all search engines inheriting from
BaseSearch - Dynamic Registration: Register new engines without modifying existing code
- Configuration Validation: Automatically checks engine configuration status
- Error Handling: Comprehensive error handling with clear messages
- placeholder: Mock search engine for development and testing
- custom_google: Prioritized Google Custom Search API integration (uses
GOOGLE_API_KEYandGOOGLE_CSE_ID) - google: Google Custom Search API integration (fallback if
custom_googleis not available) - bing: Bing Search API integration
- brave: Brave Search API integration
# List all available engines and their status
python main.py --list-engines
# Use auto-selected search engine (recommended)
python main.py --search-engine auto "your query"
# Use specific search engine
python main.py --search-engine google "AI advancements"
# Use placeholder for testing
python main.py --search-engine placeholder "test query"- Multi-Engine Search: Support simultaneous searches across multiple search engines
- Customizable Results: Configurable minimum result count per search engine
- Result Aggregation: Intelligent merging and deduplication of results from multiple sources
- Performance Optimization: Parallel search execution with configurable timeouts
- Python 3.8+
- Ollama (optional, for local models)
- API keys for desired services (OpenAI, Google, Bing, etc.)
git clone <repository-url>
cd ollama-search-agentUsing pip:
pip install -r requirements.txtUsing uv (recommended for speed):
uv pip install -r requirements.txt- Copy the environment template:
cp .env.example .env- Edit
.envfile with your API keys and settings:
# Ollama Configuration
OLLAMA_HOST=http://localhost:11434
OLLAMA_MODEL=llama3
# OpenAI Configuration
OPENAI_API_KEY=your_openai_api_key_here
OPENAI_BASE_URL=https://api.openai.com/v1
OPENAI_MODEL=gpt-4
# Search Engine API Keys
GOOGLE_API_KEY=your_google_api_key
GOOGLE_CSE_ID=your_custom_search_engine_id
CUSTOM_GOOGLE_API_KEY=your_custom_google_api_key # Note: Currently uses GOOGLE_API_KEY
CUSTOM_GOOGLE_CSE_ID=your_custom_google_cse_id # Note: Currently uses GOOGLE_CSE_ID
BING_API_KEY=your_bing_api_key
BRAVE_API_KEY=your_brave_api_keypython main.py "your search query"python main.py --llm openai "your search query"python main.py
# Then enter your query when promptedollama-search-agent/
βββ agent.py # Core agent orchestration logic
βββ config.py # Centralized configuration management
βββ main.py # CLI entry point and argument parsing
βββ requirements.txt # Python dependencies
βββ .env.example # Environment variables template
βββ .gitignore # Git ignore rules
βββ README.md # Project documentation
βββ TECHNICAL_OVERVIEW.md # Detailed technical documentation
βββ langchain_tools/ # LangChain tool implementations (e.g., SearchTool)
β βββ __init__.py
β βββ search_tools.py # LangChain wrapper for search engines
βββ llm_clients/ # LLM provider implementations
β βββ __init__.py
β βββ ollama_client.py # Ollama local model client
β βββ openai_client.py # OpenAI-compatible API client
βββ search_engines/ # Search engine implementations
βββ __init__.py
βββ base_search.py # Abstract base class for search engines
βββ placeholder_search.py # Mock search for development
βββ bing_search.py # Bing Search API
βββ brave_search.py # Brave Search API
βββ custom_google_search.py # Prioritized Google Custom Search API implementation
βββ google_search.py # Standard Google Custom Search API implementation
- Orchestrates the search workflow: Plan β Search β Synthesize
- Uses LLM to generate search plans from user queries
- Combines search results with original query for final synthesis
- OllamaClient: Communicates with local Ollama instance via REST API
- OpenAIClient: Uses OpenAI SDK v1.0.0+ for OpenAI-compatible APIs
- Both implement consistent
generate(prompt)interface
- BaseSearch: Abstract class defining search engine interface
- PlaceholderSearch: Mock implementation for testing
- GoogleSearch: Google Custom Search API integration
- BingSearch: Bing Search API integration
- BraveSearch: Brave Search API integration
- Query Analysis: LLM analyzes user query and generates search plan
- Search Execution: Search engine executes plan and retrieves results
- Information Synthesis: LLM synthesizes search results into coherent answer
- Response Delivery: Final answer returned to user
- Create new client in
llm_clients/(e.g.,anthropic_client.py) - Implement
generate(prompt)method - Add configuration to
config.pyand.env.example - Update CLI arguments in
main.py
- Create new class in
search_engines/inheriting fromBaseSearch - Implement
search(query)method returning structured results - Add API configuration to
config.pyand.env.example - Update CLI arguments in
main.py
ModuleNotFoundError: No module named 'openai'
pip install -r requirements.txtOpenAI API Compatibility Issues
- The project uses OpenAI SDK v1.0.0+ with modern API patterns
- Legacy
openai.Completioncalls have been updated toclient.chat.completions.create()
Ollama Connection Issues
- Ensure Ollama is running:
ollama serve - Verify OLLAMA_HOST in
.envmatches your Ollama instance
- TECHNICAL_OVERVIEW.md: Detailed technical architecture and component breakdown
- Code is well-documented with docstrings and type hints
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
[Add your license here]
- Intelligent Agent Selection: Automatically select the best agent based on user input and task complexity.
- Dynamic LLM Selection: Allow the agent to dynamically choose the most suitable LLM (Ollama, OpenAI, etc.) based on the query or user preferences.
- Enhanced Search Engine Prioritization: Further refine the logic for selecting search engines, potentially incorporating factors like query type, result quality, or user-defined preferences.