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 nameconfigure( config )to merge provider settingsdoSearch( query, options )to execute search and return normalized results
Result Schema
Use formatResults() from BaseSearch to normalize raw provider payloads into:
titleurlsnippetpublishedDatedomainscorethumbnaillanguage
API Key Resolution Pattern
Use resolveApiKey( envVar, settingKey ) for this precedence:
Constructor config
Module settings
Environment variable
Example: Custom News Provider
Event Lifecycle
BaseSearch automatically fires these events:
beforeAIWebSearchonAIWebSearchRequestonAIWebSearchResponseafterAIWebSearchonAIWebSearchError
This gives you observability and centralized interception without extra provider code.
Registering Your Provider
Update provider map in WebSearchTools:
Testing Pattern
Add provider API key in test setup (module settings/env var).
Use assumption-based tests when key is optional in CI.
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.
Related
Last updated