From e626d4d90129447a8a28bb2f17585ba1e7739076 Mon Sep 17 00:00:00 2001 From: Blueteemo Date: Fri, 1 May 2026 17:18:04 +0800 Subject: [PATCH 1/2] fix: include builtin tools in subagent handoff toolset when tools=None --- astrbot/core/astr_agent_tool_exec.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/astrbot/core/astr_agent_tool_exec.py b/astrbot/core/astr_agent_tool_exec.py index de5caad554..f2a74e78c3 100644 --- a/astrbot/core/astr_agent_tool_exec.py +++ b/astrbot/core/astr_agent_tool_exec.py @@ -266,11 +266,16 @@ def _build_handoff_toolset( # "all tools", including runtime computer-use tools. if tools is None: toolset = ToolSet() + # Add registered tools (MCP tools and plugin tools) for registered_tool in llm_tools.func_list: if isinstance(registered_tool, HandoffTool): continue if registered_tool.active: toolset.add_tool(registered_tool) + # Add builtin tools (e.g. web_search_tavily) + for builtin_tool in tool_mgr.iter_builtin_tools(): + if getattr(builtin_tool, "active", True): + toolset.add_tool(builtin_tool) for runtime_tool in runtime_computer_tools.values(): toolset.add_tool(runtime_tool) return None if toolset.empty() else toolset From ae73aefa1a6d380e8b91215b5dc1aa6815b967ae Mon Sep 17 00:00:00 2001 From: Blueteemo Date: Fri, 1 May 2026 17:33:01 +0800 Subject: [PATCH 2/2] fix: use tool_mgr instead of llm_tools, add web search tools based on config --- astrbot/core/astr_agent_tool_exec.py | 42 ++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/astrbot/core/astr_agent_tool_exec.py b/astrbot/core/astr_agent_tool_exec.py index f2a74e78c3..f800bd8219 100644 --- a/astrbot/core/astr_agent_tool_exec.py +++ b/astrbot/core/astr_agent_tool_exec.py @@ -240,6 +240,37 @@ def _get_runtime_computer_tools( } return {} + @classmethod + def _apply_web_search_tools( + cls, + toolset: ToolSet, + tool_mgr: T.Any, + cfg: dict, + ) -> None: + """根据配置添加 Web 搜索工具,复用主代理的逻辑。""" + prov_settings = cfg.get("provider_settings", {}) + if not prov_settings.get("web_search", False): + return + + provider = prov_settings.get("websearch_provider", "tavily") + try: + if provider == "tavily": + toolset.add_tool(tool_mgr.get_builtin_tool("web_search_tavily")) + toolset.add_tool(tool_mgr.get_builtin_tool("tavily_extract_web_page")) + elif provider == "bocha": + toolset.add_tool(tool_mgr.get_builtin_tool("web_search_bocha")) + elif provider == "brave": + toolset.add_tool(tool_mgr.get_builtin_tool("web_search_brave")) + elif provider == "firecrawl": + toolset.add_tool(tool_mgr.get_builtin_tool("web_search_firecrawl")) + toolset.add_tool( + tool_mgr.get_builtin_tool("firecrawl_extract_web_page") + ) + elif provider == "baidu_ai_search": + toolset.add_tool(tool_mgr.get_builtin_tool("web_search_baidu")) + except KeyError: + pass + @classmethod def _build_handoff_toolset( cls, @@ -266,18 +297,17 @@ def _build_handoff_toolset( # "all tools", including runtime computer-use tools. if tools is None: toolset = ToolSet() - # Add registered tools (MCP tools and plugin tools) - for registered_tool in llm_tools.func_list: + # 使用 tool_mgr 代替全局 llm_tools,确保多租户环境一致性 + for registered_tool in tool_mgr.func_list: if isinstance(registered_tool, HandoffTool): continue if registered_tool.active: toolset.add_tool(registered_tool) - # Add builtin tools (e.g. web_search_tavily) - for builtin_tool in tool_mgr.iter_builtin_tools(): - if getattr(builtin_tool, "active", True): - toolset.add_tool(builtin_tool) + # 添加计算机工具(根据 computer_use_runtime 配置) for runtime_tool in runtime_computer_tools.values(): toolset.add_tool(runtime_tool) + # 添加 Web 搜索工具(根据配置) + cls._apply_web_search_tools(toolset, tool_mgr, cfg) return None if toolset.empty() else toolset if not tools: