Skip to content

The agent that grows with you

fix(web): honest guest refusal, and one route walk per search dispatch

kshitijk4poor9ab49e73b48b
diff --git a/plugins/web/perplexity/provider.py b/plugins/web/perplexity/provider.py
index 173b758d672..eb2bb6cfa99 100644
--- a/plugins/web/perplexity/provider.py
+++ b/plugins/web/perplexity/provider.py
@@ -71,12 +71,18 @@ def _missing_key_error() -> str:
return f"PERPLEXITY_API_KEY is not set. Get a key at {_KEY_URL}"
-def _managed_gateway(token_reader=None):
- """Nous Tool Gateway config when web_search is on the managed route, else None."""
+def _managed_gateway(token_reader=None, managed=None):
+ """Nous Tool Gateway config when web_search is on the managed route, else None.
+
+ ``managed`` lets a caller that already resolved the route reuse that answer instead of
+ walking the autodetect ladder again."""
from tools import managed_tool_gateway as gw
- from tools.web_tools import _managed_web_search
- if not _managed_web_search():
+ if managed is None:
+ from tools.web_tools import _managed_web_search
+
+ managed = _managed_web_search()
+ if not managed:
return None
return gw.resolve_free_search_gateway(token_reader=token_reader)
@@ -213,11 +219,17 @@ class PerplexityWebSearchProvider(WebSearchProvider):
from tools.web_tools import _managed_web_search
direct = bool(get_provider_env("PERPLEXITY_API_KEY"))
- gateway = None if direct else _managed_gateway()
- if gateway is None and not direct and _managed_web_search():
+ managed = False if direct else _managed_web_search()
+ gateway = _managed_gateway(managed=managed) if managed else None
+ if gateway is None and managed:
+ from hermes_cli.nous_account import FREE_TIER_NEEDS_ACCOUNT, get_nous_portal_account_info
from tools.tool_backend_helpers import NOUS_MANAGED_PROVIDER, selection_error
- raise ValueError(selection_error(
- "web", NOUS_MANAGED_PROVIDER, "the Nous Tool Gateway is not available (no Nous identity or unreachable)"))
+
+ # A guest holds a real identity but is excluded by tier, so it must not be told
+ # there is no identity.
+ failure = (FREE_TIER_NEEDS_ACCOUNT if get_nous_portal_account_info().is_anonymous_tier
+ else "the Nous Tool Gateway is not available (unreachable)")
+ raise ValueError(selection_error("web", NOUS_MANAGED_PROVIDER, failure))
logger.info("Perplexity search: '%s' (limit=%d%s)", query, limit, ", managed" if gateway else "")
payload = {
"query": query,
diff --git a/tests/tools/test_web_free_fast_search.py b/tests/tools/test_web_free_fast_search.py
index c7c565d4b0c..cc9de07f8d2 100644
--- a/tests/tools/test_web_free_fast_search.py
+++ b/tests/tools/test_web_free_fast_search.py
@@ -155,6 +155,20 @@ def test_degraded_portal_lookup_does_not_grant_free_fast_search(monkeypatch, tmp
assert fast_search_entitled() is False
+def test_guest_on_a_stored_nous_selection_is_told_it_needs_an_account(monkeypatch, tmp_path, gateway_server):
+ """A guest holds a real Nous identity, so the refusal must not claim it has none."""
+ from hermes_cli.nous_account import FREE_TIER_NEEDS_ACCOUNT
+
+ _write_home(tmp_path / "home", monkeypatch, nous_state=_nous_state(ANON, "anonymous"),
+ config={"web": {"backend": "nous", "keyless_rescue": False}})
+
+ result = _search()
+
+ assert result["success"] is False
+ assert FREE_TIER_NEEDS_ACCOUNT in result["error"]
+ assert "no Nous identity" not in result["error"]
+
+
def test_free_fast_search_failure_skips_paid_firecrawl_but_keeps_keyless_rescue(monkeypatch, tmp_path, gateway_server):
from plugins.web import keyless_mcp
diff --git a/website/docs/user-guide/features/web-search.md b/website/docs/user-guide/features/web-search.md
index e1c5b2b63a7..ea471a8cadd 100644
--- a/website/docs/user-guide/features/web-search.md
+++ b/website/docs/user-guide/features/web-search.md
@@ -448,7 +448,7 @@ If no shared backend has **ever** been selected (no `web.backend` written by you
| Registered Nous Portal identity (any tier, including the no-credit free tier; anonymous guests excluded) | managed web search (`web_search` only); extract and the keyless ring below are unchanged |
| *(nothing set at all)* | keyless ring: exa / parallel / firecrawl / keenable (round-robin) |
-**Keyless free-tier ring:** when *no* credential above is present, requests rotate across the ring vendors' public free tiers (Exa, Parallel, Firecrawl, Keenable) so web tools work on a fresh install with zero setup — and a rate-limited request fails over to the next vendor in the ring automatically. Pin one vendor in `hermes tools` to stop the rotation (the ring is then only used as failover succession on throttles). All free tiers are vendor-rate-limited under burst load; sustained normal usage goes through fine. Set `web.keyless_fallback: false` to turn the tier off — with it off and no credentials, web tools are unavailable until a provider is configured.
+**Keyless free-tier ring:** when *no* credential above is present, requests rotate across the ring vendors' public free tiers (Exa, Parallel, Firecrawl, Keenable) so web tools work on a fresh install with zero setup — and a rate-limited request fails over to the next vendor in the ring automatically. Pin one vendor in `hermes tools` to stop the rotation (the ring is then only used as failover succession on throttles). All free tiers are vendor-rate-limited under burst load; sustained normal usage goes through fine. Set `web.keyless_fallback: false` to turn the tier off — with it off and no credentials, web tools are unavailable until a provider is configured. A registered Nous Portal identity is unaffected by that switch: managed `web_search` still applies, though `web_extract` needs a configured provider.
**One-shot keyless rescue for keyed backends:** when your chosen/keyed backend — including the Nous Tool Gateway route (`web.backend: nous`) — fails a call (bad key, outage, unreachable gateway, upstream 5xx), that single call automatically retries on the keyless free-tier ring instead of erroring — the result notes which vendor served it and why (`rescued_from` / `backend_error`). The failover is never sticky: the very next `web_search`/`web_extract` call attempts your chosen backend again. Disable with `web.keyless_rescue: false` (also off whenever `keyless_fallback` is off).