Expand description
delegate_to_agent tool — the PM’s primary tool for dispatching to sub-agents.
Why: Keeps the delegation schema and its executor colocated so the PM’s tool
registry can register a single type that owns both. Pre-flight validation of
agent_name against the on-disk agent config directory prevents the LLM from
hallucinating sub-agent names and crashing the subprocess runner with a
confusing IO error (#204 equivalent). (bake-off L1 diagnosis) A delegated
engineer that exhausts its turn/time budget has usually already written
real, partial progress to disk; the PM’s recovery historically was a
free-text “re-delegate with a streamlined brief” that never told the next
engineer instance to look at what was already there, so it silently
rebuilt a simpler (sometimes incomplete) solution and orphaned the correct
work. redelegation_hint makes the safer instruction automatic: it fires
on every TurnCapExceeded/Timeout/Cancelled abort, regardless of
whether the PM’s own free text remembers to ask for it.
What: DelegateToAgentTool wraps an AgentRunner and (optionally) an agent
config directory. execute() parses {agent_name, task}, validates the agent
config exists, and hands off to the runner. On miss, returns a helpful error
listing available agents. On a runner failure caused by the sub-agent’s own
loop aborting with partial work still on disk, the returned ToolResult
error appends a fixed reuse/continue directive (redelegation_hint).
(#2265) redelegation_hint is also pub(crate) so
run_task::redelegation::RedelegatingRunner can reuse the SAME hint logic
to decide, entirely inside one delegate_to_agent dispatch, whether a
failed engineer attempt is worth automatically retrying — see that
module’s docs for the retry/cap mechanics.
Test: unknown_agent_returns_helpful_error builds a tool pointed at a tempdir
containing engineer.toml only, calls execute({"agent_name":"ghost",...}),
and asserts the error names the unknown agent and lists engineer.
redelegation_hint_* tests cover the reuse-directive behaviour.
Structs§
- Delegate
ToAgent Tool - Tool executor that delegates a task to a named sub-agent.