← Back to PRs

#7738: feat(web-search): add provider fallback and Serper support

by garnetlyx open 2026-02-03 04:57 View on GitHub →
agents stale
## 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