From 4a3570e477f3a791b5d38cb404b08cd4b78de78f Mon Sep 17 00:00:00 2001 From: J03Fr0st Date: Mon, 30 Nov 2026 08:46:55 +1300 Subject: [PATCH] feat(orchestrate): keep work with the root unless a slice needs a fresh context Apply Anthropic's guidance on folding subagents into the main agent loop. Orchestrate now delegates only for a fresh, discardable context, an independent review or check, or a user or repository requirement. Slices are split by context rather than role, so steps that consume each other's output go to one worker; dependent workers get artifacts ahead of reports; and the worker contract gains a shared return shape. Evals 13 and 14 cover the new branches; paired results against the main version are recorded in docs/research/2026-11-30-orchestrate-fold-subagents.md. --- .changeset/orchestrate-fold-subagents.md | 5 + docs/engineering/orchestrate.md | 6 +- .../2026-11-30-orchestrate-fold-subagents.md | 137 ++++++++++++++++++ skills/engineering/orchestrate/SKILL.md | 13 +- .../engineering/orchestrate/evals/evals.json | 22 +++ .../orchestrate/references/routing.md | 3 +- 6 files changed, 181 insertions(+), 5 deletions(-) create mode 100644 .changeset/orchestrate-fold-subagents.md create mode 100644 docs/research/2026-11-30-orchestrate-fold-subagents.md diff --git a/.changeset/orchestrate-fold-subagents.md b/.changeset/orchestrate-fold-subagents.md new file mode 100644 index 0000000..5be736d --- /dev/null +++ b/.changeset/orchestrate-fold-subagents.md @@ -0,0 +1,5 @@ +--- +"j03fr0st-skills": minor +--- + +`orchestrate` now keeps work with the root by default and delegates only for a fresh, discardable context (parallel work or context-heavy reading), an independent review or check, or a user or repository requirement. Slices are split by context rather than role, so chained steps that consume each other's output go to one worker; dependent workers receive artifacts ahead of reports; and the worker contract gains a shared return shape. diff --git a/docs/engineering/orchestrate.md b/docs/engineering/orchestrate.md index 64271e6..9472db1 100644 --- a/docs/engineering/orchestrate.md +++ b/docs/engineering/orchestrate.md @@ -30,6 +30,8 @@ The definitions use `orchestrate-` names to coexist with existing roles. There i ## How it chooses work and models +Work stays with the root by default. One context can connect steps that a worker's summary loses, and each dispatch adds a nested model loop. The root delegates a slice only when it needs a fresh context it can throw away (independent parallel work, or reading so much that the root's context would degrade), when it needs independence (a review or check that must not see the producer's reasoning), or when the user or repository rules require agents. Slices are split by context, not by role: steps that use each other's output or touch the same data go to one worker. A dependent worker gets the earlier worker's diff or files, not just its report, and every worker returns the same shape: status, artifacts, evidence, open decisions and skills loaded. + The root first checks the available native tools, role definitions, model catalog and governing instructions. An explicit user or repository profile wins over an economical default. The selected root model remains unchanged. Routing considers ambiguity, failure impact and how easily the result can be checked. Narrow extraction can use a fast model; difficult diagnosis and consequential review justify stronger reasoning. Availability is checked in the active host, so a model mentioned in a template is not treated as proof of access. @@ -58,7 +60,7 @@ Model selection does not expand permissions. Setup, profile changes and installa ## Evaluation and design basis -The [evaluation cases](../../skills/engineering/orchestrate/evals/evals.json) cover small-task routing, forced model overrides, interrupted writers, locked roles, stale verification, unavailable native tools, shared-schema dependencies, repeated failure and worktree isolation on a feature branch. Offline scenario evaluations test decisions; live native dispatch and repeated task benchmarks are needed to establish model identity, correctness and usage improvements. +The [evaluation cases](../../skills/engineering/orchestrate/evals/evals.json) cover small-task routing, forced model overrides, interrupted writers, locked roles, stale verification, unavailable native tools, shared-schema dependencies, repeated failure, worktree isolation on a feature branch, collapsing an explorer-to-worker chain into one worker, and keeping an in-context multi-file diagnosis with the root. Offline scenario evaluations test decisions; live native dispatch and repeated task benchmarks are needed to establish model identity, correctness and usage improvements. See the [skill validation record](../research/2026-09-26-model-orchestration/skill-validation.md) and [native agent validation](../research/2026-09-26-model-orchestration/native-agents-validation.md) for the checks performed and their limits. @@ -67,3 +69,5 @@ The [research report](../research/2026-09-26-model-orchestration/README.md) and The [2026-10 source sweep](../research/2026-10-06-source-repos-sweep.md) adds file-based worker results, returning only a path, from EveryInc's `ce-compound`. The [2026-11 source sweep](../research/2026-11-16-source-repos-sweep.md) adds fresh-context workers with consolidated scope (Matt Pocock's subagent change, Cursor pstack's `poteto-mode`), batching same-shape edits and one fixer for a review's findings (Superpowers' `subagent-driven-development`), reasoning-blind verification (Trail of Bits' `patching-bugs`), a capped fix loop with recorded rulings, and a final list of rulings with their cost if wrong (Superpowers). + +The [2026-11-30 fold research](../research/2026-11-30-orchestrate-fold-subagents.md) adds the root-only default, the three delegation cases, splitting by context, artifact-first handoffs and the shared return shape, from Anthropic's article on folding subagents into the main agent loop, supported by Superpowers' `dispatching-parallel-agents` and Addy Osmani's orchestration patterns. diff --git a/docs/research/2026-11-30-orchestrate-fold-subagents.md b/docs/research/2026-11-30-orchestrate-fold-subagents.md new file mode 100644 index 0000000..8fa4b8d --- /dev/null +++ b/docs/research/2026-11-30-orchestrate-fold-subagents.md @@ -0,0 +1,137 @@ +# Orchestrate: when to fold subagents into the root loop + +Date: 2026-11-30. Scope: tighten when `orchestrate` delegates, how it splits +slices, and what workers return, based on one article and a check of the +preferred source repositories. + +## Source article + +[Building agents: when to fold subagents into your main agent loop](https://claude.com/resources/articles/building-agents-when-to-fold-subagents-into-your-main-agent-loop) +(Anthropic Applied AI, 2026-10-22). It targets production enterprise agents, not +coding-agent skills, so the claims below are translated rather than applied +literally. It reports few numbers (one customer saw roughly 2x faster runtime +with a single loop) and gives no methodology for them. + +Claims used: + +1. A single loop with progressive disclosure (skills and deferred tools) now + beats a coordinator-plus-specialists design for many tasks, because one + context can connect steps that subagent summaries lose. +2. Keep a subagent only when (a) the single loop measurably degrades from + context bloat, (b) work runs in parallel in fresh contexts that can be + discarded, or (c) tool selection or conflicting instructions break the + single loop. +3. Split by context, not by problem type. A split by problem type becomes a + "telephone game" where fidelity drops at each handoff. Good candidates: + independent research paths, components with clean interfaces, and + black-box verification. +4. Merge specialists that chain on each other's output, touch the same data, or + are usually called together. +5. Subagents return compact results in a shared response schema; the main agent + checks conclusions against real data. +6. Each subagent call is a nested model loop, so it adds latency. +7. Change one thing at a time, run tasks more than once, and compare which + tasks flipped rather than only the total score. + +Claims not used here: org ownership, MCP tool design, and the migration kit +apply to product agents. Claim 7 belongs to evaluation work (a cross-skill +routing eval is the planned follow-up). + +## Preferred repositories + +Read `docs/source-repos.md` first; order unchanged. Revisions checked +2026-11-30 unless noted. The 2026-09-26 orchestration ledger +([preferred-sources.md](2026-09-26-model-orchestration/preferred-sources.md)) +still describes the earlier influence of each repository. + +| # | Repository | Revision | Influence on this change | +| --- | --- | --- | --- | +| 1 | `mattpocock/skills` | `255351f0a1d3` | `.out-of-scope/subagent-recursion.md`: recursion limits belong to the harness, not skill prose. Confirms not adding depth-limit prose; orchestrate's existing no-recursion line stays because the role definitions enforce it as tool policy. | +| 2 | `obra/superpowers` | `22f0b463e7a5` | `dispatching-parallel-agents`: dispatch only for independent domains with no shared state; related failures go to a single agent. `subagent-driven-development/references/batching.md`: batch same-shape work into one dispatch (already adopted). Supports claims 3 and 4. | +| 3 | `addyosmani/agent-skills` | `e997ac5b9a74` | `references/orchestration-patterns.md`: direct invocation is the default; research isolation is worth it when the alternative is loading large material into the main context; an LLM lifecycle orchestrator loses nuance by summarizing at each handoff. Strongest support for the "context-heavy reading" criterion and against chained handoffs. | +| 4 | `cursor/plugins` (pstack) | `4d5593ed7f5d` | No new delegation guidance since the 2026-11 sweep; earlier influence (done predicates, isolated outputs) unchanged. | +| 5 | `DietrichGebert/ponytail` | not re-checked | Evaluation guidance (measure per workload) already recorded; not applicable to routing prose. | +| 6 | `mvanhorn/last30days-skill` | not re-checked | Research mechanics only; not applicable. | +| 7 | `anthropics/skills` | `e4bb5d960d87` | No orchestration skill; skill-creator's baseline-comparison method informs the eval additions. | +| 8 | `trailofbits/skills` | not re-checked | Reasoning-blind verification already adopted (Step 6); it is the article's "black-box verification" case. | +| 9 | `EveryInc/compound-engineering-plugin` | not re-checked | File-based worker results already adopted; unchanged. | +| 10 | `garrytan/gstack` | not re-checked | Dispatch-identity guard and stall deadlines already adopted; nothing on fold criteria. | +| 11 | `affaan-m/ECC` | not re-checked | Chain bounds already reflected; nothing new. | +| 12 | `wshobson/agents` | `c96b5f6552db` | Large specialist-per-domain catalog (for example a context-manager agent). Cited as the sprawl pattern the article warns about; not adopted. | +| 13 | `nahid-sparktales/agent-dispatcher` | `564c3f0e39d9` | "Direct" route for trivial or one known-file work, and passing the request verbatim rather than a summary. Supports passing artifacts and full directives instead of summaries. | +| 14 | `humanlayer/skills` | `4d69d20f6e9b` | RPI's locator/analyzer subagents are read-only context-isolation workers that return locations, not analysis. Matches the "context-heavy reading" case. | +| 15 | `testdouble/han` | `abba73a77352` | ADR 0001 sizes swarms by work band and announces the chosen band. Not adopted: orchestrate already caps concurrency at two by default. | + +## Gap in orchestrate before this change + +- Step 2 delegated on "difficult diagnosis or research" without asking whether + the root's own context would serve better. Diagnosis often needs one context + to connect symptoms, so the trigger is context volume, not difficulty. +- No rule merged slices that chain on each other's output; Step 3 passed an + earlier worker's report to the next, which is the telephone-game handoff. +- Role definitions shared a return skeleton, but the contract template had no + return slot, so a worker spawned without the bundled roles had no shape to + follow. + +## Decisions + +1. Step 2 defaults to root-only and names three delegation cases: a fresh, + discardable context (parallel independent work or context-heavy reading), + independence (review or verification blind to the producer), or a user or + repository requirement. +2. Split by context: a slice needs little from the rest of the run and returns + a compact result. Slices that consume each other's output, touch the same + data, or always run together are one slice. +3. A dependent slice receives the producing worker's artifacts (diff, files, + branch) ahead of its report. +4. The contract template gains a `Return shape` slot matching the roles' + existing skeleton: status first, artifacts by path or diff, evidence, open + decisions, skills last. +5. `routing.md` replaces the "difficult diagnosis" row with context-heavy + reading and adds a chained-steps row. + +Rejected: rewriting the role return formats (they already share the skeleton), +adding depth limits in prose (harness concern, per mattpocock), and swarm-size +bands (concurrency cap already exists). + +## Verification + +Two offline evals cover the new branches. Paired runs on 2026-11-30: each sample +ran in a fresh Opus context that read only the skill directory (evals, assets +and scripts removed). Control arm A was the `main` version; arm B the edited +one. Graded by hand against `expectations`, unblinded. + +**Round 1** used first-draft scenarios (a function rename chain; a one-file race +plus a p-retry version question). Both arms scored the same on every +expectation: the old skill merged the rename through its same-shape batching +rule and delegated the version question through its "current external fact" +row. The rename scenario's "keep a reviewer" expectation also conflicted with +the skill (1/3 in each arm). Both scenarios were replaced. + +**Round 2** (current `evals.json`): + +| Eval | Expectation | Arm A (old) | Arm B (new) | +| --- | --- | --- | --- | +| 13, CSV export with explorer, worker, tester, reviewer proposed | No explorer summary handed to the implementer | 0/3 | 3/3 | +| 13 | Dependants get artifacts, not only reports | 0/3 | 3/3 | +| 13 | Reviewer gets diff and contract only | 3/3 | 3/3 | +| 14, deadlock across three files already read | Diagnosis stays with the root | 3/3 | 3/3 | +| 14 | Reason is context held, not difficulty | 3/3 | 3/3 | +| 14 | Any agent serves independence (reviewer) | 3/3 | 3/3 | +| 1 (regression, round 1) | | — | 2/2 | +| 7 (regression, round 1) | | — | 2/2 | + +All three old-arm runs of eval 13 kept the four-stage chain and passed the +explorer's report to the worker as its starting input; all three new-arm runs +merged mapping, implementation and tests into one worker and kept only the +independent reviewer, citing "split by context, not by role". + +Eval 14 does not discriminate: the old skill already kept an in-context +diagnosis with the root ("small, localized, readily checked in the current +context"), so removing the "difficult diagnosis" trigger has no measured effect. +It stays as a regression guard. + +Result: the split-by-context and artifact-first rules change behaviour (eval 13, +0/3 to 3/3); the root-only default and the diagnosis rewording are supported by +the article and source repositories but not by a measured difference. Grading +was by the author with arms known; three reps per arm is a small sample. diff --git a/skills/engineering/orchestrate/SKILL.md b/skills/engineering/orchestrate/SKILL.md index 6ab9840..f2910ad 100644 --- a/skills/engineering/orchestrate/SKILL.md +++ b/skills/engineering/orchestrate/SKILL.md @@ -1,6 +1,6 @@ --- name: orchestrate -description: Coordinate non-trivial engineering work with bounded native subagents when independent execution, difficult diagnosis, current research, or an independent review materially helps. Use when asked to use subagents, run slices in parallel, delegate to workers, or install/configure orchestrate agents. Keep small, local, readily verifiable work with the root agent; slicing belongs to planning-and-task-breakdown, local execution to implement, and isolated checkouts to git-worktrees. +description: Coordinate non-trivial engineering work with bounded native subagents when independent parallel work, context-heavy research or investigation, or an independent review materially helps. Use when asked to use subagents, run slices in parallel, delegate to workers, or install/configure orchestrate agents. Keep small, local, readily verifiable work with the root agent; slicing belongs to planning-and-task-breakdown, local execution to implement, and isolated checkouts to git-worktrees. --- # Orchestrate @@ -24,14 +24,20 @@ Treat the host's native tool schema, configured roles, model catalog, permission Read [references/routing.md](references/routing.md) when deciding whether to delegate or which role/model tier to request. -Keep the work root-only when it is small, localized, and readily checked in the current context. Delegate when there is an independent bounded slice, useful parallel work, difficult diagnosis or research, a material independent review, or an explicit request for agents. Split by observable outcome and dependency; keep shared contracts and architecture decisions with the root. +Default to root-only: one context connects steps that a worker's summary loses, and every dispatch adds a nested loop. Delegate a slice only when it needs: + +- **a fresh, discardable context:** independent parallel work, or reading so much material (wide search, long logs, external research) that the root's context would degrade; +- **independence:** a review or verification that must not see the producer's reasoning; +- **compliance:** the user or repository rules require agents. + +Split by context, not by role: each slice needs little from the rest of the run and returns a compact result. Slices that consume each other's output, touch the same data, or always run together are one slice for one worker or the root. Keep shared contracts and architecture decisions with the root. **Complete when:** the route is `root-only` or a list of ready slices with dependencies and ownership. ## 3. Dispatch real bounded work - **Real native calls only:** Call the active harness's native spawn/subagent tool before doing that slice in the root. A plan, simulated transcript, or narration is not a spawn. Dispatch independent ready slices together; serialize dependent slices. Batch the same small edit repeated across files into one contract for one worker and review it as one diff. -- **Fresh context with consolidated scope:** Start every worker with a fresh context window, not a fork of the root conversation, passing the original contract, every later directive, and any earlier worker's report and branch (including fix rounds, follow-ups, and retries). Resume an existing worker only when the new work needs state that lives inside it and is costly to move, such as uncommitted changes or a running process; chained resumes can drop directives silently. +- **Fresh context with consolidated scope:** Start every worker with a fresh context window, not a fork of the root conversation, passing the original contract, every later directive, and any earlier worker's artifacts (diff, files, branch) ahead of its lossy report, including for fix rounds, follow-ups, and retries. Resume an existing worker only when the new work needs state that lives inside it and is costly to move, such as uncommitted changes or a running process; chained resumes can drop directives silently. - **Contract shape:** Give every worker outcome and constraints while leaving method to the worker: ```text @@ -41,6 +47,7 @@ Applicable skills: exposed identifiers or exact SKILL.md paths; required versus Files/subsystem owned; files that must not change: Prerequisites: Expected artifact and acceptance criteria: +Return shape: status (completed/blocked/failed); artifacts by path or diff; evidence; open decisions for the root; skills loaded/missing: Role, requested model and effort when the native schema supports them: Inherited tools/permissions: Deadline and stall recovery (what the root does if it passes or the dispatch returns nothing): diff --git a/skills/engineering/orchestrate/evals/evals.json b/skills/engineering/orchestrate/evals/evals.json index b4d5284..294c395 100644 --- a/skills/engineering/orchestrate/evals/evals.json +++ b/skills/engineering/orchestrate/evals/evals.json @@ -132,6 +132,28 @@ "Keeps the independent reviewer strictly read-only and assigns explicit disjoint ownership of src/cache.ts to the implementer.", "Verifies the integrated result with fresh checks after worker completion rather than trusting worker self-reports." ] + }, + { + "id": 13, + "prompt": "Offline decision exercise. Claude Code session. User says: 'use agents to add CSV export to the reports page'. The reports feature lives in src/reports/ (about 15 files), which nobody in this session has read yet. The proposed plan: an explorer reads src/reports/ and returns a summary of the data flow; a worker implements CSV export from that summary; a tester then writes tests for the worker's change; a reviewer checks the final diff. Describe the dispatch plan and what each agent receives; do not execute tools.", + "expected_output": "Treats mapping src/reports/ and implementing the export as one slice: the implementing agent maps the code itself (or the root does), instead of a separate explorer handing a summary to the worker. Any agent that depends on another agent's output receives artifacts (diff, files) rather than only a report. Any reviewer it keeps receives the diff and contract, not the producer's reasoning. Honors the request for agents.", + "files": [], + "expectations": [ + "Does not have a separate explorer hand a summary of src/reports/ to the implementing worker; mapping and implementation are one slice for one agent (or the root maps it).", + "Any agent that depends on another agent's output receives that output's artifacts (diff, files, branch), not only a summary or report.", + "Any reviewer it keeps receives the diff and contract, not the producing worker's transcript or conclusions." + ] + }, + { + "id": 14, + "prompt": "Offline decision exercise. Claude Code session with native subagents available; the user did not ask for agents. An intermittent deadlock appears in the job scheduler under load. During this session the root has already read src/scheduler/queue.ts, src/scheduler/lock.ts and src/scheduler/worker-pool.ts, plus the failing CI log and a thread dump. It suspects lock ordering across the three files but has not confirmed it. No external library behaviour is involved. Describe the route for diagnosing and fixing it; do not execute tools.", + "expected_output": "Keeps the diagnosis and fix with the root, because the evidence is already in its context and the steps across the three files must be connected; a worker's summary would lose them. Does not treat the bug's difficulty alone as a reason to delegate. Any agent it uses serves a fresh-context or independence need, such as an independent review of the concurrency fix given the diff and contract.", + "files": [], + "expectations": [ + "Keeps the deadlock diagnosis with the root rather than dispatching a diagnostician, researcher or explorer to investigate it.", + "Gives the evidence already in the root's context, or the need to connect steps across the three files, as the reason; does not cite difficulty alone as a reason to delegate.", + "Any agent it does use serves independence or a fresh context (for example an independent reviewer of the fix given the diff and contract), not the diagnosis itself." + ] } ] } diff --git a/skills/engineering/orchestrate/references/routing.md b/skills/engineering/orchestrate/references/routing.md index 7c5cbb3..c039351 100644 --- a/skills/engineering/orchestrate/references/routing.md +++ b/skills/engineering/orchestrate/references/routing.md @@ -9,7 +9,8 @@ Load this reference when choosing root-only work, delegation, a role, a model ti | Small localized edit or lookup | Root | Keep the current root model | Focused diff or direct evidence | | Narrow mapping, extraction, reproduction, or mechanical check | One cheap native role | Use the least expensive configured role that can meet the check | Paths, symbols, exact command and result | | Bounded implementation | One owned native worker | Economical routine tier when acceptance is clear; stronger configured tier when ambiguity or impact requires it | Diff plus behavior checks | -| Difficult diagnosis or current external fact | Native researcher/diagnostician | Escalate within the active host only when the evidence need warrants it | Reproduction or authoritative evidence | +| Steps that consume each other's output or touch the same data | Root, or one worker owning the whole chain | Tier for the hardest step | Combined diff plus behavior checks | +| Diagnosis or research needing more material than the root should hold, or a current external fact | Native researcher/diagnostician | Escalate within the active host only when the evidence need warrants it | Reproduction or authoritative evidence | | Security, concurrency, compatibility, or material regression review | Independent native reviewer | Stronger configured tier when risk justifies it | Findings tied to the integrated diff | Difficulty includes ambiguity, dependency breadth, and failure impact. Verifiability includes how directly a result can be checked. High verifiability supports a cheaper role; high ambiguity or consequence supports a stronger role. This is a routing hypothesis, not a claim that model families are universally ranked.