#8715: fix(web-search): safer provider resolution & Perplexity auto-detection
agents
size: S
Cluster:
Web Search Provider Enhancements
This PR improves the safety and reliability of provider selection in the `web_search` tool.
### **What changed**
* Honors explicitly configured `provider` values
* Automatically selects **Perplexity** when valid Perplexity credentials are detected
* Fails fast when a Perplexity API key format is ambiguous instead of guessing the endpoint
* Ensures Brave search result descriptions are always strings (stabilizes tests)
### **Why**
Previously, the tool could silently guess provider routing or fall back to defaults.
This could lead to:
* Requests being sent to the wrong endpoint
* Confusing authentication failures
* Hidden configuration mistakes
This update makes provider resolution **explicit, predictable, and safer**.
### **Impact**
* No breaking changes for correctly configured setups
* Misconfigured or ambiguous API keys now surface a clear error instead of failing silently
### **Tests**
Added/updated coverage for:
* Provider auto-detection logic
* Perplexity base URL resolution
* Failure on ambiguous API key formats
* Freshness normalization
All tests are passing
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR tightens `web_search` provider selection by (a) honoring explicit `tools.web.search.provider`, (b) auto-selecting Perplexity when Perplexity/OpenRouter credentials are detected, and (c) failing fast when a config-provided Perplexity key can’t be unambiguously mapped to a base URL. It also hardens Brave result mapping so `description` is always a string, stabilizing tests.
Changes are localized to `src/agents/tools/web-search.ts`, with corresponding unit test updates in `src/agents/tools/web-search.test.ts` validating baseUrl inference and ambiguous-key failure behavior.
<h3>Confidence Score: 3/5</h3>
- Mostly safe to merge, but has a user-facing regression in the tool description text.
- Provider resolution and baseUrl inference changes are straightforward and covered by tests, but the `createWebSearchTool` description strings appear to be placeholder/truncated, which would ship to users and likely isn’t intended. No other high-confidence functional regressions were found in the changed areas.
- src/agents/tools/web-search.ts (tool description strings)
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#7738: feat(web-search): add provider fallback and Serper support
by garnetlyx · 2026-02-03
84.6%
#8707: fix(web_search): honor configured provider at execution timeFix/web...
by codvik · 2026-02-04
83.6%
#17632: feat(web-search): add per-call provider override
by cog-bernthiddema · 2026-02-16
82.8%
#11444: Add extensible search providers for web_search
by dhc02 · 2026-02-07
82.3%
#17729: fix(configure): update web tools hint to reflect all search providers
by raktim-mondol · 2026-02-16
82.0%
#13370: Tools: rewrite Grok parser, add Tavily provider, multi-provider con...
by a-anand-91119 · 2026-02-10
80.9%
#4882: fix(web_search): strip perplexity/ prefix from model names
by AverageSuami · 2026-01-30
80.7%
#18167: feat(web-search): add baseUrl support for Brave Search provider
by jkoprax · 2026-02-16
79.9%
#6743: feat(web-search): add Tavily search provider support
by 3927o · 2026-02-02
79.3%
#19126: feat(web-search): add baseUrl option for Brave Search provider
by pierreeurope · 2026-02-17
79.3%