fix(web): add runtime availability check in web_search_tool handler - #42024
Closed
liuhao1024 wants to merge 2 commits into
Closed
liuhao1024 wants to merge 2 commits into
liuhao1024 wants to merge 2 commits into
Conversation
The `check_fn` gate (`check_web_api_key`) filters `web_search` from the LLM's tool list at `get_definitions()` time, but the handler itself had no runtime guard. When the handler is reached via the `tool_call` bridge or a stale tool-list context, `_get_search_backend()` returns the configured backend name (e.g. "ddgs") without checking availability, and the code dispatches to the provider — which may fail with a generic or confusing error. Add an explicit `_is_backend_available(backend)` check at the top of `web_search_tool()` that returns a structured error with actionable installation instructions before the provider dispatch path is entered. Fixes NousResearch#42011
…est_exception_returns_json_error
Contributor
1 task
Collaborator
|
Thanks for the focused error-handling work. This is already implemented on current
Automated hermes-sweeper review. |
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.
What does this PR do?
Adds a runtime availability check at the beginning of
web_search_tool()so that when the configured web search backend (e.g.ddgs) is unavailable at invocation time, the tool returns a clear, actionable error instead of silently falling through to provider-internal error handling.Related Issue
Fixes #42011
Type of Change
Changes Made
tools/web_tools.py: Added_is_backend_available(backend)guard after_get_search_backend()inweb_search_tool(). When the configured backend is not available, returns{"success": false, "error": "..."}with backend-specific installation instructions before the provider dispatch path is entered.tests/tools/test_web_tools_config.py: Added 3 new tests — unavailable ddgs backend, unavailable API-key backend, and empty-backend passthrough. Updated 2 existing tests to mock_is_backend_available.tests/tools/test_web_providers.py: Updatedtest_unconfigured_search_emits_top_level_errorto match the new error message format.How to Test
web.backend: ddgsin~/.hermes/config.yamlddgspackage is NOT installed:pip uninstall ddgsweb_searchtool — should return{"success": false, "error": "The configured web search backend 'ddgs' is not available. Install the package with: pip install ddgs"}pytest tests/tools/test_web_tools_config.py tests/tools/test_web_providers.py tests/tools/test_web_providers_ddgs.py -v— all tests should passChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/ACode Intelligence
tools/web_tools.py::web_search_tool(callers: 1 via registry handler lambda)check_web_api_key()atget_definitions()time,_is_backend_available()shared with_get_capability_backend()