Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions astrbot/builtin_stars/web_searcher/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down
Loading