Skip to content

fix: 子代理无法使用内置工具(如 web_search_tavily)#7939

Open
Blueteemo wants to merge 2 commits intoAstrBotDevs:masterfrom
Blueteemo:fix/issue-7870-subagent-builtin-tools
Open

fix: 子代理无法使用内置工具(如 web_search_tavily)#7939
Blueteemo wants to merge 2 commits intoAstrBotDevs:masterfrom
Blueteemo:fix/issue-7870-subagent-builtin-tools

Conversation

@Blueteemo
Copy link
Copy Markdown
Contributor

@Blueteemo Blueteemo commented May 1, 2026

问题描述

子代理配置 tools=None 时,只能使用 MCP 工具和插件工具,无法使用内置工具(如 web_search_tavily)。

根本原因

_build_handoff_toolset 方法在 ools=None 时只遍历 llm_tools.func_list,但这个列表不包含内置工具。

修复方案

在遍历 llm_tools.func_list 后,也遍历 ool_mgr.iter_builtin_tools() 添加内置工具。

关联 Issue

Fixes #7870

Summary by Sourcery

Bug Fixes:

  • Allow sub-agents configured with tools=None to use builtin tools in addition to MCP and plugin tools by including builtin tools in the constructed handoff toolset.

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label May 1, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Consider avoiding the implicit getattr(builtin_tool, "active", True) check by ensuring builtin tools conform to the same interface as registered tools (e.g., always exposing an active attribute), which will make the filtering logic more consistent and less error-prone.
  • If iter_builtin_tools() can ever return the same tool objects that are already present in llm_tools.func_list, it may be worth ensuring ToolSet deduplicates or explicitly guarding against adding duplicates here.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider avoiding the implicit `getattr(builtin_tool, "active", True)` check by ensuring builtin tools conform to the same interface as registered tools (e.g., always exposing an `active` attribute), which will make the filtering logic more consistent and less error-prone.
- If `iter_builtin_tools()` can ever return the same tool objects that are already present in `llm_tools.func_list`, it may be worth ensuring `ToolSet` deduplicates or explicitly guarding against adding duplicates here.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot
Copy link
Copy Markdown

dosubot Bot commented May 1, 2026

Related Knowledge

1 document with suggested updates is ready for review.

AstrBotTeam's Space

pr4697的改动
View Suggested Changes
@@ -247,6 +247,7 @@
    - 当 `SubAgent.tools` 设置为 `None` 时,表示"所有可用工具",与主代理行为一致
    - 此时 handoff 工具集包括:
      - 所有已注册的活跃工具(从 `llm_tools` 注册表获取,排除 HandoffTool 避免递归)
+     - 所有内置工具(builtin tools),例如 web_search_tavily(从 `tool_mgr.iter_builtin_tools()` 获取的活跃工具)
      - 所有运行时 Computer Use 工具(根据 `computer_use_runtime` 配置动态添加)
 
 2. **空工具列表(无工具)**:

[Accept] [Edit] [Decline]

How did I do? Any feedback?  Join Discord

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the _build_handoff_toolset function in astrbot/core/astr_agent_tool_exec.py to include builtin tools when initializing the toolset for sub-agents. Review feedback highlights a security concern where adding all builtin tools indiscriminately might bypass configuration-based restrictions, such as shell execution or web search toggles. Additionally, there is a suggestion to use tool_mgr instead of llm_tools to ensure the toolset remains consistent with the specific execution context.

Comment thread astrbot/core/astr_agent_tool_exec.py Outdated
Comment thread astrbot/core/astr_agent_tool_exec.py Outdated
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]给子代理单独配置工具调用

1 participant