---
name: agent-orchestration
description: Orchestrate coding work across subagents and models by complexity, risk, and provider quota. Use when delegating multi-step work, choosing a model or effort, or when a provider hits a quota limit.
license: MIT
compatibility: Any harness with subagents. Optional helper script requires Python 3.9+ (stdlib only).
metadata:
version: "0.48.0"
---
# Agent orchestration
Act as the **orchestrator** and keep your own spend low: handle cheap checks yourself (a small diff, one key test) and delegate expensive work (implementation, deep research, large-diff summaries, review, and reading screenshots or large diffs, keeping only the verdict: `references/verification.md`).
Read models only from discovery and two data files:
- `catalog.yaml` (next to this file): shared model facts, merged with `catalog.local.yaml` next to `assets.yaml` when present.
- `~/.config/agent-orchestration/assets.yaml` (or `$AGENT_ORCHESTRATION_ASSETS`): per-user providers, quota status, preferences, and policy (`assets/assets.example.yaml`). When missing, proceed with defaults (`references/selection.md`), note it in one line, and offer to create it (`scripts/orch.py probe --init`).
Every `scripts/orch.py` command ends with one decision line (`action:`, `ok:`, or `error:`): follow it.
## 1. Discover (once per conversation)
List available `provider:model` pairs with your harness's discovery (`references/harnesses.md`) and intersect them with the catalog. Run `scripts/orch.py policy` (on `error:`, use defaults and tell the user once; `references/repo-policy.md`), `scripts/orch.py probe` (quota, expired lockouts, `followups`: `references/fallbacks.md`), and `scripts/orch.py check --available <provider:model,...>` (notes what this harness does not offer). Research any required model missing from the catalog or `rating: unrated` once (`references/research-unrated.md`).
*Done when*: every available `provider:model` pair is mapped to the catalog, repo policy (if present) is loaded, quota status and follow-ups are checked (or noted unverified), and any needed unrated model is recorded once.
## 2. Classify
Score the rubric in `references/selection.md` and run `scripts/orch.py classify` (repo `High risk:` triggers set `consequences: 2`). Decide the [delegation surface](references/harnesses.md#delegation-surface). Note the `--ui` or repo `Models:` preference, tool needs, and batching (`references/supervision.md`).
*Done when*: rubric (plus coordination score when an orchestrator conversation is planned), complexity, risk, tier, strength/family, tools, surface, and batch order are stated before model selection.
## 3. Choose model + effort
Run `scripts/orch.py select` (`--role implementer|reviewer|orchestrator`) and follow its final `action:` line; without Python, apply `references/selection.md`. Models a plan names ahead are tentative: run this step for each role when its step starts, after a fresh `probe`. Branches: unavailable preferred or tier-meeting model → `references/fallbacks.md`; a user hold or `select`/`defer` hold or step queue → `references/supervision.md` (Deferred launch); reviewer → `references/review.md`; orchestrator → `references/orchestrator.md`. Apply model `quirks` (`catalog.yaml`, `references/harnesses.md`) and clear any Step 7 gate before dispatch. Log each selection with its `--role` (`scripts/orch.py log --event select`, `references/improvement.md`).
*Done when*: a primary `provider / model @ effort` (or staged Phase 1 + Phase 2 target), delegation surface, and (for reviewed work) a reviewer from `references/review.md` are selected at step start (held only when `select` says hold or ask, or the user holds work) with quirks noted and logged.
## 4. Brief
Orchestrators: [route implementation before editing](references/orchestrator.md#route-implementation).
Send one outcome per worker with the selected provider instance, model, and effort (`references/harnesses.md`). Fill `references/brief-template.md`, then verify the effective selection. A `retro` brief includes its publish lane (`references/improvement.md`). Persist staged or multi-item state, supervise non-notifying children, and act on each completion notice in the same turn (`references/supervision.md`).
*Done when*: all applicable brief fields are filled, effective settings are verified, staged and multi-item state persists locally, and every non-notifying child has active supervision.
<!-- ‹guest · 2026-12-03› -->
## 5. Quality gates
Each gate's rules live in `references/verification.md` unless named otherwise.
1. **Red→green evidence**: require failing repro/test output before the fix and passing output after, scaled to the user's and repo's evidence priorities.
2. **Design checkpoints**: for user-visible taste decisions, apply the checkpoint gate.
3. **Cross-family review**: run `scripts/orch.py scope` first, then review with a different model family given the diff or a shared **evidence pack** (reviewer fallback order: `references/review.md`); agent-facing docs, including your own edits, get the doc review loop. Send fixes to the implementing child via the harness's continue mechanism (`references/harnesses.md`). On `rework`, important findings at the escalation threshold, or a child's `STATUS: ESCALATE`, run `scripts/orch.py escalate` and follow its `action:` line (`references/escalation.md`).
4. **Final check before landing**: run the [pre-landing checklist](references/verification.md#final-check-before-landing-step-54), including its `land-check` decision. For production targets, run `scripts/orch.py prod-check` (`references/orchestrator.md`).
5. **Land**: follow repo policy `Land:` (`references/repo-policy.md`) or documented process (`AGENTS.md`/`CLAUDE.md`), within a `retro` issue's lane (`pr-only` and `confirm` PRs carry `hold` from publish and stop at a ready PR; `references/improvement.md`); advance any dependent batch waiting on these paths, and wind down the supervision loop when the batch finishes (`references/supervision.md`).
6. **Log outcome**: append completion (`ok|failed|quota|stall|rework` + findings count) to the decision ledger (`scripts/orch.py log`, `references/improvement.md`), plus one `friction` row per environment obstacle the child reported.
7. **Retro check**: when a batch closes, run `scripts/orch.py retro-check --repo <name>` for each repo it touched and follow its `action:` line (`references/improvement.md`).
*Done when*: proportional red→green evidence and any taste checkpoints are approved, review findings are resolved, the pre-landing checklist passes, the change lands (or, under `hold`, waits ready for its own owner authorization), dependent batches or supervision wind-down run, the outcome and friction are logged, and a closed batch's repos are retro-checked.
## 6. Quota and failure handling
- **Quota error**: run `scripts/orch.py exhaust` with selection arguments (reset parsing and scope in `references/quota-errors.md`), log `--outcome quota`, and follow its `action:` line through the recovery order in `references/harnesses.md`. For this conversation's own quota, pass `--self --coordination <0|1|2>` instead of the worker arguments (`references/orchestrator.md`).
- **Known infrastructure failures and unstarted PR checks**: apply the single-rerun and merge-state gates in `references/verification.md` before investigating or waiting.
- **Other child failures** (provider refusal, context cap, tool error, unknown): run `scripts/orch.py failure "<error text>" --ref <item>` (`references/supervision.md`).
- **Harness quirks or stalls**: follow the harness row in `references/harnesses.md`, `quirks` in `catalog.yaml`, and the supervision loop; log `stall` outcomes to the ledger.
- **Friction**: `failure` logs its own `friction`. Log other failures via `references/improvement.md`.
- **Manual fallback**: when the user reports facts probes cannot see (plan cancelled, renewal date, manual reset, preferences), update assets per `references/assets-updates.md`.
*Done when*: exhausted scopes carry reset times in assets, expired lockouts clear, failures follow retry/rerun and merge-state rules, any quota or reviewer hold passes `scripts/orch.py defer`, interrupted or staged work switches in place or schedules a `resume` wakeup, and outcomes are logged.
## 7. Decide, ask, report
Execute routine choices yourself: in-place model switches, staged Phase 1 launches and phase-boundary switches, same-conversation scheduled resumes, supervision checks, single reruns of known infrastructure failures, delegated design checkpoints (`design_checkpoints: delegate`), and a `select` candidate from a `low` or `preserve` pool. Waiting for a preferred model to renew is not by itself a reason to hold or to ask: dispatch what its `action:` line names now and choose the reviewer when its step starts. Before deferring an item, asking whether to wait, or announcing a stop over quota or reviewer family, run `scripts/orch.py defer` and follow its `action:` line. Follow a manual-reset request from the action line of `select` or `exhaust` (`references/assets-updates.md`). Ask the user once before destructive or irreversible actions, publishing, spending emergency models/efforts outside the active grants in [approval windows](references/assets-updates.md), spending pay-per-use APIs under `preferences.pay_per_use: ask` (under `never`, keep them excluded), opening a new top-level conversation when `preferences.new_conversations: ask`, proceeding when `preferences.ui_fallback: ask`, approving a taste checkpoint when `preferences.design_checkpoints: ask` (default), or resolving ambiguity that changes the outcome. Log every owner correction as a `friction` row (`references/improvement.md`).
**Reporting to the user** uses one line per event to say what finished, what is next, and what the user must decide. Use `OWNER_LANGUAGE` for all owner-facing text, including interim notes, and restate it after compaction or handoff. Run `scripts/orch.py report --event <id> --kind <kind>` and follow its `action:` line. Skip acks and resource releases (`preferences.report_acks: false` by default). Honor “no reply needed” by leaving the thread quiet. Name each change, then its PR or issue number. Use `orch.py history` for model questions and `orch.py board` for open work and owner decisions. Keep model details in the report unless the owner asks or needs them to decide.
Update your plan with `orch.py item` at each state change and run `item sync` at batch boundaries. Record `--thread <id>` on dispatch. Run or schedule the [supervision tick](references/supervision.md#supervision-loop) and follow its `action:` lines.
Phase boundary: run `orch.py board --mine <your-thread-id>` and follow its `action:` lines.
*Done when*: routine decisions are reported one line each and every listed high-impact or taste gate waits for one explicit approval.
## References (load on demand)
- `references/selection.md` — every run: rubric, tier floors, risk triggers, effort knee, filter and ranking.
- `references/fallbacks.md` — unavailable model: `ui_fallback`, `below_tier` staging, follow-ups.
- `references/review.md` — reviewer step: tier, fallback order, rounds, attestation, evidence pack.
- `references/orchestrator.md` — orchestrator or launch: ladder, own quota, production changes, `orch.py launch`.
- `references/escalation.md` — escalation: `rework`, findings, `STATUS: ESCALATE`.
- `references/supervision.md` — batches and children: deferred launch, durable state, supervision, rebalance, refusal, retries, replacements.
<!-- ‹guest · 2026-12-03› -->
- `references/verification.md` — quality gates: evidence, scope, doc review, design checkpoints, pre-landing, infra reruns.
- `references/harnesses.md` — harness: delegation surface, quota recovery order, requested-vs-effective check, command matrix.
- `references/brief-template.md` — brief: layout and report sections.
- `references/repo-policy.md` — repo policy: contract, precedence, brief forwarding.
- `references/quota-errors.md` — quota error: probe thresholds, exit codes, reset parsing.
- `references/assets-updates.md` — user-reported facts: plain-language `assets.yaml` edits.
- `references/research-unrated.md` — unrated model: one-time scoring.
- `references/improvement.md` — ledger and retros: logging, friction and retro dispatch, ladder calibration, upstream findings, updates.
این نسخه با نشانهگذاری اختصاصی حساب شما نمایش داده میشود. برای نصب سریع، به تب نصب و راهاندازی بروید.