DeepResearch
DeepResearch copied to clipboard
Multi-provider search with Exa → Tavily → Serper → DuckDuckGo fallback chain
Summary
This PR implements a multi-provider search system with automatic fallback for DeepResearch. It provides a 4-provider fallback chain optimized for quality and reliability.
Fallback Chain
- Exa.ai (primary) - Best quality, semantic/neural search ($10 free credits)
- Tavily (2nd) - Purpose-built for RAG/LLMs (1,000 free requests/month)
- Serper.dev (3rd) - Google SERP results (2,500 free queries)
- DuckDuckGo (final) - Free forever, always available
The system automatically falls back to the next provider when:
- API key is not configured
- Rate limit is hit (429)
- API errors occur (401, 402, 432, 433)
- Credits/quota exhausted
Why This Approach?
| Scenario | Old (Single Provider) | New (Fallback Chain) |
|---|---|---|
| Exa credits run out | Search fails | Falls back to Tavily |
| Tavily quota exceeded | Search fails | Falls back to Serper |
| Serper rate limited | Search fails | Falls back to DuckDuckGo |
| No API keys configured | Cannot use | DuckDuckGo works |
| All providers fail | Crash | Clear error message |
Provider Comparison
| Feature | Exa.ai | Tavily | Serper.dev | DuckDuckGo |
|---|---|---|---|---|
| Search Type | Neural/semantic | RAG-optimized | Google SERP | Keyword |
| Quality | Excellent | Excellent | Good | Acceptable |
| API Key Required | Yes | Yes | Yes | No |
| Free Tier | $10 credits | 1,000/month | 2,500 queries | Unlimited |
| Best For | Semantic search | LLM apps | Google results | Fallback |
Changes
-
inference/tool_search.py: Complete rewrite with 4-provider fallback-
search_exa(),search_tavily(),search_serper(),search_duckduckgo() -
sanitize_query()for input validation -
format_results()for consistent output - Proper error handling for each provider's specific error codes
-
multi_provider_search()orchestrates the fallback chain
-
-
.env.example: Updated with all provider API keys
Configuration
# .env - configure one or more (DuckDuckGo needs no key)
EXA_API_KEY=your_exa_key # Best quality (recommended)
TAVILY_API_KEY=your_tavily_key # RAG-optimized (recommended)
SERPER_KEY_ID=your_serper_key # Google results
# DuckDuckGo is always available as final fallback
Error Handling
| Provider | Error Code | Meaning | Action |
|---|---|---|---|
| Exa | 402 | Payment required | Fall back to Tavily |
| Tavily | 432 | Plan limit exceeded | Fall back to Serper |
| Tavily | 433 | Pay-as-you-go limit | Fall back to Serper |
| All | 429 | Rate limited | Fall back to next |
| All | 401 | Invalid API key | Fall back to next |
Testing
Tested all four paths:
- Exa primary works with
type: "auto"search - Tavily fallback works with Bearer token auth
- Serper fallback works when Exa/Tavily disabled
- DuckDuckGo fallback works when all APIs disabled
- Error messages show which providers failed and why