From d247adb60c06d4cfd9734cd244262f624cf9bcaa Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Sat, 21 Feb 2026 21:49:19 +0100 Subject: [PATCH] feat: add citation sources for fetch_url tool results (#21669) feat: add citation sources for fetch_url tool results URL fetches now produce clickable citation sources in the UI, matching the existing behavior of search_web and knowledge file tools. When a model calls fetch_url during native tool calling, the fetched URL appears as a citable source with a content preview, giving users full transparency into what pages the model referenced. --- backend/open_webui/utils/middleware.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index ec7af7733b..c2b2b07cb1 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -171,7 +171,10 @@ def get_citation_source_from_tool_result( Returns a list of sources (usually one, but query_knowledge_files may return multiple). """ try: - tool_result = json.loads(tool_result) + try: + tool_result = json.loads(tool_result) + except (json.JSONDecodeError, TypeError): + pass # keep tool_result as-is (e.g. fetch_url returns plain text) if isinstance(tool_result, dict) and "error" in tool_result: return [] @@ -232,6 +235,25 @@ def get_citation_source_from_tool_result( } ] + elif tool_name == "fetch_url": + url = tool_params.get("url", "") + content = tool_result if isinstance(tool_result, str) else str(tool_result) + snippet = content[:500] + ("..." if len(content) > 500 else "") + + return [ + { + "source": {"name": url or "fetch_url", "id": url or "fetch_url"}, + "document": [snippet], + "metadata": [ + { + "source": url, + "name": url, + "url": url, + } + ], + } + ] + elif tool_name == "query_knowledge_files": chunks = tool_result @@ -4102,6 +4124,7 @@ async def streaming_chat_response_handler(response, ctx): tool_function_name in [ "search_web", + "fetch_url", "view_knowledge_file", "query_knowledge_files", ]