Skip to content

fix: keep runtime tools in filtered subagents - #10460

Open
kilisamemarisaaa wants to merge 2 commits into
AstrBotDevs:masterfrom
kilisamemarisaaa:codex/fix-10456-tool-whitelist
Open

kilisamemarisaaa wants to merge 2 commits into
AstrBotDevs:masterfrom
kilisamemarisaaa:codex/fix-10456-tool-whitelist

Conversation

@kilisamemarisaaa

@kilisamemarisaaa kilisamemarisaaa commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Keep all tools provided by the enabled local or sandbox computer-use runtime in an explicitly filtered subagent toolset.
  • Resolve selected registered tools through the active context's tool manager instead of the global singleton.
  • Warn with the requested names when a selected tool is unavailable or inactive.
  • Add regression tests for runtime-tool preservation and unavailable-tool diagnostics.

This keeps the existing semantics for tools=None (all tools) and tools=[] (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.

uv run pytest tests/unit/test_astr_agent_tool_exec.py -q
54 passed, 1 warning

uv run pytest tests/unit/test_subagent_orchestrator.py tests/unit/test_astr_main_agent.py -q
152 passed, 1 warning

uv run ruff check .
All checks passed!

uv run ruff format --check .
514 files already formatted

The full local pytest -q run 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:

  • Preserve enabled runtime computer-use tools when subagents use an explicit plugin or MCP tool selection.
  • Warn when requested subagent tools are unavailable or inactive.
  • Resolve selected tools through the active context tool manager to retain the correct tool implementation.

Tests:

  • Add regression coverage for runtime-tool preservation, tool-name collisions, and unavailable-tool diagnostics.

@sourcery-ai sourcery-ai Bot left a comment

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.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread astrbot/core/astr_agent_tool_exec.py Outdated
Comment on lines +321 to +322
for runtime_tool in runtime_computer_tools.values():
toolset.add_tool(runtime_tool)

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.

🟠 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.

Comment thread astrbot/core/astr_agent_tool_exec.py Resolved
Comment thread astrbot/core/astr_agent_tool_exec.py Outdated
# 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)

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 · 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`.

@kilisamemarisaaa

Copy link
Copy Markdown
Contributor Author

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 FunctionToolExecutor.execute() with a real HandoffTool, Agent, and FunctionToolManager; the subagent execution boundary is a capturing test adapter, not a live provider. Both selecting the registered tool by name and passing a tool object failed before this follow-up, because the selected file tool's description was replaced by the runtime implementation. Both now preserve the selected implementation while retaining non-colliding runtime tools.

Validation on Windows/Python 3.12:

  • python -m pytest tests/unit/test_astr_agent_tool_exec.py tests/unit/test_subagent_orchestrator.py tests/unit/test_astr_main_agent.py -q: 208 passed, one existing audioop deprecation warning; repeated after formatting.
  • Repository Ruff check and format check passed; explicit Ruff check/format on the changed test file also passed (tests are excluded from the repository-wide invocation).
  • git diff --check passed.
  • A fresh full pytest -q -o faulthandler_timeout=60 run stopped making progress around 18%, with a timeout stack showing the async event loop waiting. I interrupted it; the cause is not established, and I do not claim a full local suite pass. CI must be evaluated for this new head, not the previous green head.

Two scope points remain for maintainer review:

  • This PR deliberately implements [Bug] 工具白名单会一并关掉框架内置工具,且界面上无法选择内置工具 #10456's requested separation between a persona's plugin/MCP selection and the separately enabled runtime, retaining the existing tools=None and tools=[] meanings. It does not claim that a non-empty selection is a strict allowlist for all runtime capabilities. If a strict per-subagent capability policy is required, that needs an explicit policy/UI design rather than silently calling this security-neutral.
  • _get_runtime_computer_tools has the same browser/lifecycle coverage limitation as upstream; this follow-up does not broaden it. I also found the later overlapping fix(agent): keep computer-use tools under a subagent whitelist and log misses #10463, which addresses browser capabilities and changes empty-list semantics. These policy differences need resolution before merging either implementation; this is not a blanket approval of either approach.

@Soulter Soulter moved this to In Progress in AstrBot Roadmap Nov 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

[Bug] 工具白名单会一并关掉框架内置工具,且界面上无法选择内置工具

1 participant