← Back to PRs

#8715: fix(web-search): safer provider resolution & Perplexity auto-detection

by abhijeet117 open 2026-02-04 09:32 View on GitHub →
agents size: S
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