#7738: feat(web-search): add provider fallback and Serper support
agents
stale
Cluster:
Web Search Provider Enhancements
## Summary
Adds provider fallback mechanism and Serper support to web-search tool.
### Changes
1. **Provider abstraction**: New WebSearchProvider interface with implementations for Brave, Perplexity, and Serper
2. **Fallback support**: When primary provider fails, automatically tries fallback provider (configurable)
3. **Serper provider**: New provider using Serper API (2500 free queries/day)
4. **Optimizations**:
- Timeout distribution (70% primary, 30% fallback)
- Cache key optimization
- Code deduplication
### Configuration
{
"tools": {
"web": {
"search": {
"provider": "brave",
"fallback": "serper",
"serper": {
"apiKey": "..."
}
}
}
}
}
### Backward Compatibility
- All existing configurations continue to work
- New fallback field is optional
- Serper provider requires SERPER_API_KEY env var or config
Closes: (no issue)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR refactors `web_search` to use a provider abstraction (`WebSearchProvider`) with implementations for Brave, Perplexity, and a new Serper provider, and adds a fallback mechanism that retries with a secondary provider when the primary fails. The tool now routes all search execution through `runWebSearchWithFallback`, adds timeout splitting between primary/fallback, and updates config types/tests accordingly.
Main issue spotted: the Serper provider’s config isn’t actually wired through from `tools.web.search.serper` to `SerperProvider` due to a key mismatch in `extractProviderConfig`, so Serper will typically require `SERPER_API_KEY` even when configured in the config file. Tests also introduce a global `fetch` mutation that is not restored, which may cause flaky test ordering failures.
<h3>Confidence Score: 2/5</h3>
- This PR has a high-impact configuration wiring bug that will break Serper usage unless an env var is set.
- While the provider abstraction/fallback structure is straightforward, `extractProviderConfig` currently reads Serper config from the wrong location, so the documented `tools.web.search.serper.apiKey` path won’t be honored and Serper provider init will fail in typical config-based setups. There’s also a test hygiene issue (global fetch not restored) that can cause flakiness. Fixing these should make the change safe.
- src/agents/tools/web-search.ts (provider config extraction), src/agents/tools/web-search-integration.test.ts (global fetch stub cleanup)
<!-- greptile_other_comments_section -->
<sub>(5/5) You can turn off certain types of comments like style [here](https://app.greptile.com/review/github)!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#8715: fix(web-search): safer provider resolution & Perplexity auto-detection
by abhijeet117 · 2026-02-04
84.6%
#19876: feat(web-search): add SerpAPI search provider support
by nksolar-tianjin · 2026-02-18
84.3%
#11444: Add extensible search providers for web_search
by dhc02 · 2026-02-07
82.3%
#17632: feat(web-search): add per-call provider override
by cog-bernthiddema · 2026-02-16
80.5%
#14445: feat: add SerpApi search provider plugin with vertical search support
by xiaoyaner0201 · 2026-02-12
80.2%
#6743: feat(web-search): add Tavily search provider support
by 3927o · 2026-02-02
79.0%
#17703: feat(web-search): add Parallel search provider
by raktim-mondol · 2026-02-16
78.7%
#16895: feat(web-search): add SearXNG as a search provider
by rustyorb · 2026-02-15
76.7%
#8707: fix(web_search): honor configured provider at execution timeFix/web...
by codvik · 2026-02-04
76.5%
#22626: feat(search): add support for SearXNG as a search provider
by sarveshgandhi · 2026-02-21
76.5%