Skip to content

Your lightweight open-source personal agent.

refactor: move search_usage to utils/searchusage, remove brave stub

Xubin Ren7ffd93f48dae
diff --git a/nanobot/command/builtin.py b/nanobot/command/builtin.py
index 81623ebd5..8ead6a131 100644
--- a/nanobot/command/builtin.py
+++ b/nanobot/command/builtin.py
@@ -64,7 +64,7 @@ async def cmd_status(ctx: CommandContext) -> OutboundMessage:
# Fetch web search provider usage (best-effort, never blocks the response)
search_usage_text: str | None = None
try:
- from nanobot.agent.tools.search_usage import fetch_search_usage
+ from nanobot.utils.searchusage import fetch_search_usage
web_cfg = getattr(getattr(loop, "config", None), "tools", None)
web_cfg = getattr(web_cfg, "web", None) if web_cfg else None
search_cfg = getattr(web_cfg, "search", None) if web_cfg else None
diff --git a/nanobot/agent/tools/search_usage.py b/nanobot/utils/searchusage.py
similarity index 89%
rename from nanobot/agent/tools/search_usage.py
rename to nanobot/utils/searchusage.py
index 70fecb8c6..3e0c86101 100644
--- a/nanobot/agent/tools/search_usage.py
+++ b/nanobot/utils/searchusage.py
@@ -81,10 +81,8 @@ async def fetch_search_usage(
if p == "tavily":
return await _fetch_tavily_usage(api_key)
- elif p == "brave":
- return await _fetch_brave_usage(api_key)
else:
- # duckduckgo, searxng, jina, unknown — no usage API
+ # brave, duckduckgo, searxng, jina, unknown — no usage API
return SearchUsageInfo(provider=p, supported=False)
@@ -171,13 +169,3 @@ def _parse_tavily_usage(data: dict[str, Any]) -> SearchUsageInfo:
)
-# ---------------------------------------------------------------------------
-# Brave
-# ---------------------------------------------------------------------------
-
-async def _fetch_brave_usage(api_key: str | None) -> SearchUsageInfo:
- """
- Brave Search does not have a public usage/quota endpoint.
- Rate-limit headers are returned per-request, not queryable standalone.
- """
- return SearchUsageInfo(provider="brave", supported=False)
diff --git a/tests/tools/test_search_usage.py b/tests/utils/test_searchusage.py
similarity index 99%
rename from tests/tools/test_search_usage.py
rename to tests/utils/test_searchusage.py
index faec41dfa..dd8c62571 100644
--- a/tests/tools/test_search_usage.py
+++ b/tests/utils/test_searchusage.py
@@ -5,7 +5,7 @@ from __future__ import annotations
import pytest
from unittest.mock import AsyncMock, MagicMock, patch
-from nanobot.agent.tools.search_usage import (
+from nanobot.utils.searchusage import (
SearchUsageInfo,
_parse_tavily_usage,
fetch_search_usage,