Skip to content
Merged
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
15 changes: 7 additions & 8 deletions astrbot/builtin_stars/web_searcher/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,9 +567,9 @@ async def edit_web_search_tools(
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:
if web_search_t and web_search_t.active:
tool_set.add_tool(web_search_t)
if fetch_url_t:
if fetch_url_t and fetch_url_t.active:
tool_set.add_tool(fetch_url_t)
tool_set.remove_tool("web_search_tavily")
tool_set.remove_tool("tavily_extract_web_page")
Expand All @@ -578,9 +578,9 @@ async def edit_web_search_tools(
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:
if web_search_tavily and web_search_tavily.active:
tool_set.add_tool(web_search_tavily)
if tavily_extract_web_page:
if tavily_extract_web_page and tavily_extract_web_page.active:
tool_set.add_tool(tavily_extract_web_page)
tool_set.remove_tool("web_search")
tool_set.remove_tool("fetch_url")
Expand All @@ -590,9 +590,8 @@ async def edit_web_search_tools(
try:
await self.ensure_baidu_ai_search_mcp(event.unified_msg_origin)
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 and aisearch_tool.active:
tool_set.add_tool(aisearch_tool)
Comment on lines +593 to +594
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This change correctly adds the tool.active check, but it also removes the ValueError that was raised if aisearch_tool is not found. This makes the logic consistent with other providers, but it might hide a configuration issue specific to the baidu_ai_search provider. The original code seemed to assume that if ensure_baidu_ai_search_mcp succeeds, the AIsearch tool must exist. Silently ignoring its absence could make debugging harder if the MCP server is misconfigured. It would be safer to restore the error-raising logic for when the tool is not found, while still checking the active flag.

Suggested change
if aisearch_tool and aisearch_tool.active:
tool_set.add_tool(aisearch_tool)
if aisearch_tool:
if aisearch_tool.active:
tool_set.add_tool(aisearch_tool)
else:
raise ValueError("Cannot get Baidu AI Search MCP tool.")

tool_set.remove_tool("web_search")
Comment on lines +593 to 595
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Consider surfacing a warning/log when the Baidu AI Search tool is missing or inactive instead of failing silently.

The previous ValueError made Baidu AI Search MCP configuration issues visible. With if aisearch_tool and aisearch_tool.active:, callers now get no signal if ensure_baidu_ai_search_mcp returns None or an inactive tool, which can hide misconfiguration and leave the system without any search provider. Please add at least a warning log when the tool is missing or inactive so these issues remain detectable without reintroducing a hard failure.

Suggested implementation:

            try:
                await self.ensure_baidu_ai_search_mcp(event.unified_msg_origin)
                aisearch_tool = func_tool_mgr.get_func("AIsearch")
                if aisearch_tool and aisearch_tool.active:
                    tool_set.add_tool(aisearch_tool)
                else:
                    # Keep configuration issues visible without hard-failing
                    if aisearch_tool is None:
                        logger.warning(
                            "Baidu AI Search MCP tool 'AIsearch' is not available; "
                            "web search fallback tools will be disabled."
                        )
                    elif not aisearch_tool.active:
                        logger.warning(
                            "Baidu AI Search MCP tool 'AIsearch' is inactive; "
                            "web search fallback tools will be disabled."
                        )
                tool_set.remove_tool("web_search")
                tool_set.remove_tool("fetch_url")
  1. Ensure this module has a logger defined according to your existing logging conventions, for example:
    import logging
    logger = logging.getLogger(__name__)
    If a different logging utility is used elsewhere in astrbot/builtin_stars/web_searcher/main.py, adapt the warning calls to that logger instead.
  2. If you want to also surface unexpected errors when ensuring the Baidu MCP, consider adding an except Exception as exc: logger.exception(...) around this try block, consistent with the rest of the file’s error-handling style.

tool_set.remove_tool("fetch_url")
tool_set.remove_tool("web_search_tavily")
Expand All @@ -602,7 +601,7 @@ async def edit_web_search_tools(
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:
if web_search_bocha and web_search_bocha.active:
tool_set.add_tool(web_search_bocha)
tool_set.remove_tool("web_search")
tool_set.remove_tool("fetch_url")
Expand Down
Loading