Skip to content

fix(web): add runtime availability check in web_search_tool handler - #42024

Closed
liuhao1024 wants to merge 2 commits into
NousResearch:mainfrom
liuhao1024:fix/web-search-backend-unavailable
Closed

liuhao1024 wants to merge 2 commits into
NousResearch:mainfrom
liuhao1024:fix/web-search-backend-unavailable

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

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

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • tools/web_tools.py: Added _is_backend_available(backend) guard after _get_search_backend() in web_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: Updated test_unconfigured_search_emits_top_level_error to match the new error message format.

How to Test

  1. Set web.backend: ddgs in ~/.hermes/config.yaml
  2. Ensure the ddgs package is NOT installed: pip uninstall ddgs
  3. Call web_search tool — should return {"success": false, "error": "The configured web search backend 'ddgs' is not available. Install the package with: pip install ddgs"}
  4. Run 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 pass

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Code Intelligence

  • Analyzed: tools/web_tools.py::web_search_tool (callers: 1 via registry handler lambda)
  • Blast radius: LOW — additive guard at handler entry; existing provider-internal error handling unchanged
  • Related patterns: check_web_api_key() at get_definitions() time, _is_backend_available() shared with _get_capability_backend()

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
@alt-glitch alt-glitch added type/bug Something isn't working comp/tools Tool registry, model_tools, toolsets tool/web Web search and extraction P3 Low — cosmetic, nice to have labels Jun 8, 2026
@alt-glitch

Copy link
Copy Markdown
Contributor

Implements the fix for #42011 (web_search silently echoes tool call when backend package missing). Related work in availability-gate cluster: #31887, #11331.

@teknium1

Copy link
Copy Markdown
Collaborator

Thanks for the focused error-handling work. This is already implemented on current main through the provider-dispatch architecture.

  • tools/web_tools.py:679-730 resolves the registered search provider and returns its structured result rather than using the inline dispatch path targeted by this PR.
  • plugins/web/ddgs/provider.py:101-107 catches a missing ddgs import and returns {"success": false, "error": "ddgs package is not installed — run pip install ddgs"}`.
  • tests/tools/test_web_providers_ddgs.py:134-150 covers that missing-package failure path.
  • The registry dispatch arrived in b05253ceed5f9d139f4a7d8705f5c97fcf644a2c, included in v2026.5.16.

Automated hermes-sweeper review.

@teknium1 teknium1 closed this Jul 14, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tools Tool registry, model_tools, toolsets P3 Low — cosmetic, nice to have sweeper:implemented-on-main Sweeper: behavior already present on current main tool/web Web search and extraction type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

web_search silently echoes tool call when backend package is missing

3 participants