fix(web_search): validate missing API key/URL directly in Search methods#2517
fix(web_search): validate missing API key/URL directly in Search methods#2517wj-xiao merged 1 commit intosipeed:mainfrom
Conversation
| Proxy string | ||
| } | ||
|
|
||
| func NewWebSearchTool(opts WebSearchToolOptions) (*WebSearchTool, error) { |
There was a problem hiding this comment.
This change does more than move validation from construction time to execution time; it also changes provider selection semantics.
Before this patch, NewWebSearchTool selected the first usable provider in priority order by requiring a non-empty key/URL for providers that need credentials.
After this patch, the first enabled provider wins even when it is not configured, so a setup like PerplexityEnabled=true with no keys and DuckDuckGoEnabled=true will now fail at runtime with "no API key provided" instead of falling back to DuckDuckGo.
The same regression applies to Brave, SearXNG, Tavily, Baidu Search, and GLM Search. We should preserve the existing "first usable provider" fallback behavior and add a regression test for mixed-provider configurations.
There was a problem hiding this comment.
I think it is acceptable. Previously, whether to load a provider was determined based on the supplier's key/URL. If the key/URL was not set, the web_search tool would not be loaded into the context. Now, if a provider does not have a key configured, it will intuitively inform the user that the key/URL is not configured when the tool is called. I believe sacrificing the priority selection feature is acceptable.
📝 Description
Summary
Move the API key / URL validation for web search providers from
NewWebSearchToolinto the individualSearchmethods. When a required key or URL is missing, the tool now returns a clear error at execution time instead of silently creating aniltool.Changes
BraveSearchProvider.Search: returnno API key providedwhen the key pool is emptyTavilySearchProvider.Search: returnno API key providedwhen the key pool is emptyPerplexitySearchProvider.Search: returnno API key providedwhen the key pool is emptyGLMSearchProvider.Search: returnno API key providedwhen the API key is emptyBaiduSearchProvider.Search: returnno API key providedwhen the API key is emptySearXNGSearchProvider.Search: returnno SearXNG URL providedwhenbaseURLis emptyNewWebSearchTool: remove key / URL non-empty guards so the tool can be instantiated even when credentials are missingTestWebTool_WebSearch_NoApiKeyto assert the runtime error behavior🗣️ Type of Change
🤖 AI Code Generation
🔗 Related Issue
📚 Technical Context (Skip for Docs)
🧪 Test Environment
📸 Evidence (Optional)
Click to view Logs/Screenshots
☑️ Checklist