Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(bot): mark web fetch failures as errors (#6311)
z1gon21a3ca15cc64
diff --git a/bot/tests/test_web_fetch.py b/bot/tests/test_web_fetch.pynew file mode 100644index 000000000..30fd65c66--- /dev/null+++ b/bot/tests/test_web_fetch.py@@ -0,0 +1,49 @@+# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.+# SPDX-License-Identifier: AGPL-3.0++"""Tests for the VikingBot web_fetch tool."""++import json++import pytest+from vikingbot.agent.loop import _is_tool_result_success+from vikingbot.agent.tools import web+from vikingbot.agent.tools.base import ToolContext+++def _error_payload(result: str) -> dict:+ assert result.startswith("Error: ")+ assert _is_tool_result_success(result) is False+ return json.loads(result.removeprefix("Error: "))+++async def test_web_fetch_invalid_url_returns_failed_tool_result():+ result = await web.WebFetchTool().execute(ToolContext(), "ftp://example.com/private")++ assert _error_payload(result) == {+ "error": "URL validation failed: Only http/https allowed, got 'ftp'",+ "url": "ftp://example.com/private",+ }+++async def test_web_fetch_request_exception_returns_failed_tool_result(monkeypatch):+ class FailingClient:+ async def __aenter__(self):+ return self++ async def __aexit__(self, *_args):+ return False++ async def get(self, *_args, **_kwargs):+ raise RuntimeError("fetch failed")++ monkeypatch.setattr(web.httpx, "AsyncClient", lambda **_kwargs: FailingClient())++ result = await web.WebFetchTool().execute(ToolContext(), "https://example.com/")++ assert _error_payload(result) == {+ "error": "fetch failed",+ "url": "https://example.com/",+ }diff --git a/bot/vikingbot/agent/tools/web.py b/bot/vikingbot/agent/tools/web.pyindex 3b242e109..67e1fa8ff 100644--- a/bot/vikingbot/agent/tools/web.py+++ b/bot/vikingbot/agent/tools/web.py@@ -103,7 +103,9 @@ class WebFetchTool(Tool):# Validate URL before fetchingis_valid, error_msg = _validate_url(url)if not is_valid:- return json.dumps({"error": f"URL validation failed: {error_msg}", "url": url})+ return "Error: " + json.dumps(+ {"error": f"URL validation failed: {error_msg}", "url": url}+ )try:async with httpx.AsyncClient(@@ -146,7 +148,7 @@ class WebFetchTool(Tool):})except Exception as e:- return json.dumps({"error": str(e), "url": url})+ return "Error: " + json.dumps({"error": str(e), "url": url})def _to_markdown(self, html: str) -> str:"""Convert HTML to markdown."""