For the complete documentation index, see llms.txt. This page is also available as Markdown.

Building Web Search Providers

Build custom web search providers by extending BaseSearch and implementing provider-specific search logic

Create your own web search provider when you need to integrate an API that is not shipped with the module.

Architecture

Custom providers implement IWebSearch by extending BaseSearch.

Required Contract

Your provider must implement:

  • getName() returning a unique provider name

  • configure( config ) to merge provider settings

  • doSearch( query, options ) to execute search and return normalized results

Result Schema

Use formatResults() from BaseSearch to normalize raw provider payloads into:

  • title

  • url

  • snippet

  • publishedDate

  • domain

  • score

  • thumbnail

  • language

API Key Resolution Pattern

Use resolveApiKey( envVar, settingKey ) for this precedence:

  1. Constructor config

  2. Module settings

  3. Environment variable

Example: Custom News Provider

Event Lifecycle

BaseSearch automatically fires these events:

  • beforeAIWebSearch

  • onAIWebSearchRequest

  • onAIWebSearchResponse

  • afterAIWebSearch

  • onAIWebSearchError

This gives you observability and centralized interception without extra provider code.

Registering Your Provider

Update provider map in WebSearchTools:

Testing Pattern

  1. Add provider API key in test setup (module settings/env var).

  2. Use assumption-based tests when key is optional in CI.

  3. Assert normalized output fields, not raw provider fields.

Security Notes

  • Treat provider responses as untrusted input.

  • Sanitize snippets before injecting into prompts.

  • Apply domain allow/block filters for regulated workloads.

  • Avoid logging full response payloads when sensitive data may appear.

Last updated