← Back to PRs

#19876: feat(web-search): add SerpAPI search provider support

by nksolar-tianjin open 2026-02-18 08:05 View on GitHub →
agents size: M
Add SerpAPI as a fourth web search provider alongside Brave, Perplexity, and Grok. - Add 'serpapi' to provider union type and zod schema - Add serpapi config block (apiKey, engine) to types and validation - Implement runSerpApiSearch following the Brave pattern - Support SERPAPI_API_KEY env var and config-based key resolution - Map freshness shortcuts (pd/pw/pm/py) to SerpAPI tbs params - Add 18 test cases for config resolution and freshness mapping <!-- greptile_comment --> <h3>Greptile Summary</h3> Adds SerpAPI as a fourth web search provider alongside Brave, Perplexity, and Grok. The implementation closely follows existing patterns: config resolution mirrors the Grok/Perplexity approach, result mapping follows the Brave pattern, and freshness shortcuts (pd/pw/pm/py) are mapped to SerpAPI's `tbs` query parameter. - Adds `serpapi` to provider union type, Zod schema, and all provider resolution/dispatch paths - Implements `runSerpApiSearch` with proper error handling, timeout, caching, and content wrapping - Adds `resolveSerpApiApiKey` (config-first, `SERPAPI_API_KEY` env fallback) and `resolveSerpApiEngine` (default: `"google"`) - Includes 18 test cases covering config resolution and freshness mapping - Minor type annotation issue: `runSerpApiSearch` return type omits the `published` field that is actually returned in result objects <h3>Confidence Score: 4/5</h3> - This PR is safe to merge — it adds a new search provider following well-established patterns with no changes to existing provider behavior. - The implementation is clean and consistent with existing providers. The only finding is a minor return type annotation omission (missing `published` field) that doesn't affect runtime behavior. All four changed files are straightforward additive changes with no risk to existing functionality. - Minor attention needed for `src/agents/tools/web-search.ts` — the `runSerpApiSearch` return type annotation is missing the `published` field. <sub>Last reviewed commit: f4d8160</sub> <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs