mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-18 04:41:56 +00:00
Removes the seven hardcoded TOOL_CATEGORIES["web"] provider rows that
duplicated the plugin-registered providers, and deletes the
_WEB_PLUGIN_SKIPLIST that existed to prevent duplicate picker rows
during the migration. The Web Search & Extract category now derives its
provider rows entirely from agent.web_search_registry via
_plugin_web_search_providers(), matching how Spotify, Google Meet, and
the image_gen plugins are surfaced.
Removed (deduplicated against plugin schemas):
- Firecrawl Cloud → plugins.web.firecrawl
- Exa → plugins.web.exa
- Parallel → plugins.web.parallel
- Tavily → plugins.web.tavily
- SearXNG → plugins.web.searxng
- Brave Search (Free Tier) → plugins.web.brave_free
- DuckDuckGo (ddgs) → plugins.web.ddgs (post_setup hook preserved)
Retained in TOOL_CATEGORIES["web"]:
- Nous Subscription — requires requires_nous_auth +
managed_nous_feature + override_env_vars
to drive the managed-gateway UX. Not a
provider — a different *setup flow* for the
firecrawl backend.
- Firecrawl Self-Hosted — points firecrawl at a private Docker URL
via FIRECRAWL_API_URL only. Same reason:
UX setup-flow row, not a provider.
These two rows describe alternative auth/billing paths for the
firecrawl backend; they intentionally share web_backend="firecrawl"
with the plugin row but light up different env-var prompts.
Plugin schema extensions
------------------------
- ddgs plugin's get_setup_schema() now emits `post_setup: "ddgs"` so
selection still triggers the pip-install hook in _run_post_setup().
- _plugin_web_search_providers() passes `post_setup` through verbatim
when present in the schema (other future plugins like camofox / a
hypothetical playwright-web plugin can opt in the same way).
- Picker rows now carry both `web_backend` (legacy field consumed by
setup + selection helpers) and `web_search_plugin_name`
(informational marker), so behavior is identical between hardcoded
and plugin-registered rows.
Net diff
--------
- hermes_cli/tools_config.py: -141/+50 lines (~91 lines net)
- plugins/web/ddgs/provider.py: +7/-4 (post_setup field + badge polish)
Verified
--------
- Compile-clean for both files
- Picker shows: 2 hardcoded rows (Nous Subscription, Firecrawl
Self-Hosted) + 7 plugin rows (alphabetically: Brave Search,
DuckDuckGo, Exa, Firecrawl, Parallel, SearXNG, Tavily). DuckDuckGo
row carries post_setup="ddgs" for first-time install.
- 173 web-specific tests still pass.
104 lines
3.7 KiB
Python
104 lines
3.7 KiB
Python
"""DuckDuckGo search — plugin form (via the ``ddgs`` package).
|
|
|
|
Subclasses the plugin-facing :class:`agent.web_search_provider.WebSearchProvider`.
|
|
The legacy in-tree module ``tools.web_providers.ddgs`` was removed in the
|
|
same commit that moved this code under ``plugins/``; this file is now the
|
|
canonical implementation.
|
|
|
|
The ``ddgs`` package is an optional dependency. ``is_available()`` reflects
|
|
whether the package is importable; the plugin still registers either way so
|
|
``hermes tools`` can prompt the user to install it.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from typing import Any, Dict
|
|
|
|
from agent.web_search_provider import WebSearchProvider
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class DDGSWebSearchProvider(WebSearchProvider):
|
|
"""DuckDuckGo HTML-scrape search provider.
|
|
|
|
No API key needed. Rate limits are enforced server-side by DuckDuckGo;
|
|
the provider surfaces ``DuckDuckGoSearchException`` and other ddgs errors
|
|
as ``{"success": False, "error": ...}`` rather than raising.
|
|
"""
|
|
|
|
@property
|
|
def name(self) -> str:
|
|
return "ddgs"
|
|
|
|
@property
|
|
def display_name(self) -> str:
|
|
return "DuckDuckGo (ddgs)"
|
|
|
|
def is_available(self) -> bool:
|
|
"""Return True when the ``ddgs`` package is importable.
|
|
|
|
Probes the import once; cheap because Python caches the import. Must
|
|
NOT perform network I/O — runs at tool-registration time and on every
|
|
``hermes tools`` paint.
|
|
"""
|
|
try:
|
|
import ddgs # noqa: F401
|
|
|
|
return True
|
|
except ImportError:
|
|
return False
|
|
|
|
def supports_search(self) -> bool:
|
|
return True
|
|
|
|
def supports_extract(self) -> bool:
|
|
return False
|
|
|
|
def search(self, query: str, limit: int = 5) -> Dict[str, Any]:
|
|
"""Execute a DuckDuckGo search and return normalized results."""
|
|
try:
|
|
from ddgs import DDGS # type: ignore
|
|
except ImportError:
|
|
return {
|
|
"success": False,
|
|
"error": "ddgs package is not installed — run `pip install ddgs`",
|
|
}
|
|
|
|
# DDGS().text yields at most `max_results` items; we cap defensively
|
|
# in case the package ignores the hint.
|
|
safe_limit = max(1, int(limit))
|
|
|
|
try:
|
|
web_results = []
|
|
with DDGS() as client:
|
|
for i, hit in enumerate(client.text(query, max_results=safe_limit)):
|
|
if i >= safe_limit:
|
|
break
|
|
url = str(hit.get("href") or hit.get("url") or "")
|
|
web_results.append(
|
|
{
|
|
"title": str(hit.get("title", "")),
|
|
"url": url,
|
|
"description": str(hit.get("body", "")),
|
|
"position": i + 1,
|
|
}
|
|
)
|
|
except Exception as exc: # noqa: BLE001 — ddgs raises its own exceptions
|
|
logger.warning("DDGS search error: %s", exc)
|
|
return {"success": False, "error": f"DuckDuckGo search failed: {exc}"}
|
|
|
|
logger.info("DDGS search '%s': %d results (limit %d)", query, len(web_results), limit)
|
|
return {"success": True, "data": {"web": web_results}}
|
|
|
|
def get_setup_schema(self) -> Dict[str, Any]:
|
|
return {
|
|
"name": "DuckDuckGo (ddgs)",
|
|
"badge": "free · no key · search only",
|
|
"tag": "Search via the ddgs Python package — no API key (pair with any extract provider)",
|
|
"env_vars": [],
|
|
# Trigger `_run_post_setup("ddgs")` after the user picks this row
|
|
# so the ddgs Python package gets pip-installed on first selection.
|
|
"post_setup": "ddgs",
|
|
}
|