Skip to content

The agent that grows with you

fix(tools): light the Nous row when one web capability is pinned to the gateway

Teknium32859234d470
diff --git a/hermes_cli/tools_config_providers.py b/hermes_cli/tools_config_providers.py
index db50d6b1ee4..ce563de4f7e 100644
--- a/hermes_cli/tools_config_providers.py
+++ b/hermes_cli/tools_config_providers.py
@@ -348,41 +348,37 @@ def _web_tier_matches(provider: dict, config: dict) -> bool:
return row_tier == ("paid" if has_key else "free")
-def _web_backend_active(provider: dict, config: dict) -> bool:
- """True when a web row's ``web_backend`` serves either capability as configured.
-
- ``web_search``/``web_extract`` resolve their own ``web.search_backend`` /
- ``web.extract_backend`` override first and only then fall back to the shared
- ``web.backend`` (``tools/web_tools.py``: ``_get_search_backend`` /
- ``_get_extract_backend``), so a vendor serving one capability through its
- override is in use even when the shared key names a different one. An override
- shadows the shared key for its own capability only, so the shared key still
- serves whichever capability was left without one. Managed Nous rows never reach
- here — they answer in ``_managed_provider_active``.
- """
- backend = provider.get("web_backend")
- if not backend:
- return False
+def _web_serving_backends(config: dict) -> set:
+ """Backend names serving web search / extract as configured: each capability's own
+ ``web.<cap>_backend`` override first, else the shared ``web.backend`` (``tools/web_tools.py``
+ dispatch order; legacy ``use_gateway: true`` reads as the managed ``nous`` selection).
+ Lower-cased and stripped like the dispatchers."""
raw_web_cfg = config.get("web")
web_cfg = raw_web_cfg if isinstance(raw_web_cfg, dict) else {}
- # Dispatch lower-cases and strips the configured name; compare the same way.
+
def _name(key: str) -> str:
value = web_cfg.get(key)
return value.lower().strip() if isinstance(value, str) else ""
- shared = _name("backend")
- serving = {
- _name(key) or shared # per-capability override wins, else the shared key
- for key in ("search_backend", "extract_backend")
- }
+ shared = NOUS_MANAGED_PROVIDER if is_truthy_value(web_cfg.get("use_gateway"), default=False) else _name("backend")
+ serving = {_name(key) or shared for key in ("search_backend", "extract_backend")}
serving.discard("")
- return backend in serving and _web_tier_matches(provider, config)
+ return serving
+
+
+def _web_backend_active(provider: dict, config: dict) -> bool:
+ """True when a web row's ``web_backend`` serves either capability as configured: a vendor serving
+ one capability through its override is in use even when the shared key names a different one,
+ and a shared vendor shadowed by both overrides serves nothing. Managed Nous rows never reach
+ here — they answer in ``_managed_provider_active``."""
+ backend = provider.get("web_backend")
+ return bool(backend) and backend in _web_serving_backends(config) and _web_tier_matches(provider, config)
# Managed-row marker -> (config section, key) the pick writes, in check order.
_MANAGED_SELECTION_KEYS: tuple[tuple[str, str, str], ...] = (
("tts_provider", "tts", "provider"), ("stt_provider", "stt", "provider"),
- ("browser_provider", "browser", "cloud_provider"), ("web_backend", "web", "backend"))
+ ("browser_provider", "browser", "cloud_provider"))
def _has_marker(provider: dict, marker: str) -> bool:
@@ -413,13 +409,14 @@ def _managed_provider_active(provider: dict, config: dict, managed_feature: str,
return feature.managed_by_nous
# Browser Use mode is a driver on top of the provider (attaches to its CDP endpoint), so the browser
# provider row stays active alongside the Browser Use row.
+ if _has_marker(provider, "web_backend"):
+ # Search and extract pick their route separately: the managed row serves whichever one
+ # resolves to the gateway (a ``nous`` override, or the shared ``nous`` selection).
+ return feature.managed_by_nous and NOUS_MANAGED_PROVIDER in _web_serving_backends(config)
for marker, section, key in _MANAGED_SELECTION_KEYS:
if _has_marker(provider, marker):
current = cfg_get(config, section, key)
- selected = current in {provider[marker], NOUS_MANAGED_PROVIDER}
- if marker == "web_backend":
- selected = selected and _web_tier_matches(provider, config)
- return feature.managed_by_nous and selected
+ return feature.managed_by_nous and current in {provider[marker], NOUS_MANAGED_PROVIDER}
return feature.managed_by_nous
diff --git a/tests/tools/test_web_picker_active_rows.py b/tests/tools/test_web_picker_active_rows.py
index f25aac0991d..046275b24c7 100644
--- a/tests/tools/test_web_picker_active_rows.py
+++ b/tests/tools/test_web_picker_active_rows.py
@@ -4,9 +4,11 @@
first and only then fall back to the shared ``web.backend`` (tools/web_tools.py
``_get_search_backend`` / ``_get_extract_backend``). The picker row's ``is_active``
must follow the same precedence, otherwise a vendor that is genuinely serving one
-capability is displayed as inactive.
+capability is displayed as inactive (#132511).
"""
+import types
+
import pytest
from hermes_cli.tools_config_providers import _is_provider_active
@@ -15,105 +17,44 @@ from hermes_cli.tools_config_providers import _is_provider_active
@pytest.fixture(autouse=True)
def _no_web_env(monkeypatch):
"""Keep tier auto-detection out of the picture: no web credentials present."""
- for var in (
- "EXA_API_KEY",
- "PARALLEL_API_KEY",
- "TAVILY_API_KEY",
- "FIRECRAWL_API_KEY",
- "FIRECRAWL_API_URL",
- ):
+ for var in ("EXA_API_KEY", "PARALLEL_API_KEY", "TAVILY_API_KEY", "FIRECRAWL_API_KEY", "FIRECRAWL_API_URL"):
monkeypatch.delenv(var, raising=False)
- monkeypatch.setattr(
- "agent.web_search_provider.get_provider_env", lambda name: "", raising=True
- )
+ monkeypatch.setattr("agent.web_search_provider.get_provider_env", lambda name: "", raising=True)
def _row(backend: str, **extra) -> dict:
return {"name": backend, "web_backend": backend, "env_vars": [], **extra}
-class TestSplitCapabilityRowsAreActive:
- def test_extract_only_backend_is_active(self):
- """The reported config: search on firecrawl, extract on tavily."""
- config = {
- "web": {
- "search_backend": "firecrawl",
- "extract_backend": "tavily",
- "backend": "firecrawl",
- }
- }
- assert _is_provider_active(_row("tavily"), config) is True
-
- def test_search_only_backend_is_active(self):
- config = {
- "web": {
- "search_backend": "searxng",
- "extract_backend": "firecrawl",
- "backend": "firecrawl",
- }
- }
- assert _is_provider_active(_row("searxng"), config) is True
-
- def test_shared_key_fallback_still_highlights(self):
- """Neither per-capability key set → shared ``web.backend`` decides, as before."""
- config = {"web": {"backend": "tavily"}}
- assert _is_provider_active(_row("tavily"), config) is True
- assert _is_provider_active(_row("firecrawl"), config) is False
-
- def test_unrelated_backend_stays_inactive(self):
- config = {
- "web": {
- "search_backend": "firecrawl",
- "extract_backend": "tavily",
- "backend": "firecrawl",
- }
- }
- assert _is_provider_active(_row("ddgs"), config) is False
- assert _is_provider_active(_row("searxng"), config) is False
-
- def test_backend_naming_one_capability_does_not_claim_the_other(self):
- """``search_backend: tavily`` alone: tavily serves search, not extract."""
- config = {"web": {"search_backend": "tavily", "backend": "firecrawl"}}
- assert _is_provider_active(_row("tavily"), config) is True
- assert _is_provider_active(_row("firecrawl"), config) is True
-
- def test_shared_key_shadowed_by_both_overrides(self):
- """An override shadows the shared key for its own capability only — when both
- capabilities are overridden, the shared vendor serves neither and must not be
- highlighted."""
- config = {
- "web": {
- "search_backend": "searxng",
- "extract_backend": "tavily",
- "backend": "firecrawl",
- }
- }
- assert _is_provider_active(_row("searxng"), config) is True
- assert _is_provider_active(_row("tavily"), config) is True
- assert _is_provider_active(_row("firecrawl"), config) is False
-
- def test_empty_capability_keys_fall_back_to_shared(self):
- """Blank overrides are what a cleared selection leaves behind."""
- config = {"web": {"search_backend": "", "extract_backend": None, "backend": "searxng"}}
- assert _is_provider_active(_row("searxng"), config) is True
-
- def test_case_and_whitespace_match_dispatch(self):
- """The dispatchers lower-case and strip the config value; highlighting must agree."""
- config = {"web": {"search_backend": " FireCrawl ", "backend": "tavily"}}
- assert _is_provider_active(_row("firecrawl"), config) is True
-
- def test_tier_gate_still_applies_to_capability_keys(self):
- """Tiered rows (exa/parallel free vs paid) keep the tier discriminator."""
- config = {
- "web": {
- "search_backend": "parallel",
- "provider_tier": {"parallel": "paid"},
- }
- }
- assert _is_provider_active(_row("parallel", web_tier="paid"), config) is True
- assert _is_provider_active(_row("parallel", web_tier="free"), config) is False
-
-
-class TestNonWebProvidersUnaffected:
- def test_row_without_web_backend_is_never_active(self):
- assert _is_provider_active({"name": "openai", "env_vars": []}, {"web": {}}) is False
\ No newline at end of file
[email protected]("web,active,inactive", [
+ # The reported config: search on firecrawl, extract on tavily — both rows serve something.
+ ({"search_backend": "firecrawl", "extract_backend": "tavily", "backend": "firecrawl"}, ["firecrawl", "tavily"], ["ddgs"]),
+ # An override shadows the shared key for its own capability only: shadowed twice, it serves nothing.
+ ({"search_backend": "searxng", "extract_backend": "tavily", "backend": "firecrawl"}, ["searxng", "tavily"], ["firecrawl"]),
+ # No overrides (or blank ones): the shared key decides, as before.
+ ({"search_backend": "", "extract_backend": None, "backend": "searxng"}, ["searxng"], ["firecrawl"]),
+ # Dispatch lower-cases and strips the configured name; highlighting must agree.
+ ({"search_backend": " FireCrawl ", "backend": "tavily"}, ["firecrawl", "tavily"], []),
+])
+def test_row_active_iff_it_serves_a_capability(web, active, inactive):
+ config = {"web": web}
+ assert [b for b in active if not _is_provider_active(_row(b), config)] == []
+ assert [b for b in inactive if _is_provider_active(_row(b), config)] == []
+ # Tiered rows keep the free/paid discriminator on the capability keys too.
+ tiered = {"web": {"search_backend": "parallel", "provider_tier": {"parallel": "paid"}}}
+ assert _is_provider_active(_row("parallel", web_tier="paid"), tiered) is True
+ assert _is_provider_active(_row("parallel", web_tier="free"), tiered) is False
+
+
+def test_managed_row_active_for_a_nous_capability_pin(monkeypatch):
+ """``extract_backend: nous`` (Desktop "Use for Extract" on Nous Subscription): the managed row serves
+ extract and must be active alongside the BYOK row serving search; a vendor-only config leaves it off."""
+ import hermes_cli.tools_config as tools_config
+
+ monkeypatch.setattr(tools_config, "get_nous_subscription_features", lambda *a, **k: types.SimpleNamespace(
+ features={"web": types.SimpleNamespace(managed_by_nous=True)}))
+ nous = _row("firecrawl", managed_nous_feature="web")
+ split = {"web": {"search_backend": "firecrawl", "extract_backend": "nous"}}
+ assert _is_provider_active(nous, split) is True
+ assert _is_provider_active(_row("firecrawl"), split) is True
+ assert _is_provider_active(nous, {"web": {"search_backend": "firecrawl", "extract_backend": "tavily"}}) is False