Skip to content

fix: validate delegated sub-agent tool lists resolve to >=1 tool (Closes #1387) - #1421

Closed
Lexus2016 wants to merge 1 commit into
mainfrom
evolution/issue-1387-validate-toolsets
Closed

fix: validate delegated sub-agent tool lists resolve to >=1 tool (Closes #1387)#1421
Lexus2016 wants to merge 1 commit into
mainfrom
evolution/issue-1387-validate-toolsets

Conversation

@Lexus2016

Copy link
Copy Markdown
Owner

Automated evolution PR for issue #1387.

Problem

When a delegated sub-agent's toolset resolution produced an empty list (requested toolsets don't intersect with parent's, or inherited toolsets are all stripped by _strip_blocked_tools), the sub-agent was launched with zero tools. This caused the sub-agent to spiral on every tool call — the root cause of the 'is not a deferrable tool' pattern observed in introspection (64 failed sessions, 4.14% rate).

Fix

Added a validation guard in _build_child_agent after toolset resolution:

  • If child_toolsets is empty AND toolsets were explicitly requested → ValueError naming the requested toolsets and parent's available toolsets
  • If child_toolsets is empty from inherited toolsets → ValueError explaining the parent has no surviving enabled toolsets
  • The caller in delegate_task catches the ValueError and returns a per-task error result with status: "error" instead of launching the toolless sub-agent

Changes

  • tools/delegate_tool.py: Empty-toolset guard in _build_child_agent (raises ValueError); try/except in delegate_task batch loop catches it and returns structured error result
  • tests/tools/test_delegate_toolset_scope.py: Added TestEmptyToolsetValidation with 3 tests covering explicit-request-empty, inherited-empty, and valid-toolsets-no-raise

Validation

  • Lint: ✓ (ruff check)
  • Tests: 14/14 passed (tests/tools/test_delegate_toolset_scope.py)

Co-Authored-By: Hermes Evolution evolution@hermes.ai

 #1387)

After toolset resolution and _strip_blocked_tools, if child_toolsets is
empty the sub-agent would have no tools and spiral on every tool call.
Added a guard in _build_child_agent that raises ValueError with a
structured error message. The caller in delegate_task catches the
ValueError and returns a per-task error result instead of launching
the toolless sub-agent.

Co-Authored-By: Hermes Evolution <evolution@hermes.ai>
@github-actions github-actions Bot added fix Bug or fix introspection Found by session introspection labels Jul 28, 2026
@Lexus2016

Copy link
Copy Markdown
Owner Author

Blocked by code-review: CI failing — the validation guard in _build_child_agent causes IndexError at delegate_tool.py:3240, breaking 8 tests in test_delegate_shallow_retry.py. The guard raises ValueError which is caught per-task, but the return-path change at line 3240 accesses an index that no longer exists in the modified control flow. Needs: fix the IndexError so existing shallow-retry tests pass, or restructure the guard to not alter the function's return-path shape.

@Lexus2016 Lexus2016 closed this Jul 28, 2026
@Lexus2016
Lexus2016 deleted the evolution/issue-1387-validate-toolsets branch July 28, 2026 05:04
Lexus2016 added a commit that referenced this pull request Jul 28, 2026
)

When a delegated sub-agent resolves to zero tools (requested toolsets
don't intersect with parent's, or inherited toolsets are all stripped),
append a structured error entry to results with status='error' and
skip launching that child. Preserves the {'results': [...]} contract
without raising ValueError (broke PR #1421) or returning {'error':...}
(broke PR #1419).

Closes #1387

Co-authored-by: Hermes Evolution <evolution@hermes.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug or fix introspection Found by session introspection

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant