Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(web-search): return structured Serper errors
Xubin Ren1cfa48ad4a8a
diff --git a/nanobot/agent/tools/web.py b/nanobot/agent/tools/web.pyindex 335fc9be8..aa5645acd 100644--- a/nanobot/agent/tools/web.py+++ b/nanobot/agent/tools/web.py@@ -705,10 +705,10 @@ class WebSearchTool(Tool):return _format_results(query, items, n)except httpx.HTTPStatusError as e:if e.response.status_code == 429:- return "Error: Serper search rate limited. Try again later or reduce search frequency."- return f"Error: Serper search failed ({e.response.status_code}): {e}"+ return ToolResult.error("Error: Serper search rate limited. Try again later or reduce search frequency.")+ return ToolResult.error(f"Error: Serper search failed ({e.response.status_code}): {e}")except Exception as e:- return f"Error: Serper search failed: {e}"+ return ToolResult.error(f"Error: Serper search failed: {e}")async def _search_volcengine(self,diff --git a/tests/tools/test_web_search_tool.py b/tests/tools/test_web_search_tool.pyindex 18dbf1605..b7ad7d609 100644--- a/tests/tools/test_web_search_tool.py+++ b/tests/tools/test_web_search_tool.py@@ -3,6 +3,7 @@import httpximport pytest+from nanobot.agent.tools.registry import is_tool_error_resultfrom nanobot.agent.tools.web import WebSearchToolfrom nanobot.config.schema import WebSearchConfig@@ -271,6 +272,7 @@ async def test_serper_search_http_error(monkeypatch):tool = _tool(provider="serper", api_key="bad-serper-key")result = await tool.execute(query="serper")assert "Error: Serper search failed (403)" in result+ assert is_tool_error_result(tool.name, result)@pytest.mark.asyncio@@ -282,6 +284,7 @@ async def test_serper_search_rate_limited(monkeypatch):tool = _tool(provider="serper", api_key="serper-key")result = await tool.execute(query="serper")assert "Serper search rate limited" in result+ assert is_tool_error_result(tool.name, result)@pytest.mark.asyncio