Repository navigation
fix: keep runtime tools in filtered subagents - #10460
kilisamemarisaaa wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="astrbot/core/astr_agent_tool_exec.py" line_range="321-322" />
<code_context>
+
+ # Explicit persona selections only describe plugin/MCP tools in the
+ # dashboard. Keep enabled runtime tools available for the subagent.
+ for runtime_tool in runtime_computer_tools.values():
+ toolset.add_tool(runtime_tool)
+
return None if toolset.empty() else toolset
</code_context>
<issue_to_address>
**Declared tool restrictions are bypassed**
When a subagent has a non-empty declared tool allowlist that omits runtime tools while a runtime is enabled, `_build_handoff_toolset` appends every runtime tool after resolving the declared names, so the allowlist no longer restricts the subagent’s capabilities. Callers can access tools such as shell and file tools, including local command execution when runtime policy permits it.
Only add runtime tools that are permitted by the subagent’s declared tool allowlist.
</issue_to_address>
### Comment 2
<location path="astrbot/core/astr_agent_tool_exec.py" line_range="322" />
<code_context>
continue
runtime_tool = runtime_computer_tools.get(tool_name_or_obj)
if runtime_tool:
toolset.add_tool(runtime_tool)
+ continue
+ unavailable_names.append(tool_name_or_obj)
</code_context>
<issue_to_address>
**Selected tools are replaced**
When a selected plugin or MCP tool shares a name with an enabled runtime tool, `ToolSet.add_tool` replaces the selected implementation when the runtime tool with the same name is added, so the subagent calls the runtime implementation instead of the tool its persona selected.
Preserve the selected plugin or MCP implementation when adding a runtime tool with the same name.
Also at `astrbot/core/astr_agent_tool_exec.py:323`.
</issue_to_address>
### Comment 3
<location path="astrbot/core/astr_agent_tool_exec.py" line_range="322" />
<code_context>
continue
runtime_tool = runtime_computer_tools.get(tool_name_or_obj)
if runtime_tool:
toolset.add_tool(runtime_tool)
+ continue
+ unavailable_names.append(tool_name_or_obj)
</code_context>
<issue_to_address>
**Sandbox tools are unavailable**
When a filtered subagent uses a browser-capable sandbox or the `shipyard_neo` booter, `runtime_computer_tools` contains only the tools returned by `_get_runtime_computer_tools`, so this loop does not add sandbox browser or Shipyard Neo lifecycle tools registered by `_apply_sandbox_tools`. The filtered subagent cannot perform those browser or skill tasks.
Include the sandbox tools registered for the main agent when building the filtered subagent toolset.
Also at `astrbot/core/astr_agent_tool_exec.py:323`.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 3 findings to address first, and if the filtering behavior is wrong, every affected subagent can gain shell, Python, and file read/write capabilities even when those tools were not explicitly selected. Reverting stops future access but cannot undo commands already run, files changed, or data exposed, and the permission decision is applied immediately without an inherent failure signal.
Blocking findings: astrbot/core/astr_agent_tool_exec.py:322, astrbot/core/astr_agent_tool_exec.py:322, astrbot/core/astr_agent_tool_exec.py:322
| for runtime_tool in runtime_computer_tools.values(): | ||
| toolset.add_tool(runtime_tool) |
There was a problem hiding this comment.
🟠 High · Declared tool restrictions are bypassed
When a subagent has a non-empty declared tool allowlist that omits runtime tools while a runtime is enabled, _build_handoff_toolset appends every runtime tool after resolving the declared names, so the allowlist no longer restricts the subagent’s capabilities. Callers can access tools such as shell and file tools, including local command execution when runtime policy permits it.
Only add runtime tools that are permitted by the subagent’s declared tool allowlist.
Prompt for AI agents
In `astrbot/core/astr_agent_tool_exec.py` at lines 321-322:
**Declared tool restrictions are bypassed**
When a subagent has a non-empty declared tool allowlist that omits runtime tools while a runtime is enabled, `_build_handoff_toolset` appends every runtime tool after resolving the declared names, so the allowlist no longer restricts the subagent’s capabilities. Callers can access tools such as shell and file tools, including local command execution when runtime policy permits it.
Only add runtime tools that are permitted by the subagent’s declared tool allowlist.| # Explicit persona selections only describe plugin/MCP tools in the | ||
| # dashboard. Keep enabled runtime tools available for the subagent. | ||
| for runtime_tool in runtime_computer_tools.values(): | ||
| toolset.add_tool(runtime_tool) |
There was a problem hiding this comment.
🟡 Medium · Sandbox tools are unavailable
When a filtered subagent uses a browser-capable sandbox or the shipyard_neo booter, runtime_computer_tools contains only the tools returned by _get_runtime_computer_tools, so this loop does not add sandbox browser or Shipyard Neo lifecycle tools registered by _apply_sandbox_tools. The filtered subagent cannot perform those browser or skill tasks.
Include the sandbox tools registered for the main agent when building the filtered subagent toolset.
Also at astrbot/core/astr_agent_tool_exec.py:323.
Prompt for AI agents
In `astrbot/core/astr_agent_tool_exec.py` at line 322:
**Sandbox tools are unavailable**
When a filtered subagent uses a browser-capable sandbox or the `shipyard_neo` booter, `runtime_computer_tools` contains only the tools returned by `_get_runtime_computer_tools`, so this loop does not add sandbox browser or Shipyard Neo lifecycle tools registered by `_apply_sandbox_tools`. The filtered subagent cannot perform those browser or skill tasks.
Include the sandbox tools registered for the main agent when building the filtered subagent toolset.
Also at `astrbot/core/astr_agent_tool_exec.py:323`.|
AI-assisted follow-up to the review, with an independently run regression. Fixed the selected-tool collision in baac65f: adding runtime defaults now skips names already resolved from the explicit selection. The two new cases go through Validation on Windows/Python 3.12:
Two scope points remain for maintainer review:
|
Fixes #10456.
When a persona selects a subset of plugin or MCP tools, the subagent handoff builder only looks up those names. Runtime computer-use tools are configured separately, so the selected subagent loses its shell and file tools even when the configured runtime is enabled. If every selected plugin tool is inactive or unavailable, the handoff toolset also becomes empty without explaining why.
Changes
This keeps the existing semantics for
tools=None(all tools) andtools=[](no tools), while making a non-empty plugin/MCP selection safe for the runtime capabilities that the dashboard does not expose as selectable persona tools.Verification
The new tests fail on the unchanged upstream implementation: a local-runtime subagent with
tools=["plugin_tool"]produced no toolset, and an unavailable name emitted no warning.The full local
pytest -qrun reached approximately 26% and then stopped making progress in an existing integration test that launches local subprocesses. It was interrupted after the process remained idle for several minutes; no failure was attributed to this change.No new dependencies are introduced.
Summary by Sourcery
Keep runtime computer-use capabilities available in filtered subagents while improving diagnostics for unavailable tool selections.
Bug Fixes:
Tests: