Subagents orchestration guide

From shinpr/codex-workflows · View interactive version

Subagents orchestration guide is an AI agent skill from the GitHub repository shinpr/codex-workflows. Coordinates custom specialists through workflow phases, artifact handoffs, approval gates, and autonomous implementation. Use when executing a workflow recipe or routing its next specialist.

How to use this skill

Skill file

Subagents Orchestration Guide

Load subagent-delegation for assignment, waiting, and intervention rules. This guide owns workflow-specific coordination.

Invocation rule: Start each named agent with spawn_agent and fork_turns="none". When invoking the same named agent again within this flow, use followup_task on its existing instance with the inputs specified for the current invocation.

Role: The Orchestrator

The orchestrator owns workflow state and directly performs lightweight coordination: locating artifacts, reading status fields, resolving paths, applying explicit user answers, updating execution plans and continuation records, running deterministic repository checks, and filling specialist input contracts from their sources. Invoke a specialized subagent when a recipe names that role or the work requires its domain judgment or implementation authority.

Purpose and Decision Authority

Every role owns the smallest sufficient result within its assigned scope. Unnecessary mechanisms create downstream implementation, verification, and maintenance work. Apply ai-development-guide's Outcome Boundary: evidence and prior passage do not establish necessity or lifecycle value.

A phase pass means the current evidence permits progression. User confirmation permits the requested next work; neither makes internal design choices immutable. Final user acceptance concerns the delivered outcome. Interpret existing approved or ADR Accepted records as passage/continuation in context, without requiring a new field or repeating permission already granted.

Interpret user responses by their meaning and the authority they supply. Continuation or route approval advances the workflow. A product requirement or exclusion enters scope when the user's response selects it.

Resolve outcome-preserving technical reductions, including superseding ADR choices, through existing owners. Update only affected sources, tasks, and proof, and continue within the user's execution authority. Escalate changes to user-required outcomes, explicit constraints, actual consumer obligations, or external-action authority. Optional new requirements remain unadopted; propose a requirement expansion only with evidence that the current conditions cannot deliver the requested result; requirement reductions follow Requirement reopening after codebase analysis.

Execution Plans

Reuse one active execution plan for the recipe. When none exists, create it before substantive multi-step work with the recipe phases and final verification, then update the same plan as evidence is produced. Agent-internal execution plans remain local to each agent. Plans prevent skipped work; their wording or presence is not a user approval gate.

Entry Ownership

The invoked recipe determines the workflow entry point. Recipes for new or scope-changing requirements may invoke requirement-analyzer for compact scope and cost evidence. The user retains product requirements and exclusions; the orchestrator owns evidence comparison, readiness, Structural Scale, and documentation and workflow routing. Continuation, build, review, diagnosis, document update, and reverse-engineering recipes resume from their declared artifacts and request new scope evidence only when their own scope-change rule fires.

Requirement Convergence

The orchestrator builds the convergence object from the user's wording and compares it with requirement-analyzer's scope and cost evidence. At the requirements stop, apply Requirement Convergence and its Scope Confirmation output shape. The user's selections supply product requirements and exclusions; the orchestrator then judges readiness and determines Structural Scale, documentation routing, and workflow routing.

Before a PRD or Design Doc exists, include the object only in the handoff that needs it. After it is persisted, pass the document path instead of copying the object through later prompts.

Requirement Evidence Handoff

For a new or scope-changing request, retain the complete user wording in the orchestrator context. Give requirement-analyzer only the minimum evidence contract:

Keep all remaining requirement detail for comparison after the result returns. The handoff supplies an evidence target, while the retained user record supplies product requirements and exclusions. Requirement analysis completes when the evidence result returns; parallel orchestrator work stays outside the delegated evidence boundary.

A PRD is both a binding product contract and a Product Context carrier. Downstream design and planning prompts consume the converged outcome, requirements, acceptance criteria, user-decided exclusions, and explicit constraints. They load Product Context only when one of those binding items cites it. This keeps business, UX, and feasibility background available for product judgment without turning it into implementation scope.

Requirement Change Detection During Flow [MANDATORY]

During flow execution, compare a user addition with the outcome, requirements, and exclusions:

Preserve completed unaffected work on either route.

Requirement reopening after codebase analysis: When the first codebase-analyzer result after requirement confirmation shows existing behavior that would serve a requirement's need if the requirement dropped behavior it adds on top, whichever field reports it, present each such requirement with that existing behavior, the added behavior, and its cost effect at one requirements stop before UI Spec, ADR, or Design Doc work, and let the user keep or change it. Apply the answer through Handling Requirement Changes and continue; later analyses do not reopen requirements this way. The user selected the requirements before any code was read, so that selection does not answer this question. Never leave such a requirement out because it can be built as specified, because existing behavior cannot be reused unchanged, or because a design choice not yet made would exclude that behavior: every later phase builds and reviews against the requirement without questioning it, so added behavior left out of this stop becomes implementation, verification, and maintenance cost that nothing downstream removes.

Orchestration Principles

Task Assignment with Responsibility Separation [MANDATORY]

Assign work based on each subagent's responsibilities:

What the orchestrator completes directly:

What to invoke task-executor for:

What to invoke quality-fixer for:

How to Invoke Agents

Apply the Invocation rule above. Resolve missing workflow inputs that affect the next action or its verification from repository and governing evidence; route remaining blockers through Orchestrator Escalation Resolution.

Invocation Prompt Requirements

Analysis Assignment

For codebase-analyzer and ui-analyzer, determine the effective child model, including known inheritance. Pass exploration_mode: autonomous only for gpt-6.2-astra; pass guided for every other or unknown model.

Assign distinct questions: codebase analysis owns responsibility/data/contracts/reuse; UI analysis owns rendering/interaction/visual evidence. Pass existing relevant findings as prior_evidence to reuse them. Carry evidence-backed simplifications as candidates, retaining their conditions; technical choices remain revisable under Purpose and Decision Authority.

Explicit Stop Points [MANDATORY]

Use these stops when the active recipe reaches a user decision or authority not already supplied. Outcome-preserving technical corrections return through their owners without repeating these stops.

| Phase | Stop Point | User Action Required |

|-------|------------|---------------------|

| Requirements | After an entry recipe invokes requirement-analyzer | Converge fields below ready, then confirm requirements |

| PRD | After document-reviewer completes PRD review | Confirm the required outcome and continue |

| Requirement reopening | After the first codebase-analyzer result when it shows existing behavior that would serve a requirement's need without behavior the requirement adds on top | Keep or change each affected requirement |

| UI Spec | After document-reviewer completes UI Spec review (frontend/fullstack) | Confirm the UI outcome and continue |

| ADR | After document-reviewer completes the complete ADR-batch review (when ADRs were created) | Continue with the current technical choices |

| Design | After design-sync completes consistency verification | Continue with the current design |

| Work Plan | After document-reviewer completes WorkPlan review for Medium/Large | Authorize implementation within this outcome |

After implementation authorization, continue autonomously until completion or a user-owned decision requires input. A repeated review is not a new permission gate.

Design Confirmation

At the existing design confirmation stop, read the current PRD (when present) and Design Doc(s). Derive the minimum user-visible value and briefly state it alongside the major changes included, making internal mechanism changes or refactoring visible. Ask whether this MVP and scope match the user's intent. Keep this to a short alignment message, rather than design detail or a justification of necessity. Apply corrections through the existing scope-change flow.

Common Status Meanings

Use agent statuses as routing signals, not as a parser contract. Prefer pass for new review results; interpret legacy approved as the same phase passage. Interpret the artifact and evidence when a field is absent or worded differently. Reviewer passage alone grants no user-held execution authority.

| Status | Scope | Meaning | Next Action |

|--------|-------|---------|-------------|

| pass (legacy approved) | Review/check agents | Current evidence passes this phase | Proceed; technical means remain revisable |

| needs_revision | Review/approval agents | Significant issues repairable within the repository scope | Resolve through the normal review or verifier-fix cycle |

| rejected | Document agents | Fundamental problems | Apply Orchestrator Escalation Resolution |

| blocked | Agents whose schema permits it | An agent-specific blocking condition prevents a usable result | Apply Orchestrator Escalation Resolution |

| skipped | Review/approval agents whose schema permits skipping | Preconditions not met for this step | Report reason, proceed |

Review Resolution

Apply references/review-resolution.md wherever review or verification results can generate work. Before assigning repairs, record the disposition; retaining or adding a mechanism requires a reason subtraction cannot deliver the required result. Pass user outcomes and explicit constraints separately from revisable technical decisions.

Lite Mode

When the user requests Lite Mode (light mode), read references/lite-mode.md before the next workflow decision and apply it until the user withdraws the request.

Orchestrator Escalation Resolution [MANDATORY]

Apply this procedure when a workflow result cannot support the next action, including escalation_needed, blocked, a missing artifact, or contradictory evidence. The response returns control to the orchestrator; it is not itself a human stop. For review results, Review Resolution still governs scope, completed reviewers, and rerun boundaries.

  1. Resolve the issue from user requirements, governing artifacts, repository evidence, and prior agent outputs. For missing invocation context, supply it and rerun the interrupted agent; assign artifact changes only when the evidence requires them. Choose the smallest resolution that preserves user intent.
  2. Invoke the responsible author or reviewer with the artifact and concrete issue, then retry the interrupted step with the resulting artifact and evidence.
  3. Retry the interrupted step while corrections add evidence or materially change the result. When progress stops, decide the remaining disposition from governing sources and continue to the next resolution step.
  4. Resume when the interrupted step succeeds or only a non-blocking disagreement remains. Apply Purpose and Decision Authority to user escalation; a smaller technical design alone is resolved by the orchestrator and relevant owners. Preserve unaffected work and still-valid evidence.

Work Plan Resolution

Resolve an exact Work Plan path from the first applicable source: an explicit recipe argument, the active execution plan's Work Plan, or Work Plans derived from task files matching the recipe's managed task patterns. When no managed task file yields a candidate, treat non-template Work Plans as candidates. Use the sole candidate; when multiple candidates remain, present them for selection; when none exists, report the exact missing prerequisite.

Work Plan Authorization

Planning recipes create and review the Work Plan, then resolve implementation authority from the user's instructions. Record its source and scope in Implementation Authorization; obtain it only when absent. Review passage remains in the reviewer response, not a second plan status.

A build proceeds from the user's authorization to implement, recorded in the conversation or existing plan. Accept equivalent continuation wording and legacy approval records; a reviewer-only pass is not user authorization. Ask only when that authority is absent. Route technical reductions through affected plan/task updates without asking again; user-outcome or authority changes follow Purpose and Decision Authority. Regenerate affected uncommitted task files and preserve unaffected work.

Scale Determination and Document Requirements

Use documentation-criteria Structural Scale as the single scale definition.

| Scale | PRD | ADR | Design Doc | Work Plan |

|-------|-----|-----|------------|-----------|

| Small | None | None | None | None |

| Medium | Update* | Conditional batch | Required | Required** |

| Large | Required or user-authorized convergence carrier* | Conditional batch | Required | Required** |

\* Update if PRD exists for the relevant feature

\\ One ADR per durable technical choice that requires comparison between at least two credible materially distinct options; the Choice and Durability filters determine qualification independently of scale

\\\* Create, update, or reverse-engineer the PRD in flows that own it. A design recipe that does not create PRDs may use its convergence carrier after the user explicitly authorizes that route.

Using Agent Results

Agent schemas describe their full internal result. The orchestrator consumes only the fields needed for the next action:

| Producer | Consumer-required result |

|---|---|

| Artifact producer | completion or blocked state, plus produced artifact path(s) |

| Task executor | completion or escalation state, filesModified, requiresTestReview, operation-verification evidence, and completionCriteria |

| Quality fixer | pass, stub_detected, or blocked state; filesModified; reason or findings when not passed |

| Reviewer | decision, actionable findings, governing basis, and whether each finding blocks the outcome |

| Analyzer | only reuse, invalidation, decision-point, cost, contract, verification, and decision-changing unknown material needed by the next consumer |

Continue through minor optional-field, serialization, or wording differences when the orchestrator can verify the required outcome from the artifact, repository, or command result. Verify claimed paths before passing them onward. Route a missing artifact, failed implementation, unresolved contradiction, or otherwise unusable result through Orchestrator Escalation Resolution.

Per-Task Change Set

For each implementation task, record diffBase and maintain one taskWriteSet:

  1. Initialize it from the first executor's filesModified and the repository diff from diffBase.
  2. Union files changed by executor retries, review fixes, stub repairs, and the quality fixer.
  3. Before quality review and before commit, reconcile it with repository state so earlier changes are retained and unrelated user changes are excluded.
  4. Pass the accumulated taskWriteSet to the quality fixer. After quality pass, commit only implementation, test, and required generated files in that set. After that commit succeeds, mark the Task File's Completion Criteria that the executor's completionCriteria evidence satisfies and the corresponding Work Plan task and phase complete, then update the active execution plan.

Task Files and Work Plans are local workflow state. Exclude both from implementation commits; their checkboxes record completion only after a successful implementation commit.

Handling Requirement Changes

Handling Requirement Changes in requirement-analyzer

Update the orchestrator's retained user record with the new wording. When the change invalidates the analysis target or scope/cost evidence, repeat the Requirement Evidence Handoff from the changed outcome and its essential reason or constraint. Otherwise update the convergence record directly.

Update Mode for Document Generation Agents

Document generation agents invoked in update mode can update their existing target documents.

Basic Flow for Work Planning

After the selected entry recipe completes its requirement stop, follow the minimum flow required by scale and affected layers. Continuation recipes resume from their declared artifact.

| Scale | Required flow |

|-------|---------------|

| Large | scope evidence + requirements convergence [Stop] -> PRD creation/review [Stop] when the active recipe owns it; otherwise its user-authorized convergence carrier -> codebase analysis -> requirement reopening when applicable [Stop when applicable] -> frontend/fullstack UI Spec + document-reviewer [Stop] -> optional ADR batch + one batch document-reviewer [Stop] -> technical-designer* -> code-verifier + Review Resolution -> document-reviewer -> design-sync [Stop] -> acceptance-test-generator -> work-planner -> document-reviewer (doc_type: WorkPlan) [Stop] -> task-decomposer |

| Medium | scope evidence + requirements convergence [Stop] -> codebase analysis -> requirement reopening when applicable [Stop when applicable] -> frontend/fullstack UI Spec + document-reviewer [Stop] -> optional ADR batch + one batch document-reviewer [Stop] -> technical-designer* -> code-verifier + Review Resolution -> document-reviewer -> design-sync [Stop] -> acceptance-test-generator -> work-planner -> document-reviewer (doc_type: WorkPlan) [Stop] -> task-decomposer |

| Small | scope evidence + requirements convergence [Stop] -> one standard task file -> task execution cycle |

Flow rules:

Autonomous Execution Mode

Conditional Environment Preparation

Build recipes proceed with the approved task set. recipe-prepare-implementation runs when the user explicitly requests repository-local setup or when a concrete task-local capability failure makes preparation the smallest authorized Orchestrator Escalation Resolution. Unaffected implementation continues.

Definition of Autonomous Execution Mode

Within execution authority established by Work Plan Authorization or the Small flow, autonomously execute:

Authorized scope -> task decomposition when needed -> each task:
implementation -> optional integration-test review -> quality-fixer -> commit
-> final code/security review -> completion report

Reviewer findings in this mode are candidates, not work orders; create repair work only from the Review Resolution apply set.

For each task, record diffBase, run the routed executor, and inspect the resulting repository change. Add each execution or repair result to the Per-Task Change Set. Run integration-test-reviewer when requiresTestReview is true and changed integration/E2E paths exist, then resolve findings through Review Resolution. Run the routed quality-fixer with the accumulated taskWriteSet and the executor's operation-verification evidence. The quality fixer reruns task-specific verification when evidence is missing or its fixes can invalidate that evidence. On quality pass, add its changed paths to the set and commit the reconciled Per-Task Change Set. After the commit succeeds, mark the Task File's Completion Criteria that the executor's completionCriteria evidence satisfies and the corresponding Work Plan task and phase complete, then update the active execution plan. Repair stub_detected through the same implementation owner. Resolve blocked or unusable results through Orchestrator Escalation Resolution.

Conditions for Stopping Autonomous Execution

Stop autonomous execution and request user input in the following cases:

  1. Orchestrator resolution requires user input: Orchestrator Escalation Resolution reaches one of its user-escalation conditions
  2. Scope change needs user approval: Requirement Change Detection routes the addition through Requirement Convergence
  3. User explicitly stops: Direct stop instruction or interruption

Agent blocked results, maintained blocking findings, and implementation deviations first enter Orchestrator Escalation Resolution. The orchestrator requests user input only under that procedure's explicit user-decision conditions.

Continue autonomous execution in the following situations:

Use the task loop defined in the autonomous execution diagram above. The canonical per-task cycle is:

  1. capture diffBase, execute the task, and accumulate its change set
  2. resolve escalation or integration-test review when applicable
  3. run the quality fixer on the accumulated change set and resolve findings until the required checks pass
  4. commit the reconciled Per-Task Change Set, then record Task File, Work Plan task/phase, and execution-plan completion locally

Post-Implementation Review

| Reviewer | Pass | Requires disposition | Blocked |

|----------|------|------|---------|

| code-reviewer | verdict is pass | verdict is needs-improvement or needs-redesign | verdict is blocked |

| security-reviewer | status is pass (legacy approved) | status is needs_revision | status is blocked |

Review Units

One code-reviewer cannot judge every file of a large change at the same depth, so a Medium or Large change is reviewed in units of completed Work Plan tasks. A unit holds a consuming task (one delivering a screen, route, command, or job) together with the tasks it depends on through Depends on, so a contract's producer, its consumer, and the tests proving their behavior are reviewed together. Tasks that several units depend on form one shared unit. Each completed task belongs to exactly one unit, and a unit's implementationFiles are the files changed by its tasks' implementation commits; a file changed outside the task cycles joins the unit whose behavior it changes. A change whose tasks form one unit has one code-reviewer.

Invoke one code-reviewer per unit with the governing Design Docs, the unit's implementationFiles, the Work Plan path, and the unit's tasks as task scope. A Small flow has one code-reviewer with its active task file as the governing source. security-reviewer reviews the complete change once with the same governing sources; the Small path passes its active task file as type: task-file. Mechanical repository checks remain owned by the quality-fixer in each implementation or review-fix task cycle.

Apply Review Resolution to reviewer findings. Apply a security-reviewer finding only when leaving it unresolved would violate an explicit governing requirement or repository rule, or leave a concrete material security failure in the actual reachable trust model. The violated requirement, rule, or failure defines implementation scope: route the smallest correction that resolves it, treating the reviewer's suggestion as one candidate implementation.

Reruns

The reviewer that reported a finding reruns it under Review Resolution. After each correction, also compare its actual diff with the scope of every other passed review, because a shared contract corrected for one unit's finding can invalidate another unit's pass. A code-reviewer's scope is its implementationFiles, the ACs or requirements its task scope or governing source makes applicable, and the contracts those files provide or consume; security-reviewer's scope is the trust boundaries the complete change touches. Rerun a reviewer whose scope the diff changes in behavior, contract, or proof, with its previous result and that diff as prior_feedback, and retain every other passed result; a correction that touches the same file without changing that behavior, contract, or proof reopens nothing.

Main Orchestrator Roles

  1. State Management: Track current phase, each subagent's state, and next action
  2. Lightweight Workflow Work: Resolve artifact paths and statuses, build the convergence record from user selections, judge readiness and finding dispositions from supplied materials, update execution plans and approval fields, and run deterministic routing checks
  3. Information Bridging: Transmission between subagents
  1. Quality Assurance and Commit Execution: Execute git commit through the per-task cycle
  2. Autonomous Execution Mode Management: Start/stop autonomous execution after approval and escalation decisions
  3. ADR Status Management: Update ADR status after user decision (Accepted/Rejected)

Required Handoffs

| From | To | Required pass-through |

|------|----|-----------------------|

| requirement-analyzer | orchestrator requirement hearing | compact scope and cost evidence; the orchestrator compares them with retained user wording, obtains user selections, and decides readiness and scale before codebase analysis |

| requirement carrier | codebase-analyzer | current PRD path when present, otherwise the convergence record's requirements, plus compact scope evidence |

| convergence record | PRD or Design Doc owner | prd-creator persists PRD fields; technical-designer* persists Design Doc fields when no PRD exists; both record open requirement fields while cost remains ephemeral |

| convergence record | Small-flow implementation | compact record in the task file's Governing Sources when no PRD or Design Doc exists |

| codebase-analyzer | orchestrator and technical-designer* | relevant simplifications, reuse, invalidations, candidateDecisionPoints, verification, decision-changing unknowns, and material limitations; the orchestrator passes the qualifying ADR points to the designer |

| technical-designer* | ADR batch reviewer | complete ADR paths[] from the invocation |

| technical-designer* | code-verifier | Design Doc path |

| code-verifier | orchestrator Review Resolution, then technical designer or document reviewer | apply discrepancies for the author; declined reasons and resolved verification evidence for the next reviewer |

| task-executor* | integration-test-reviewer | diffBase, changed integration/E2E paths, exact task file, and matching skeleton paths when available |

| implementation task | quality-fixer* | exact task file, accumulated taskWriteSet, and operation-verification evidence |

| acceptance-test-generator | work-planner | artifacts[].path |

| work-planner | document-reviewer | completed path |

| task-decomposer | routed task-executor* | completed taskFiles[] |

| Design Doc | work-planner | Design Doc path; work-planner reads only sections that control task outcome, order, or verification |

Handoff rules:

Important Constraints [MANDATORY]

Required Dialogue Points with Humans [MANDATORY]

Basic Principles

Action Checklist

When receiving a task, check the following:

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.