web_search: return an error when the Brave API key is unconfigured#488
Merged
Conversation
Previously BraveSearchProvider returned an empty result list when no API key was set, which WebSearchToolExecutor reported as "No results found." with IsError=false. That's indistinguishable from a search that genuinely found nothing, so the agent couldn't tell the user that web search is simply not configured. Introduce WebSearchNotConfiguredException; the provider throws it (with an actionable message naming WebTools:ApiKey / the env var) instead of returning empty, and the executor catches it to return IsError=true with that message. Distinct from both the generic "Search failed" path and "No results found". Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When no Brave Search API key is configured,
BraveSearchProvider.SearchAsyncreturned an empty list, andWebSearchToolExecutormappedCount == 0to"No results found."withIsError = false. That's indistinguishable from a search that ran and genuinely found nothing — so the agent can't tell the user that web search isn't set up, and just reports "no results."Noticed while bringing up the docker-compose stack without a
BRAVE_API_KEY:web_searchis still offered to the model every turn but silently returns nothing.Change
WebSearchNotConfiguredException.BraveSearchProviderthrows it (with an actionable message namingWebTools:ApiKeyand the env var) instead of returning[].WebSearchToolExecutorcatches it and returnsIsError = truewith that message — distinct from both the generic"Search failed: …"path and"No results found.".Result — the agent now receives, and can relay:
Tests
BraveSearchProviderTests: missing key now assertsThrowsExactlyAsync<WebSearchNotConfiguredException>.WebSearchToolExecutorTestscase: provider throwingWebSearchNotConfiguredException→IsError = truewith the actionable message.RockBot.Tools.Web.Testspass.🤖 Generated with Claude Code