Skip to main content

Module delegate

Module delegate 

Source
Expand description

Parallel delegation primitive — spawn N isolated subagents with restricted toolsets and collect their summaries.

Port of _inspirations/hermes-agent/tools/delegate_tool.py. The key invariants:

  • Isolation: child agents start with a fresh conversation — no parent history, own session-id-equivalent.
  • Restricted toolset: caller specifies which tools the child may call. A default blocklist strips dangerous recursion paths (delegate, memory writes, user-interaction tools) at depth ≥ 1.
  • Depth cap: max_depth = 2 (parent = 0, child = 1, no grandchildren) prevents infinite recursion.
  • Bounded parallelism: up to max_concurrent children run at once via tokio::task::JoinSet.
  • Best-effort: a child failure doesn’t abort the batch; the parent gets an error summary for that task and keeps going.

This module does NOT pull in a Python RPC bridge for code execution — that’s the 0.1.9 lift.

Structs§

DelegateConfig
Top-level config for a batch delegation.
DelegateResult
Result from one child agent.
DelegateTask
Input to a single delegation.

Constants§

DEFAULT_MAX_CONCURRENT
Default in-flight child limit per batch — matches hermes-agent’s max_concurrent_children.
DELEGATE_BLOCKED_TOOLS
Tools whose names match these strings are stripped from the child’s toolset. These are either recursion hazards (delegate) or cross-agent side effects (memory writes, user-facing messages). Caller-provided blocklists are merged with this default.
MAX_DEPTH
Maximum delegation depth (parent=0). Children cannot spawn grandchildren.

Functions§

build_child_system_prompt
Build the child system prompt. Verbatim port of _inspirations/hermes-agent/tools/delegate_tool.py::_build_child_system_prompt — paraphrasing costs us the bench parity guarantee.
run_batch
Run a batch of delegations. Blocks until every child completes (success or failure). On depth exhaustion, returns an error immediately without spawning anything.

Type Aliases§

ProviderFactory
Function that constructs a fresh provider for each child. Needed because Provider trait objects aren’t cloneable — each delegated child needs its own provider instance.
ToolsetFactory
Function that constructs a fresh toolset for each child. Same reason as ProviderFactoryBox<dyn Tool> isn’t cloneable.