--- name: orchestrate description: "Internal, invoked from the orchestration context: tier classification, delegation model table and phase-owner dispatch rules for sizing and dispatching implementation work." user-invocable: false --- # Orchestrate - Tier, Delegation and Dispatch On-demand depth for sizing work and dispatching agents. Shapes are in [`_generated/call-shapes.md`](../_generated/call-shapes.md); ids below are 8-hex shorts (a full UUID is also accepted). `steering` lives under `extensions.claude-code` in the project config (see [`extensions`](../../../../current/docs/config-reference.md#extensions)). The tier table and the delegation model table apply when it is `workflow`. In `schema` mode the schema alone governs process, so skip the tier and model-table content; the phase-owner dispatch rules and the explicit-`model` rule below still apply, with the model chosen by judgment. ## Tier Classification Classify every piece of work into a tier before starting; the tier decides how much process to apply. | Criteria | Tier | Pipeline | |----------|------|----------| | 1-2 files, known fix, no migration/new API | **Direct** | Orchestrator edits, tests, reviews inline | | 3-10 files, single logical unit, clear or explorable scope | **Delegated** | Single subagent, separate review agent | | 11+ files, multiple independent work streams, dependency edges | **Parallel** | Worktree agents, full pipeline | **Force-UP signals** (bump tier regardless of file count): - Database migration -> min Delegated - New public API surface -> min Delegated - Multiple independent work streams -> Parallel - User says "let's plan" / collaborative language -> min Delegated **Force-DOWN signals:** - User says "just fix it" / "quick" -> Direct (unless complexity contradicts) - The item's type resolves to the `default` schema, or the item is schema-free -> eligible for Direct Thresholds and signals are data: `tiers` in the plugin's `dispatch-policy.json`. When `.taskorchestrator/tier-policy.json` exists beside the project config, the table in force is the output of `node /scripts/tier-policy.mjs`. ### Tier Pipeline Summary | Step | Direct | Delegated | Parallel | |------|--------|-----------|----------| | Plan mode | skip | optional | required | | Queue notes | none required | fill per schema | fill per schema | | Implementation | orchestrator inline, no subagent, no delegation metadata | single subagent | parallel worktree agents | | Review | inline (orchestrator) | separate agent | separate agent | Review applies only when the item's schema declares review-phase notes; otherwise work advances straight to terminal. Detect it from `newRole` in the `advance` result and skip review dispatch. **Director mode.** Director mode is the session state entered by `/task-orchestrator:director` (or by running as the hardened `director` agent). No tier runs inline there: Direct and Delegated work becomes ONE background `Agent` (`run_in_background: true`, `model` set) that runs the pipeline above; Parallel work goes to an orchestrator (see [coordinator-tiers.md](../director/references/coordinator-tiers.md)). A background agent dispatched by a director is not in director mode: it runs the tiers above. **Multi-item dispatch:** when post-plan-workflow's four-part condition holds (two or more unblocked leaf items, a resolvable rootId, filled queue notes, protocol rules served), dispatch goes through `/task-orchestrator:run-wave`; otherwise hand-dispatch. ## Delegation Model and effort per kind of work come from the plugin's dispatch policy: load `task-orchestrator:model-effort` for its class table (bulk writes, implementation, planning, review and the rest) and the rules for raising or lowering effort. **Always set `model` AND `effort` explicitly** on every Agent dispatch: an omitted `model` runs on the orchestrator's own model, and an omitted `effort` runs at the model's default (`dispatch-model-guard` denies both). **A fix after a failed test or review runs at a raised effort.** When a hand-dispatched implementer's or test author's work fails a test or a review and you send the fix back, dispatch a FRESH agent (not a `SendMessage` resume: a resumed agent keeps its effort) with the same model and the effort the policy's `escalate` rule gives: the base effort raised by the step, which is 1 plus the seat's earlier fixes after a failed review or test, capped at the policy's `escalation.ceiling` (`model-effort` states it). A failure past the ceiling is a decision for a person, not another cycle at the same effort. A late carry-in or a breach replacement is not a failure and keeps the original effort; reviewers never escalate. Inside a run, `reseat --cause` computes this for you (run-wave `post-run.md`). **Show the assignment in the dispatch `description`.** End every Agent `description` with ` [/]`, for example `implementer:5fc03a84 [sonnet/high]`: the app's background-task list shows only that string, and the run-wave workflows put the same tag on their labels, so a reader can tell what each agent was assigned without opening it. ### Dispatching an item's phase owner This applies only to the agent that OWNS the phase being entered (the implementer entering work, the reviewer entering review), never to the test author, planning seats or the docs seat; those take their class from `task-orchestrator:model-effort`. Read the profile for the phase you dispatch INTO, not the item's current phase: - If the orchestrator already made the transition (for example it advanced the item into review and now dispatches the reviewer), read `dispatch` off that `advance` `transition` result (`data.results[0].dispatch`): it is the profile for `newRole`, the phase being dispatched into. ```to-call {"tool": "advance", "op": "transition", "args": {"itemId": "4b7d0e19", "trigger": "start"}} ``` - If the agent will perform its own phase entry (the agent-owned-phase protocol: the implementer is dispatched while the item is still in queue and calls `start` itself), `items_read` `context` returns only the profile for the CURRENT role (queue), which is the wrong one. Read the schema instead; `dispatch` is the per-phase map and `dispatchBySeat` the per-seat one: ```to-call {"tool": "items_read", "select": "schema", "args": {"itemId": "4b7d0e19"}} ``` When the profile names an `agent`, dispatch with `subagent_type` set to it. Whether or not `agent` is set, pass `model` and `effort` explicitly: the profile's value for each when it sets one, otherwise the value of the work's class in `task-orchestrator:model-effort`. Every shipped agent (implementer, reviewer, planner, test-author, director) ships `model: inherit`, and Claude Code resolves the per-invocation Agent-tool `model` first, then the agent's frontmatter, where `inherit` means the main conversation's model. Omitting `model` silently runs the phase owner on the orchestrator's own model. Pass the effort on the Agent tool's own `effort` parameter, with or without an `agent`. The shipped agent definitions carry no `effort` of their own, so an omitted parameter runs at the model's default. `CLAUDE_CODE_EFFORT_LEVEL` and organization caps outrank the parameter. Auxiliary dispatches on the same item (the test-author seat, planning seats, the docs seat) use the same rule with their own class. For a **seat-aware** item (its schema declares `seats`), read every seat's profile, test author and planning seats included, from the resolved `dispatchBySeat`; it supersedes the class values for those seats. A model-selecting seat-only override wins whatever the trait order (see [Seat dispatch precedence](../../../../current/docs/config-reference.md#seat-dispatch-precedence)). To change a pinned `model`, change it through the project's config traits, not by overriding it at dispatch time. Before dispatching a seat at a feature or wave parent, branch on the parent's role with the pre-dispatch recipe in `/task-orchestrator:schema-workflow` ("Pre-dispatch recipe: a seat at a parent"): never a reviewer at a work-role parent. ### Batching and prompts **Batch writes** per the rule `orchestration-discipline` (point 2), fetched with `docs_read` `get` (`kind` `rule`, `slug` `orchestration-discipline`, `rootId`). The mechanic: one `ops[]` call carries many writes (`items_write`, `notes_write`, `deps_write` and `advance` all take an array). Delegation prompts must include entity ids and full context; subagents start fresh. ### Judgment stays, mechanical work goes down The orchestrator's own model is spent on judgment. It keeps these steps itself: - whether a choice is its own to judge or a decision to raise, by the drive/decide boundary: the orchestrator drives, the user or a director decides; - when it raises one, the `recommended` option and the `context` evidence the answer needs; - the tier, when the sizing signals conflict; - cutting a plan into items; - disposing of review findings (`orchestrator-confirmation`); - triage of a failure: reseat or raise; - whether a branch is ready to merge. A mechanical step whose result it needs only in summary may go to one agent at the `bulk` or `extraction` class (`task-orchestrator:model-effort`): writes that cannot be batched into one call, a status sweep that takes several reads, or a script run whose output it needs only summarised. The agent returns that summary, never the raw output. Verification is never one of these steps (see Verification below). ### Dispatch contract **Parallel-tier dispatches follow a dispatch contract.** Where the project ships a dispatch-contract template, generate the run's plan file from it; otherwise write one plan file for the wave that pins branch, worktree, file ownership, commit form, build self-check and review scoping. Either way, point every dispatch prompt at that file by absolute path instead of restating those rules inline. Under a run plan (`/task-orchestrator:run-wave`) seat prompts are generated and never reference this file; the contract then serves the orchestrator (fallback hand-dispatches, the post-run commit map) and the reviewers, and anything a seat must know goes in the item's `specification` or `task-scope` note. ### Hand-dispatched seats carry the project's verify commands `/task-orchestrator:run-wave` reads the project's `.taskorchestrator/run-profile.json`, and a project dispatch contract pins its own build self-check. A seat you dispatch **by hand**, outside both of those, gets neither unless you put it there. When that file exists: - For each `verify` entry whose `seats` lists the seat you dispatch (`implementer`, `test-author`, ...), paste its `command` into the seat's prompt verbatim, substituting `` and `` (and `` with the seat's owned test paths, space-separated and double-quoted, filtered by the entry's `ownedTestsPattern`; an entry whose owned set is empty is skipped; not supported on orchestrator entries), as the check the seat runs before committing. If the command calls a wrapper that a wave's setup creates (a lock script in the scratchpad, say) and that file is absent, give the seat the same tasks through the build tool directly: the task list is what matters, not the wrapper. - Run every entry whose `seats` lists `orchestrator` yourself, on the item's worktree, at the points the project's rules set (a served rule wins over this text), before dispatching the reviewer. A failure goes back to the owning seat before review, not to the reviewer. - Without a run-profile, the seat runs the checks the item's spec note names. ### Verification **Do not delegate verification.** Follow the rule `orchestration-discipline` (point 1); fetch it as above. ### Notes are the report Subagents write findings into their work item's notes; their final message back is 1-2 lines (item id, outcome, note keys filled). Never ask agents to restate note content in replies. ### Delegation metadata If your project defines a `delegated` trait, apply it to Delegated and Parallel items so the note below is schema-visible rather than convention-only. Traits are an array. Set it at creation, `"traits": ["delegated"]` on the `items_write` `create` (or tree child), or add it later with an update, which REPLACES the list, so send the full list: ```to-call {"tool": "items_write", "op": "update", "args": {"id": "4b7d0e19", "traits": ["needs-docs-accuracy-review", "delegated"]}} ``` An update that changes `traits` is itself a pin point: the item is re-pinned to the current config (see [Schema pins](../../../../current/docs/config-reference.md#schema-pins)). Then, after each subagent returns, fill its `delegation-metadata` work note: model, effort when one was assigned, isolation, a one-line rationale and a one-line outcome. The orchestrator fills this, not the subagent (only the orchestrator knows the dispatch details). On a member of an open run whose schema gives the key `seat: orchestrator`, send that upsert with the run's token; a seat never writes it. It feeds `/session-retrospective`'s delegation-alignment scoring; projects without the trait skip it.