The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): honor env-configured local backends and persist Tool Gateway declines
Teknium8b86097a62ad
diff --git a/hermes_cli/config.py b/hermes_cli/config.pyindex 5b166427a71..8afa4f93136 100644--- a/hermes_cli/config.py+++ b/hermes_cli/config.py@@ -1999,6 +1999,7 @@ _EXTRA_KNOWN_ROOT_KEYS = {"platform_toolsets", # written by the setup wizard (hermes_cli/setup.py)"known_plugin_toolsets", # written/read by hermes_cli/tools_config.py toolset-save flow"known_builtin_toolsets", # ditto — which builtin toolsets a platform's checklist has offered+ "tool_gateway_declined_tools", # per-tool Tool Gateway offer declines (hermes_cli/nous_subscription.py, #92647)"session_reset", # top-level form read by gateway/config.py + setup"group_sessions_per_user", # top-level form bridged by gateway/config.py"thread_sessions_per_user", # top-level form bridged by gateway/config.pydiff --git a/hermes_cli/nous_subscription.py b/hermes_cli/nous_subscription.pyindex 115865ea8b5..bdd6f9532e0 100644--- a/hermes_cli/nous_subscription.py+++ b/hermes_cli/nous_subscription.py@@ -1000,6 +1000,11 @@ def _get_gateway_direct_credentials() -> Dict[str, bool]:or get_env_value("PARALLEL_API_KEY")or get_env_value("TAVILY_API_KEY")or get_env_value("EXA_API_KEY")+ # Env-configured keyless local backend: a reachable self-hosted+ # SearXNG is a working web setup even with no stored selection+ # (the autodetect cascade in tools/web_tools.py picks it up), so+ # it must not be classified "unconfigured" and pre-checked (#92647).+ or get_env_value("SEARXNG_URL")),"image_gen": fal_direct,"video_gen": fal_direct,@@ -1019,17 +1024,22 @@ def _get_gateway_direct_credentials() -> Dict[str, bool]:"browser": bool(get_env_value("BROWSER_USE_API_KEY")or (get_env_value("BROWSERBASE_API_KEY") and get_env_value("BROWSERBASE_PROJECT_ID"))+ # Env-configured keyless local backend: CAMOFOX_URL activates the+ # Camofox browser via never-configured autodetect (see+ # _resolve_browser_state above), so it counts as configured even+ # with no stored cloud_provider selection (#92647).+ or get_env_value("CAMOFOX_URL")),}_GATEWAY_DIRECT_LABELS = {- "web": "Firecrawl/Exa/Parallel/Tavily key",+ "web": "Firecrawl/Exa/Parallel/Tavily key or SearXNG","image_gen": "FAL key","video_gen": "FAL key","tts": "OpenAI/ElevenLabs key","stt": "OpenAI/Groq/Mistral key",- "browser": "Browser Use/Browserbase key",+ "browser": "Browser Use/Browserbase key or Camofox",}_ALL_GATEWAY_KEYS = ("web", "image_gen", "video_gen", "tts", "stt", "browser")@@ -1251,13 +1261,26 @@ def prompt_enable_tool_gateway(# Per-tool checklist: unconfigured tools first (pre-checked for new users),# then tools where the user already has their own key (left unchecked so we# don't override their own setup unless they ask).+ #+ # Decline persistence (#92647): tools the user has previously seen offered+ # and left unchecked are recorded in ``tool_gateway_declined_tools`` and+ # are never pre-checked again — the offer downgrades to opt-in-only.+ # Acceptance used to be sticky while refusal was not, so the identical+ # pre-checked checklist re-fired on every Nous model swap.+ declined_raw = config.get("tool_gateway_declined_tools")+ declined: set[str] = (+ {str(k) for k in declined_raw} if isinstance(declined_raw, list) else set()+ )+offer_keys: list[str] = list(unconfigured) + list(has_direct)labels: list[str] = [_GATEWAY_TOOL_LABELS[k] for k in unconfigured]labels += [f"{_GATEWAY_TOOL_LABELS[k]} — keep using your {_GATEWAY_DIRECT_LABELS[k]}"for k in has_direct]- pre_selected = list(range(len(unconfigured)))+ pre_selected = [+ i for i, k in enumerate(unconfigured) if k not in declined+ ]if pool_only:title = "Your free Nous tool pool — pick the tools to enable:"@@ -1273,11 +1296,28 @@ def prompt_enable_tool_gateway(return set()chosen_keys = [offer_keys[i] for i in chosen_idx if 0 <= i < len(offer_keys)]++ # Persist per-tool declines: every unconfigured tool that was offered and+ # NOT chosen was actively left (or unchecked) by the user — remember that+ # so the next Nous model swap doesn't pre-check it again. Cancel paths+ # (Ctrl-C/ESC above) return before this and record nothing. Choosing a+ # previously-declined tool clears its decline.+ newly_declined = [k for k in unconfigured if k not in chosen_keys and k not in declined]+ undeclined = declined & set(chosen_keys)+ if newly_declined or undeclined:+ config["tool_gateway_declined_tools"] = sorted(+ (declined | set(newly_declined)) - set(chosen_keys)+ )+if not chosen_keys:+ if newly_declined:+ from hermes_cli.config import save_config++ save_config(config)return set()changed = apply_gateway_defaults(config, chosen_keys)- if changed:+ if changed or newly_declined:from hermes_cli.config import save_configsave_config(config)diff --git a/tests/hermes_cli/test_nous_subscription.py b/tests/hermes_cli/test_nous_subscription.pyindex e71f1145633..c9ffaa931a0 100644--- a/tests/hermes_cli/test_nous_subscription.py+++ b/tests/hermes_cli/test_nous_subscription.py@@ -295,6 +295,86 @@ def test_prompt_enable_tool_gateway_never_offers_explicit_backend(monkeypatch):assert "image" in blob # other unconfigured tools still offered+def test_gateway_direct_credentials_honor_env_configured_local_backends(monkeypatch):+ """SEARXNG_URL / CAMOFOX_URL are env-configured keyless local backends+ with no stored selection — they must still count as direct credentials+ so the tool is offered unchecked, never pre-checked (#92647)."""+ monkeypatch.setattr(+ ns,+ "get_env_value",+ lambda name: "http://localhost:9377" if name in ("SEARXNG_URL", "CAMOFOX_URL") else "",+ )+ monkeypatch.setattr(ns, "fal_key_is_configured", lambda: False)+ monkeypatch.setattr(ns, "resolve_openai_audio_api_key", lambda: None)++ direct = ns._get_gateway_direct_credentials()++ assert direct["web"] is True+ assert direct["browser"] is True+ assert direct["image_gen"] is False+++def test_prompt_enable_tool_gateway_persists_decline(monkeypatch):+ """Submitting the checklist with a tool left unchecked records it in+ tool_gateway_declined_tools and never pre-checks it again (#92647:+ acceptance was sticky, refusal was not)."""+ monkeypatch.setattr(ns, "get_nous_portal_account_info", lambda **kw: _account(logged_in=True, paid=True))+ monkeypatch.setattr(+ ns,+ "_get_gateway_direct_credentials",+ lambda: {"web": False, "image_gen": False, "video_gen": False, "tts": False, "stt": False, "browser": False},+ )+ saved = []+ captured = _capture_checklist(monkeypatch, selected_idx=[])+ monkeypatch.setattr(+ "hermes_cli.config.save_config", lambda cfg: saved.append(dict(cfg)), raising=False+ )++ config = {"model": {"provider": "nous"}}+ assert ns.prompt_enable_tool_gateway(config) == set()++ # First offer: everything pre-checked, decline recorded and saved.+ assert captured["pre_selected"] == list(range(len(captured["items"])))+ declined = config.get("tool_gateway_declined_tools")+ assert isinstance(declined, list) and "web" in declined and "browser" in declined+ assert saved, "decline must be persisted via save_config"++ # Second offer with the recorded declines: nothing is pre-checked.+ captured2 = _capture_checklist(monkeypatch, selected_idx=[])+ monkeypatch.setattr(+ "hermes_cli.config.save_config", lambda cfg: saved.append(dict(cfg)), raising=False+ )+ ns.prompt_enable_tool_gateway(config)+ assert captured2["pre_selected"] == []+++def test_prompt_enable_tool_gateway_choosing_declined_tool_clears_decline(monkeypatch):+ """Opting in to a previously-declined tool removes it from the decline+ list, so state tracks the user's latest explicit choice."""+ monkeypatch.setattr(ns, "get_nous_portal_account_info", lambda **kw: _account(logged_in=True, paid=True))+ monkeypatch.setattr(+ ns,+ "_get_gateway_direct_credentials",+ lambda: {"web": False, "image_gen": False, "video_gen": False, "tts": False, "stt": False, "browser": False},+ )+ captured = _capture_checklist(monkeypatch, selected_idx=[0])++ config = {+ "model": {"provider": "nous"},+ "tool_gateway_declined_tools": ["browser", "web"],+ }+ ns.prompt_enable_tool_gateway(config)++ # The first offered key was chosen; it must leave the decline list.+ chosen_key = None+ for key, label in ns._GATEWAY_TOOL_LABELS.items():+ if captured["items"][0].startswith(label):+ chosen_key = key+ break+ assert chosen_key is not None+ assert chosen_key not in config["tool_gateway_declined_tools"]++def test_apply_nous_managed_defaults_writes_video_gen_config(monkeypatch):"""apply_nous_managed_defaults must store the managed 'nous' selectionwhen a Nous subscriber selects video_gen without a direct FAL_KEY."""diff --git a/website/docs/user-guide/features/tool-gateway.md b/website/docs/user-guide/features/tool-gateway.mdindex 247b4ed383b..ee828cbb466 100644--- a/website/docs/user-guide/features/tool-gateway.md+++ b/website/docs/user-guide/features/tool-gateway.md@@ -84,6 +84,15 @@ The Tool Gateway is a **paid-subscription** feature. Free-tier Nous accounts canSome accounts are also entitled to a **free tool pool** — a small managed-tool allowance that covers gateway tool calls without a paid subscription. When a free pool is available, the gateway surfaces it and shows a setup prompt on first use, so you can opt in and start using managed tools right away.+## The enablement checklist++Picking a Nous model (`hermes model`) offers a per-tool checklist of gateway backends. Its behavior respects your existing setup:++- Tools you've explicitly pointed at another backend (e.g. `web.backend: searxng`, `browser.cloud_provider: camofox`) are **never offered** — your selection can't be accidentally overwritten.+- Tools configured via environment variables alone (e.g. `SEARXNG_URL`, `CAMOFOX_URL`) are offered **unchecked**, labeled to keep your own backend.+- Only genuinely unconfigured tools come pre-checked.+- Declines stick: if you submit the checklist with a tool unchecked, it won't be pre-checked on future Nous model swaps (stored in `tool_gateway_declined_tools` in `config.yaml`; checking it later clears the decline).+## Mix and matchThe gateway is per-tool. Turn it on for just what you want: