Skip to content

The agent that grows with you

fix(web): restore free fast search for anonymous guest users

kshitijk4poor96ac3d349faa
diff --git a/plugins/web/perplexity/provider.py b/plugins/web/perplexity/provider.py
index eb0b0f2a10f..49e961f5ab5 100644
--- a/plugins/web/perplexity/provider.py
+++ b/plugins/web/perplexity/provider.py
@@ -222,11 +222,10 @@ class PerplexityWebSearchProvider(WebSearchProvider):
managed = False if direct else _managed_web_search()
gateway = _managed_gateway(managed=managed) if managed else None
if gateway is None and managed:
- from tools.tool_backend_helpers import (
- NOUS_MANAGED_PROVIDER, fast_search_unavailable_message, selection_error)
+ from tools.tool_backend_helpers import NOUS_MANAGED_PROVIDER, selection_error
- raise ValueError(selection_error("web", NOUS_MANAGED_PROVIDER,
- fast_search_unavailable_message()))
+ raise ValueError(selection_error(
+ "web", NOUS_MANAGED_PROVIDER, "there is no usable Nous identity (sign in with `/login`)"))
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 8d21e644e97..2fdf64445bb 100644
--- a/tests/tools/test_web_free_fast_search.py
+++ b/tests/tools/test_web_free_fast_search.py
@@ -1,8 +1,7 @@
-"""Free managed Perplexity fast search for a REGISTERED Nous Portal identity with no usable credits
-and no tool pool. The gateway serves ``POST /search`` + ``search_type: "fast"`` without funding
-checks, so the local paid-tool gate must not block this one route while every other managed vendor
-keeps it. The anonymous guest tier is excluded — it has no Portal account behind it, so it keeps the
-keyless ring. Real config, real auth store, real selection-to-provider dispatch over local HTTP."""
+"""Free managed Perplexity fast search for any Nous identity: anonymous guest, or signed in with no
+usable credits and no tool pool. The gateway serves ``POST /search`` + ``search_type: "fast"`` without
+funding checks, so the local paid-tool gate must not block this one route while every other managed
+vendor keeps it. Real config, real auth store, real selection-to-provider dispatch over local HTTP."""
import base64
import json
@@ -96,11 +95,13 @@ def _calls(log):
return [(path, headers["Authorization"], body.get("search_type")) for path, headers, body in log]
-def test_zero_credit_portal_identity_autodetects_free_fast_search(monkeypatch, tmp_path, gateway_server):
[email protected]("state", [_nous_state(ANON, "anonymous"), _nous_state(EXHAUSTED, "oauth")])
+def test_unentitled_nous_identity_autodetects_free_fast_search(monkeypatch, tmp_path, gateway_server, state):
+ """Guests are the users this route exists for: an anonymous identity and a zero-credit account
+ both reach the gateway, while the paid gate stays closed for extract and every other vendor."""
from tools import web_tools
from tools.tool_backend_helpers import managed_nous_tools_enabled
- state = _nous_state(EXHAUSTED, "oauth")
_write_home(tmp_path / "home", monkeypatch, nous_state=state)
# Premise: the paid-tool gate is closed for this identity and stays closed for extract.
assert managed_nous_tools_enabled() is False
@@ -113,88 +114,10 @@ def test_zero_credit_portal_identity_autodetects_free_fast_search(monkeypatch, t
assert _calls(gateway_server) == [("/perplexity/search", f"Bearer {state['access_token']}", "fast")]
-def test_anonymous_guest_keeps_the_keyless_ring(monkeypatch, tmp_path, gateway_server):
- """The guest tier holds a usable Nous token, so the exclusion must come from the tier itself."""
- from tools import web_tools
- from tools.managed_tool_gateway import peek_nous_access_token, resolve_free_search_gateway
- from tools.tool_backend_helpers import fast_search_entitled
-
- _write_home(tmp_path / "home", monkeypatch, nous_state=_nous_state(ANON, "anonymous"))
- # Premise: a token IS present — anonymous is refused by entitlement, not by a missing credential.
- assert peek_nous_access_token()
- assert fast_search_entitled() is False
- assert resolve_free_search_gateway(token_reader=peek_nous_access_token) is None
-
- assert web_tools._managed_web_search() is False
- assert web_tools._get_search_backend() != "perplexity"
-
-
[email protected]("tier", ["anonymous", "Anonymous", "ANONYMOUS", " anonymous "])
-def test_anonymous_tier_is_matched_case_and_whitespace_insensitively(monkeypatch, tmp_path, gateway_server, tier):
- """The tier claim arrives verbatim from the JWT or account payload; casing must never promote
- the guest tier to the registered route."""
- from tools.managed_tool_gateway import peek_nous_access_token, resolve_free_search_gateway
- from tools.tool_backend_helpers import fast_search_entitled
-
- _write_home(tmp_path / "home", monkeypatch,
- nous_state=_nous_state({**ANON, "account_tier": tier}, "anonymous"))
-
- assert fast_search_entitled() is False
- assert resolve_free_search_gateway(token_reader=peek_nous_access_token) is None
-
-
-def test_degraded_portal_lookup_does_not_grant_free_fast_search(monkeypatch, tmp_path, gateway_server):
- """A token inside the JWT freshness window drops to the account API; when that lookup fails the
- snapshot is still stamped ``logged_in=True``, so entitlement must key on the error, not on
- ``logged_in`` alone."""
- from hermes_cli.nous_account import get_nous_portal_account_info
- from tools.tool_backend_helpers import fast_search_entitled
-
- state = _nous_state(EXHAUSTED, "oauth", exp_offset=30)
- state["portal_base_url"] = "http://127.0.0.1:9" # closed port: the lookup cannot succeed
- _write_home(tmp_path / "home", monkeypatch, nous_state=state)
-
- info = get_nous_portal_account_info()
- # Premise: the degraded snapshot claims a login, so `logged_in` alone would have granted it.
- assert info.logged_in is True and info.error is not None
- 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."""
- _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 "needs a Nous account" in result["error"]
- assert "no Nous identity" not in result["error"]
-
-
-def test_guest_whose_lookup_fails_is_still_told_it_needs_an_account(monkeypatch, tmp_path, gateway_server):
- """A failed lookup must not make a guest look like a registered identity in the refusal."""
- from hermes_cli.nous_account import get_nous_portal_account_info
-
- state = _nous_state(ANON, "anonymous", exp_offset=30)
- state["portal_base_url"] = "http://127.0.0.1:9" # closed port: the lookup cannot succeed
- _write_home(tmp_path / "home", monkeypatch, nous_state=state,
- config={"web": {"backend": "nous", "keyless_rescue": False}})
-
- info = get_nous_portal_account_info()
- # Premise: the snapshot carries the error AND the tier it could not re-read.
- assert info.error is not None and info.is_anonymous_tier is True
-
- result = _search()
-
- assert result["success"] is False
- assert "needs a Nous account" 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
- state = _nous_state(EXHAUSTED, "oauth")
+ state = _nous_state(ANON, "anonymous")
_write_home(tmp_path / "home", monkeypatch, nous_state=state, config={"web": {"keyless_rescue": True}})
monkeypatch.setenv("PERPLEXITY_GATEWAY_URL", gateway_server.base + "/down")
rescued = {"success": True, "data": {"web": [{"title": "ring", "url": "https://ring.test", "description": "", "position": 1}]}}
diff --git a/tests/tools/test_web_managed_routing.py b/tests/tools/test_web_managed_routing.py
index 93478f56aa9..942cc376236 100644
--- a/tests/tools/test_web_managed_routing.py
+++ b/tests/tools/test_web_managed_routing.py
@@ -43,11 +43,8 @@ def local_gateway(monkeypatch):
monkeypatch.setenv("PERPLEXITY_GATEWAY_URL", base + "/perplexity")
monkeypatch.setenv("FIRECRAWL_GATEWAY_URL", base)
monkeypatch.setenv("PERPLEXITY_BASE_URL", base + "/direct")
- # Only entitlement is stubbed: route and credential resolution remain real. Fast search carries
- # its own (registered-identity) gate, stubbed here to match the entitled premise; the real tier
- # resolution — including the anonymous exclusion — lives in test_web_free_fast_search.py.
+ # Only entitlement is stubbed: route and credential resolution remain real.
monkeypatch.setattr(managed_tool_gateway, "managed_nous_tools_enabled", lambda **kw: True)
- monkeypatch.setattr(managed_tool_gateway, "fast_search_entitled", lambda **kw: True)
# CI omits the firecrawl extra; stand in for the SDK, still over real HTTP.
class FirecrawlSDK:
diff --git a/tools/managed_tool_gateway.py b/tools/managed_tool_gateway.py
index 4ff76691727..2649f62fea9 100644
--- a/tools/managed_tool_gateway.py
+++ b/tools/managed_tool_gateway.py
@@ -10,7 +10,7 @@ from dataclasses import dataclass
from typing import Callable, Optional
from hermes_constants import get_hermes_home
-from tools.tool_backend_helpers import fast_search_entitled, managed_nous_tools_enabled
+from tools.tool_backend_helpers import managed_nous_tools_enabled
logger = logging.getLogger(__name__)
@@ -180,13 +180,10 @@ def resolve_managed_tool_gateway(
def resolve_free_search_gateway(token_reader: Optional[Callable[[], Optional[str]]] = None) -> Optional[ManagedToolGatewayConfig]:
- """Perplexity ``search_type: "fast"`` is served without funding checks, so it needs a registered
- Nous identity this profile may use (guest-disabled and refresh rules live in the reader) rather
- than paid entitlement. The anonymous guest tier is excluded — it has no Portal account, so it
- keeps the keyless ring. Search only: every other vendor route goes through
- :func:`resolve_managed_tool_gateway`."""
- if not fast_search_entitled():
- return None
+ """Perplexity ``search_type: "fast"`` is served to every Nous identity with no funding check, the
+ anonymous guest tier included, so it needs a token this profile may use (guest-disabled and refresh
+ rules live in the reader), not paid entitlement or a registered account. Search only: every other
+ vendor route goes through :func:`resolve_managed_tool_gateway`."""
return _vendor_gateway("perplexity", None, token_reader)
diff --git a/tools/tool_backend_helpers.py b/tools/tool_backend_helpers.py
index 2e045fccad8..a27f37680bc 100644
--- a/tools/tool_backend_helpers.py
+++ b/tools/tool_backend_helpers.py
@@ -36,38 +36,6 @@ def managed_nous_tools_enabled(*, force_fresh: bool = False) -> bool:
return bool(account_info is not None and account_info.logged_in and account_info.tool_gateway_entitled)
-def fast_search_entitled() -> bool:
- """Eligibility for the managed Perplexity ``search_type: "fast"`` route: a registered Portal
- identity of ANY tier, with no credit or tool-pool requirement — that route is served without
- funding checks. The anonymous guest tier is excluded: it has no Portal account behind it, so
- it keeps the keyless ring.
-
- Unlike :func:`managed_nous_tools_enabled` this deliberately ignores ``tool_gateway_entitled``
- (no credit requirement) and so must reject an error snapshot itself: a failed lookup is still
- stamped ``logged_in=True``, and only ``error`` distinguishes it from a real account."""
- account_info = _account_info()
- # ``error`` is load-bearing, not belt-and-braces: a failed lookup is still stamped
- # ``logged_in=True``, and the error paths that cannot recover the tier from stored state would
- # otherwise read as a registered identity.
- return bool(account_info is not None and account_info.logged_in
- and account_info.error is None and not account_info.is_anonymous_tier)
-
-
-def fast_search_unavailable_message() -> str:
- """Why the managed Perplexity search route did not resolve, phrased as a clause for
- :func:`selection_error`'s "but …" template and kept beside :func:`fast_search_entitled` so the
- predicate and its explanation cannot drift.
-
- ``FREE_TIER_NEEDS_ACCOUNT`` and ``_CHAT`` are standalone sentences, so the guest case is phrased
- as the matching clause rather than embedded verbatim."""
- account_info = _account_info()
- if account_info is not None and account_info.is_anonymous_tier:
- return "it needs a Nous account (sign in with `/login`)"
- if account_info is None or account_info.error is not None or not account_info.logged_in:
- return "there is no usable Nous identity (sign in with `/login`)"
- return "the Nous Tool Gateway is unreachable"
-
-
def nous_tool_gateway_unavailable_message(capability: str = "the Nous Tool Gateway", *,
force_fresh: bool = False) -> str:
"""Return account-aware guidance for an unavailable Nous Tool Gateway path."""
diff --git a/website/docs/user-guide/features/web-search.md b/website/docs/user-guide/features/web-search.md
index ea471a8cadd..dc57d7b1584 100644
--- a/website/docs/user-guide/features/web-search.md
+++ b/website/docs/user-guide/features/web-search.md
@@ -445,10 +445,10 @@ If no shared backend has **ever** been selected (no `web.backend` written by you
| `SEARXNG_URL` | searxng |
| `BRAVE_SEARCH_API_KEY` | brave-free |
| `ddgs` package importable | ddgs |
-| 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 |
+| Nous identity present (any account, including the free tier and anonymous guests) | 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. A registered Nous Portal identity is unaffected by that switch: managed `web_search` still applies, though `web_extract` needs a configured provider.
+**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 Nous identity (guest included) 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).