feat: add delegate pre-spawn guard - #23177
Closed
ai-ag2026 wants to merge 2 commits into
Closed
Conversation
Contributor
Author
|
CI follow-up after all checks completed: Three failures appear unrelated to this PR's changed files:
The PR diff only touches:
Happy to investigate further if maintainers see something specific in this PR's changes. |
ai-ag2026
marked this pull request as ready for review
May 10, 2026 12:48
Contributor
Author
|
Closing rather than refreshing this old branch. The delegate pre-spawn guard is not directly replaced on current |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a disabled-by-default
delegate_taskpre-spawn guard so installations can call an external policy system before Hermes constructs child agents.delegation.pre_spawn_guardconfig with command-based JSON stdin/stdout protocol._build_child_agent(...)when a guard denies a planned child.guard_context_idinto delegated children so recursive delegation can stay attached to the same external work item.Why
Some operators need a local policy/budget/permission broker to approve subagent creation before resources are allocated or side effects become possible. The hook is generic: Hermes Core only knows about an optional guard context; integrations decide what that context means.
Example uses:
Design
The guard is disabled by default, and when it is disabled delegation behavior is unchanged:
For each planned child, Hermes sends a compact JSON payload to the command on stdin. It deliberately includes a
goal_previewtruncated to 240 characters, not the full task context. The command returns JSON such as:{ "ok": true, "allowed": true, "reason": "approved" }or:
{ "ok": true, "allowed": false, "reason": "missing approval" }manualis for interactive sessions where an operator can react to warnings;autonomousis for unattended dispatchers where unknown states should fail closed.allowed: falseis treated as a policy decision. A valid denial should return exit 0 withallowed: false; non-zero exit, timeout, or invalid JSON are treated as hook failures and resolved byfail_policy.Commit structure
This branch is intentionally two commits:
feat: add delegate pre-spawn guard— core hook, tests, docs.feat: propagate delegate guard context to children— recursive delegation context propagation.Test plan
python -m pytest tests/tools/test_delegate.py -q -o 'addopts=' python -m py_compile tools/delegate_tool.py tests/tools/test_delegate.py git diff --checkLocal result:
Additional local integration smoke against an external adapter verified:
That adapter is local-only and not part of this PR.
Upstream-safety checks
Core code/tests were checked for local integration names: