-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix(websearch): prevent disabled websearch tools from being added to the toolset #6584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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") | ||
|
|
@@ -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") | ||
|
|
@@ -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) | ||
| tool_set.remove_tool("web_search") | ||
|
Comment on lines
+593
to
595
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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")
|
||
| tool_set.remove_tool("fetch_url") | ||
| tool_set.remove_tool("web_search_tavily") | ||
|
|
@@ -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") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change correctly adds the
tool.activecheck, but it also removes theValueErrorthat was raised ifaisearch_toolis not found. This makes the logic consistent with other providers, but it might hide a configuration issue specific to thebaidu_ai_searchprovider. The original code seemed to assume that ifensure_baidu_ai_search_mcpsucceeds, theAIsearchtool 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 theactiveflag.