Skip to content

fix(web_search): validate missing API key/URL directly in Search methods#2517

Merged
wj-xiao merged 1 commit intosipeed:mainfrom
lxowalle:fix/web_search
Apr 15, 2026
Merged

fix(web_search): validate missing API key/URL directly in Search methods#2517
wj-xiao merged 1 commit intosipeed:mainfrom
lxowalle:fix/web_search

Conversation

@lxowalle
Copy link
Copy Markdown
Collaborator

📝 Description

Summary

Move the API key / URL validation for web search providers from NewWebSearchTool into the individual Search methods. When a required key or URL is missing, the tool now returns a clear error at execution time instead of silently creating a nil tool.

Changes

  • BraveSearchProvider.Search: return no API key provided when the key pool is empty
  • TavilySearchProvider.Search: return no API key provided when the key pool is empty
  • PerplexitySearchProvider.Search: return no API key provided when the key pool is empty
  • GLMSearchProvider.Search: return no API key provided when the API key is empty
  • BaiduSearchProvider.Search: return no API key provided when the API key is empty
  • SearXNGSearchProvider.Search: return no SearXNG URL provided when baseURL is empty
  • NewWebSearchTool: remove key / URL non-empty guards so the tool can be instantiated even when credentials are missing
  • Update TestWebTool_WebSearch_NoApiKey to assert the runtime error behavior

🗣️ Type of Change

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 📖 Documentation update
  • ⚡ Code refactoring (no functional changes, no api changes)

🤖 AI Code Generation

  • 🤖 Fully AI-generated (100% AI, 0% Human)
  • 🛠️ Mostly AI-generated (AI draft, Human verified/modified)
  • 👨‍💻 Mostly Human-written (Human lead, AI assisted or none)

🔗 Related Issue

📚 Technical Context (Skip for Docs)

  • Reference URL:
  • Reasoning:

🧪 Test Environment

  • Hardware:
  • OS:
  • Model/Provider:
  • Channels:

📸 Evidence (Optional)

Click to view Logs/Screenshots

☑️ Checklist

  • My code/docs follow the style of this project.
  • I have performed a self-review of my own changes.
  • I have updated the documentation accordingly.

@sipeed-bot sipeed-bot bot added type: bug Something isn't working domain: tool labels Apr 14, 2026
Comment thread pkg/tools/web.go
Proxy string
}

func NewWebSearchTool(opts WebSearchToolOptions) (*WebSearchTool, error) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@wj-xiao wj-xiao merged commit 773a94c into sipeed:main Apr 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: tool type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants