Skip to content

The agent that grows with you

feat: keyless free-tier failover + Tavily/Firecrawl salvage integration

Teknium2eb5217af955
diff --git a/plugins/web/exa/provider.py b/plugins/web/exa/provider.py
index 1f4dde6f162..a388e3ad0ad 100644
--- a/plugins/web/exa/provider.py
+++ b/plugins/web/exa/provider.py
@@ -143,14 +143,14 @@ class ExaWebSearchProvider(WebSearchProvider):
from agent.web_search_provider import get_provider_env
- from plugins.web.keyless_mcp import exa_search_keyless, use_keyless
+ from plugins.web.keyless_mcp import search_with_failover, use_keyless
if use_keyless("exa", get_provider_env("EXA_API_KEY")):
# Keyless free tier — public MCP endpoint, no SDK needed.
logger.info(
"Exa keyless search: '%s' (limit=%d)", query, limit
)
- return exa_search_keyless(query, limit)
+ return search_with_failover("exa", query, limit)
logger.info("Exa search: '%s' (limit=%d)", query, limit)
response = _get_exa_client().search(
@@ -198,12 +198,12 @@ class ExaWebSearchProvider(WebSearchProvider):
from agent.web_search_provider import get_provider_env
- from plugins.web.keyless_mcp import exa_extract_keyless, use_keyless
+ from plugins.web.keyless_mcp import extract_with_failover, use_keyless
if use_keyless("exa", get_provider_env("EXA_API_KEY")):
# Keyless free tier — public MCP endpoint, no SDK needed.
logger.info("Exa keyless extract: %d URL(s)", len(urls))
- return exa_extract_keyless(list(urls))
+ return extract_with_failover("exa", list(urls))
logger.info("Exa extract: %d URL(s)", len(urls))
response = _get_exa_client().get_contents(urls, text=True)
diff --git a/plugins/web/keyless_mcp.py b/plugins/web/keyless_mcp.py
index df21069abcd..462625ee84a 100644
--- a/plugins/web/keyless_mcp.py
+++ b/plugins/web/keyless_mcp.py
@@ -46,6 +46,23 @@ class KeylessMCPError(RuntimeError):
"""A keyless MCP call failed (transport, rate limit, or tool error)."""
+_RATE_LIMIT_MARKERS = (
+ "rate limit",
+ "rate-limit",
+ "ratelimit",
+ "too many requests",
+ "429",
+ "quota exceeded",
+ "slow down",
+)
+
+
+def _is_rate_limitish(message: str) -> bool:
+ """Heuristic: does an error message look like free-tier throttling?"""
+ lowered = (message or "").lower()
+ return any(marker in lowered for marker in _RATE_LIMIT_MARKERS)
+
+
def keyless_enabled() -> bool:
"""Return True when the keyless fallback tier is enabled.
@@ -418,3 +435,92 @@ def exa_extract_keyless(urls: List[str]) -> List[Dict[str, Any]]:
}
)
return results
+
+
+# ---------------------------------------------------------------------------
+# Cross-vendor failover (rate-limited free tiers)
+# ---------------------------------------------------------------------------
+
+_KEYLESS_SEARCHERS = {
+ "exa": lambda query, limit: exa_search_keyless(query, limit),
+ "parallel": lambda query, limit: parallel_search_keyless(query, limit),
+}
+
+_KEYLESS_EXTRACTORS = {
+ "exa": lambda urls: exa_extract_keyless(urls),
+ "parallel": lambda urls: parallel_extract_keyless(urls),
+}
+
+
+def _failover_peer(name: str) -> Optional[str]:
+ """Return the OTHER keyless vendor, or None when failover is off.
+
+ Only fires in auto/free tiers: a user who explicitly pinned a paid
+ tier for the peer (``web.provider_tier.<peer>: paid``) has opted the
+ peer's free endpoint out, so we respect that and don't route to it.
+ """
+ peer = {"exa": "parallel", "parallel": "exa"}.get(name)
+ if peer is None or not keyless_enabled():
+ return None
+ if provider_tier(peer) == "paid":
+ return None
+ return peer
+
+
+def search_with_failover(name: str, query: str, limit: int = 5) -> Dict[str, Any]:
+ """Keyless search via *name*, failing over to the peer vendor on throttle.
+
+ When the primary's free tier returns a rate-limit-shaped error, retry
+ once on the other vendor's free endpoint (Exa <-> Parallel). Non-throttle
+ errors are returned as-is (a malformed-query error on vendor A would
+ just fail identically on vendor B). The failover result notes which
+ vendor actually served the request via ``data.served_by``.
+ """
+ primary = _KEYLESS_SEARCHERS[name]
+ result = primary(query, limit)
+ if result.get("success") or not _is_rate_limitish(result.get("error", "")):
+ return result
+
+ peer = _failover_peer(name)
+ if peer is None:
+ return result
+ logger.info("keyless %s search throttled; failing over to %s", name, peer)
+ fallback = _KEYLESS_SEARCHERS[peer](query, limit)
+ if fallback.get("success"):
+ fallback.setdefault("data", {})["served_by"] = peer
+ return fallback
+ # Both throttled: surface the primary's error (it names the pinned
+ # vendor's key), with a note that the peer was tried too.
+ result["error"] = (
+ f"{result.get('error', '')} Failover to {peer} also failed: "
+ f"{fallback.get('error', 'unknown error')}"
+ )
+ return result
+
+
+def extract_with_failover(name: str, urls: List[str]) -> List[Dict[str, Any]]:
+ """Keyless extract via *name*, failing over per-batch on throttle.
+
+ If EVERY url in the primary's result carries a rate-limit-shaped
+ error, retry the whole batch on the peer vendor. Partial failures
+ (some URLs fine, some broken) are returned as-is — those are page
+ problems, not throttling.
+ """
+ primary = _KEYLESS_EXTRACTORS[name]
+ results = primary(list(urls))
+ errors = [r.get("error", "") for r in results]
+ all_throttled = bool(results) and all(
+ e and _is_rate_limitish(e) for e in errors
+ )
+ if not all_throttled:
+ return results
+
+ peer = _failover_peer(name)
+ if peer is None:
+ return results
+ logger.info("keyless %s extract throttled; failing over to %s", name, peer)
+ fallback = _KEYLESS_EXTRACTORS[peer](list(urls))
+ fallback_errors = [r.get("error", "") for r in fallback]
+ if all(e and _is_rate_limitish(e) for e in fallback_errors):
+ return results # both throttled: keep primary's key guidance
+ return fallback
diff --git a/plugins/web/parallel/provider.py b/plugins/web/parallel/provider.py
index 4f0f05950c6..5a9390e92fa 100644
--- a/plugins/web/parallel/provider.py
+++ b/plugins/web/parallel/provider.py
@@ -198,14 +198,14 @@ class ParallelWebSearchProvider(WebSearchProvider):
from agent.web_search_provider import get_provider_env
- from plugins.web.keyless_mcp import parallel_search_keyless, use_keyless
+ from plugins.web.keyless_mcp import search_with_failover, use_keyless
if use_keyless("parallel", get_provider_env("PARALLEL_API_KEY")):
# Keyless free tier — public MCP endpoint, no SDK needed.
logger.info(
"Parallel keyless search: '%s' (limit=%d)", query, limit
)
- return parallel_search_keyless(query, limit)
+ return search_with_failover("parallel", query, limit)
mode = _resolve_search_mode()
logger.info(
@@ -262,7 +262,7 @@ class ParallelWebSearchProvider(WebSearchProvider):
from agent.web_search_provider import get_provider_env
- from plugins.web.keyless_mcp import parallel_extract_keyless, use_keyless
+ from plugins.web.keyless_mcp import extract_with_failover, use_keyless
if use_keyless("parallel", get_provider_env("PARALLEL_API_KEY")):
# Keyless free tier — blocking HTTP, so hop off the loop.
@@ -270,7 +270,7 @@ class ParallelWebSearchProvider(WebSearchProvider):
logger.info("Parallel keyless extract: %d URL(s)", len(urls))
return await asyncio.to_thread(
- parallel_extract_keyless, list(urls)
+ extract_with_failover, "parallel", list(urls)
)
logger.info("Parallel extract: %d URL(s)", len(urls))
diff --git a/tests/tools/test_web_keyless_fallback.py b/tests/tools/test_web_keyless_fallback.py
index 175a604e3ff..74c6e5e51e0 100644
--- a/tests/tools/test_web_keyless_fallback.py
+++ b/tests/tools/test_web_keyless_fallback.py
@@ -414,3 +414,88 @@ class TestPickerTierRows:
cfg_auto = {"web": {"backend": "parallel"}}
assert _web_tier_matches(free_row, cfg_auto) is True
assert _web_tier_matches(paid_row, cfg_auto) is False
+
+
+# ---------------------------------------------------------------------------
+# Cross-vendor keyless failover
+# ---------------------------------------------------------------------------
+
+
+class TestKeylessFailover:
+ def _ok(self, vendor):
+ return {"success": True, "data": {"web": [{"url": f"https://{vendor}.example"}]}}
+
+ def _throttled(self, vendor):
+ return {"success": False, "error": f"Keyless {vendor} search failed: free MCP rate limit."}
+
+ def test_search_fails_over_on_rate_limit(self, monkeypatch):
+ monkeypatch.setattr(keyless_mcp, "exa_search_keyless", lambda q, l: self._throttled("Exa"))
+ monkeypatch.setattr(keyless_mcp, "parallel_search_keyless", lambda q, l: self._ok("parallel"))
+ out = keyless_mcp.search_with_failover("exa", "q", 3)
+ assert out["success"] is True
+ assert out["data"]["served_by"] == "parallel"
+
+ def test_search_no_failover_on_non_throttle_error(self, monkeypatch):
+ monkeypatch.setattr(
+ keyless_mcp, "exa_search_keyless",
+ lambda q, l: {"success": False, "error": "Unrecognized MCP response shape"},
+ )
+ called = []
+ monkeypatch.setattr(
+ keyless_mcp, "parallel_search_keyless",
+ lambda q, l: called.append(1) or self._ok("parallel"),
+ )
+ out = keyless_mcp.search_with_failover("exa", "q")
+ assert out["success"] is False
+ assert not called # peer never tried
+
+ def test_search_both_throttled_reports_both(self, monkeypatch):
+ monkeypatch.setattr(keyless_mcp, "exa_search_keyless", lambda q, l: self._throttled("Exa"))
+ monkeypatch.setattr(keyless_mcp, "parallel_search_keyless", lambda q, l: self._throttled("Parallel"))
+ out = keyless_mcp.search_with_failover("exa", "q")
+ assert out["success"] is False
+ assert "Failover to parallel also failed" in out["error"]
+
+ def test_failover_respects_peer_paid_pin(self, monkeypatch):
+ monkeypatch.setattr(keyless_mcp, "parallel_search_keyless", lambda q, l: self._throttled("Parallel"))
+ monkeypatch.setattr(
+ keyless_mcp, "provider_tier",
+ lambda name: "paid" if name == "exa" else "auto",
+ )
+ called = []
+ monkeypatch.setattr(
+ keyless_mcp, "exa_search_keyless",
+ lambda q, l: called.append(1) or self._ok("exa"),
+ )
+ out = keyless_mcp.search_with_failover("parallel", "q")
+ assert out["success"] is False
+ assert not called # exa pinned paid: its free tier is opted out
+
+ def test_extract_fails_over_when_all_urls_throttled(self, monkeypatch):
+ throttled = [
+ {"url": "https://a", "title": "", "content": "", "error": "rate limit hit"},
+ {"url": "https://b", "title": "", "content": "", "error": "429 too many requests"},
+ ]
+ good = [
+ {"url": "https://a", "title": "A", "content": "x"},
+ {"url": "https://b", "title": "B", "content": "y"},
+ ]
+ monkeypatch.setattr(keyless_mcp, "exa_extract_keyless", lambda urls: throttled)
+ monkeypatch.setattr(keyless_mcp, "parallel_extract_keyless", lambda urls: good)
+ out = keyless_mcp.extract_with_failover("exa", ["https://a", "https://b"])
+ assert out == good
+
+ def test_extract_partial_failure_stays_on_primary(self, monkeypatch):
+ partial = [
+ {"url": "https://a", "title": "A", "content": "x"},
+ {"url": "https://b", "title": "", "content": "", "error": "rate limit"},
+ ]
+ called = []
+ monkeypatch.setattr(keyless_mcp, "exa_extract_keyless", lambda urls: partial)
+ monkeypatch.setattr(
+ keyless_mcp, "parallel_extract_keyless",
+ lambda urls: called.append(1) or [],
+ )
+ out = keyless_mcp.extract_with_failover("exa", ["https://a", "https://b"])
+ assert out == partial
+ assert not called
diff --git a/website/docs/user-guide/features/web-search.md b/website/docs/user-guide/features/web-search.md
index cd89aab0905..e9cd8dc6997 100644
--- a/website/docs/user-guide/features/web-search.md
+++ b/website/docs/user-guide/features/web-search.md
@@ -18,7 +18,7 @@ Both are configured through a single backend selection. Providers are chosen via
| Provider | Env Var | Search | Extract | Free tier |
|----------|---------|--------|---------|-----------|
-| **Firecrawl** (default) | `FIRECRAWL_API_KEY` | ✔ | ✔ | 500 credits/mo |
+| **Firecrawl** (default) | `FIRECRAWL_API_KEY` (optional — keyless when selected) | ✔ | ✔ | 500 credits/mo · keyless cloud when selected |
| **SearXNG** | `SEARXNG_URL` | ✔ | — | ✔ Free (self-hosted) |
| **Brave Search (free tier)** | `BRAVE_SEARCH_API_KEY` | ✔ | — | 2 000 queries/mo |
| **DDGS (DuckDuckGo)** | — (no key) | ✔ | — | ✔ Free |
@@ -32,7 +32,9 @@ Brave Search, DDGS, and xAI are **search-only** — pair any of them with Firecr
**Per-capability split:** you can use different providers for search and extract independently — for example SearXNG (free) for search and Firecrawl for extract. See [Per-capability configuration](#per-capability-configuration) below.
:::info Works out of the box — keyless free tier
-A fresh install with **no web credentials at all** still gets working `web_search` and `web_extract`: Hermes falls back to Exa's and Parallel's public anonymous endpoints (rate-limited free tiers), splitting unpinned installs 50/50 between the two vendors — the pick is random per process and stable within it. No signup, no key. This tier is strictly last-resort — any configured backend or present API key always wins — and requests carry no user identifiers (only a random per-process session id, rotated on restart). For reliable, unthrottled service, set up a keyed provider. Disable the keyless tier entirely with `web.keyless_fallback: false`.
+A fresh install with **no web credentials at all** still gets working `web_search` and `web_extract`: Hermes falls back to Exa's and Parallel's public anonymous endpoints (rate-limited free tiers), splitting unpinned installs 50/50 between the two vendors — the pick is random per process and stable within it. If one vendor's free tier throttles a request, Hermes automatically retries it once on the other vendor's free tier. No signup, no key. This tier is strictly last-resort — any configured backend or present API key always wins — and requests carry no user identifiers (only a random per-process session id, rotated on restart). For reliable, unthrottled service, set up a keyed provider. Disable the keyless tier entirely with `web.keyless_fallback: false`.
+
+Tavily and Firecrawl also offer keyless access when **explicitly selected** (`web.backend: tavily` / `firecrawl` or via `hermes tools`) — they are not part of the automatic zero-config fallback, but picking them without entering a key now works instead of erroring.
:::
**Choosing free vs paid explicitly:** in `hermes tools`, Exa and Parallel each appear as two rows — **Free (keyless)** and **Paid (API key)**. Picking Free pins the anonymous endpoint (even if you later add a key); picking Paid pins the keyed SDK path (a missing key then errors instead of silently downgrading to the free tier). The selection is stored as `web.provider_tier.<name>: free|paid`; leave it unset for auto (key present → paid, otherwise free).