From ad567c9a8fca3a6a4d65f0a036e1803efe0d1c84 Mon Sep 17 00:00:00 2001 From: BongSuCHOI Date: Mon, 6 Apr 2026 18:16:02 +0000 Subject: [PATCH] fix: subagent toolset inheritance when parent enabled_toolsets is None When parent_agent.enabled_toolsets is None (the default, meaning all tools are enabled), subagents incorrectly fell back to DEFAULT_TOOLSETS (['terminal', 'file', 'web']) instead of inheriting the parent's full toolset. Root cause: - Line 188 used 'or' fallback: None or DEFAULT_TOOLSETS evaluates to DEFAULT_TOOLSETS - Line 192 checked truthiness: None is falsy, falling through to else Fix: - Use 'is not None' checks instead of truthiness - When enabled_toolsets is None, derive effective toolsets from parent_agent.valid_tool_names via the tool registry Fixes the bug introduced in f75b1d21b and repeated in e5d14445e (PR #3269). --- tools/delegate_tool.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/tools/delegate_tool.py b/tools/delegate_tool.py index 2a990d8f..71a78ea6 100644 --- a/tools/delegate_tool.py +++ b/tools/delegate_tool.py @@ -185,12 +185,28 @@ def _build_child_agent( # When no explicit toolsets given, inherit from parent's enabled toolsets # so disabled tools (e.g. web) don't leak to subagents. - parent_toolsets = set(getattr(parent_agent, "enabled_toolsets", None) or DEFAULT_TOOLSETS) + # Note: enabled_toolsets=None means "all tools enabled" (the default), + # so we must derive effective toolsets from the parent's loaded tools. + parent_enabled = getattr(parent_agent, "enabled_toolsets", None) + if parent_enabled is not None: + parent_toolsets = set(parent_enabled) + elif parent_agent and hasattr(parent_agent, "valid_tool_names"): + # enabled_toolsets is None (all tools) — derive from loaded tool names + import model_tools + parent_toolsets = { + ts for name in parent_agent.valid_tool_names + if (ts := model_tools.get_toolset_for_tool(name)) is not None + } + else: + parent_toolsets = set(DEFAULT_TOOLSETS) + if toolsets: # Intersect with parent — subagent must not gain tools the parent lacks child_toolsets = _strip_blocked_tools([t for t in toolsets if t in parent_toolsets]) - elif parent_agent and getattr(parent_agent, "enabled_toolsets", None): - child_toolsets = _strip_blocked_tools(parent_agent.enabled_toolsets) + elif parent_agent and parent_enabled is not None: + child_toolsets = _strip_blocked_tools(parent_enabled) + elif parent_toolsets: + child_toolsets = _strip_blocked_tools(sorted(parent_toolsets)) else: child_toolsets = _strip_blocked_tools(DEFAULT_TOOLSETS)