Skip to content

Your lightweight open-source personal agent.

merge origin/main into pr-1071, adopt @property api_key pattern

Re-bin4b9ffea3fcf0
diff --cc nanobot/agent/tools/web.py
index ae69e9e4a,82eca83d4..56956c30e
--- a/nanobot/agent/tools/web.py
+++ b/nanobot/agent/tools/web.py
@@@ -58,21 -58,16 +58,20 @@@ class WebSearchTool(Tool)
}
def __init__(self, api_key: str | None = None, max_results: int = 5):
- self.api_key = api_key
+ self._init_api_key = api_key
self.max_results = max_results
+ @property
+ def api_key(self) -> str:
+ """Resolve API key at call time so env/config changes are picked up."""
+ return self._init_api_key or os.environ.get("BRAVE_API_KEY", "")
-
++
async def execute(self, query: str, count: int | None = None, **kwargs: Any) -> str:
- api_key = self.api_key or os.environ.get("BRAVE_API_KEY", "")
- if not api_key:
+ if not self.api_key:
return (
"Error: Brave Search API key not configured. "
- "Set BRAVE_API_KEY environment variable or add "
- "tools.web.search.apiKey to ~/.nanobot/config.json, "
- "then restart the gateway."
+ "Set it in ~/.nanobot/config.json under tools.web.search.apiKey "
+ "(or export BRAVE_API_KEY), then restart the gateway."
)
try: