From e56b373ec376e1b9859d0e6cc60ada3ef860402a Mon Sep 17 00:00:00 2001 From: Yufeng He <40085740+universeplayer@users.noreply.github.com> Date: Tue, 17 Mar 2026 22:09:13 +0800 Subject: [PATCH] Fix disabled web search tools still being added to LLM requests edit_web_search_tools filter was fetching tools via get_func() and adding them to the tool set without checking their active status. Tools deactivated by the admin would get re-added on every request. Extract a _try_add helper that checks tool.active before adding, consistent with how persona setup already filters inactive tools. Fixes #6506 --- astrbot/builtin_stars/web_searcher/main.py | 30 ++++++++++------------ 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/astrbot/builtin_stars/web_searcher/main.py b/astrbot/builtin_stars/web_searcher/main.py index d13ca15792..d1c1a0c2f7 100644 --- a/astrbot/builtin_stars/web_searcher/main.py +++ b/astrbot/builtin_stars/web_searcher/main.py @@ -564,24 +564,23 @@ async def edit_web_search_tools( return func_tool_mgr = self.context.get_llm_tool_manager() + + def _try_add(tool_name: str) -> None: + """Only add a tool if it exists and hasn't been deactivated by the admin.""" + t = func_tool_mgr.get_func(tool_name) + if t and t.active: + tool_set.add_tool(t) + if provider == "default": - web_search_t = func_tool_mgr.get_func("web_search") - fetch_url_t = func_tool_mgr.get_func("fetch_url") - if web_search_t: - tool_set.add_tool(web_search_t) - if fetch_url_t: - tool_set.add_tool(fetch_url_t) + _try_add("web_search") + _try_add("fetch_url") tool_set.remove_tool("web_search_tavily") tool_set.remove_tool("tavily_extract_web_page") tool_set.remove_tool("AIsearch") tool_set.remove_tool("web_search_bocha") elif provider == "tavily": - web_search_tavily = func_tool_mgr.get_func("web_search_tavily") - tavily_extract_web_page = func_tool_mgr.get_func("tavily_extract_web_page") - if web_search_tavily: - tool_set.add_tool(web_search_tavily) - if tavily_extract_web_page: - tool_set.add_tool(tavily_extract_web_page) + _try_add("web_search_tavily") + _try_add("tavily_extract_web_page") tool_set.remove_tool("web_search") tool_set.remove_tool("fetch_url") tool_set.remove_tool("AIsearch") @@ -592,7 +591,8 @@ async def edit_web_search_tools( aisearch_tool = func_tool_mgr.get_func("AIsearch") if not aisearch_tool: raise ValueError("Cannot get Baidu AI Search MCP tool.") - tool_set.add_tool(aisearch_tool) + if aisearch_tool.active: + tool_set.add_tool(aisearch_tool) tool_set.remove_tool("web_search") tool_set.remove_tool("fetch_url") tool_set.remove_tool("web_search_tavily") @@ -601,9 +601,7 @@ async def edit_web_search_tools( except Exception as e: logger.error(f"Cannot Initialize Baidu AI Search MCP Server: {e}") elif provider == "bocha": - web_search_bocha = func_tool_mgr.get_func("web_search_bocha") - if web_search_bocha: - tool_set.add_tool(web_search_bocha) + _try_add("web_search_bocha") tool_set.remove_tool("web_search") tool_set.remove_tool("fetch_url") tool_set.remove_tool("AIsearch")