Howto codex

Static reading edition · s04-04

Chain agents through explicit evidence handoffs

Subagents20 min estimatedApp / CLI / IDE

Run dependent stages in the right order and make each handoff precise enough to verify.

Understand the approach

A chain is appropriate when a stage needs evidence produced by an earlier stage. Investigation establishes the actual failure and interface before implementation begins. Integration then waits for both implementation outputs. This does not require serializing every activity: once CONTRACT.md freezes normalized status inputs and report outputs, A and B can work independently. The dependency is between evidence and implementation, then between both implementations and integration.

The capstone makes those dependencies observable. The original starter produces done=1 and doneMinutes=80. A correct normalizer alone should repair the completed count but leave the all-task effort bug in B. The final target remains done=2 and doneMinutes=55. Use this partial candidate deliberately to test whether the integrator rejects an incomplete handoff. A statement that package A is done cannot satisfy package B's requirements.

A handoff should carry the input version, changed file, supported conclusion, observed checks and unresolved limits. The parent follows source references, inspects both diffs and runs the combined candidate. candidate.test.cjs adds independent invalid-input and aggregation cases, so a hardcoded fixture total is not an adequate solution. If a later edit invalidates earlier evidence, rerun the affected check against the new state instead of forwarding the earlier pass claim.

The worktree demo actually executes the partial-handoff experiment. In a temporary repository it copies only A’s repair into a separate checkout: the composed result becomes done=2,doneMinutes=80. After B’s repair it becomes 2,55. The temporary parent stays 1,80 until a reviewed two-file patch is applied and its own candidate grader passes. This is a falsifiable evidence dependency, not only an authored expectation. The program spawns zero agents; compare these observed code states with any actual investigator/worker handoffs you choose to run.

A handoff carries evidence between stages

Investigation produces a reproduction and relevant paths; review checks that evidence; implementation changes the chosen behavior; verification checks the final integrated version. A later stage must not silently turn an unverified report into a fact.

Investigation produces a reproduction and relevant paths; review checks that evidence; implementation changes the chosen behavior; verification checks the final integrated version. A later stage must not silently turn an unverified report into a fact.

Open the full diagram

Practice and acceptance

A chain can proceed only when its dependency's evidence is available; independent package work need not wait unnecessarily.

About your environment

Checked 21 October 2026. The frozen baseline retains deliberate defects; grade the edited starter with candidate.test.cjs and the integrated runner.

Try it step by step

  1. Run the baseline and write a factual investigator handoff naming the two defects and constraints.
  2. Complete A and B against their independent frozen input contracts; do not serialize them merely because integration is a later stage.
  3. Require each implementation handoff to name changed files, actual cases and unresolved limits.
  4. Have the integrator wait for both packages, inspect their combined diff and run the real candidate.
  5. Inject an incomplete handoff by leaving B unchanged; confirm the integrated check rejects the partial result.

A useful starting example

Illustration · adapt before use.

Investigation, independent implementations, integrated verification text
Read labs/delegation-capstone/CONTRACT.md and reproduce the starter result. Return an investigator handoff identifying the missing trim and completed-only aggregation defects. Then implement A and B with disjoint file ownership. Require each handoff to name its actual checks. After both changes exist, inspect their combined diff and run node labs/delegation-capstone/run.cjs starter and node --test labs/delegation-capstone/candidate.test.cjs. Reject a candidate with only A fixed; record its remaining aggregation failure rather than calling the chain complete.
From input to result

A handoff that can be falsified

A temporary-worktree program actually runs the A-only and complete candidates.

Worked input text
node labs/delegation-capstone/worktree-demo.cjs
Expected result · compare with your run
onlyA: done=2, doneMinutes=80
fixedWorker: done=2, doneMinutes=55
parentBeforeIntegration: done=1, doneMinutes=80
integrated: done=2, doneMinutes=55
actualAgentsSpawned: 0

These are observed subprocess/Git states in disposable copies. The incomplete handoff fails the same combined check; it is not an agent transcript.

Hands-on exercise

Your turn

Complete the two starter modules in a disposable copy. Produce separate investigator, implementer and integrator handoffs. Then repeat integration with only A fixed and explain the remaining failure. Preserve the actual outputs as proof that the dependency gate catches an incomplete chain.

Try the exercise before opening its reference answer. Use a disposable practice folder.

Run the practice

Enforce the evidence handoff chain

Extract into a new practice folder and keep the included labs folder. Run these commands from that extraction root, or from the course folder, using an existing Node.js installation.

  1. Command 1 text
    node labs/delegation-capstone/run.cjs starter

    Check: Baseline exposes normalization and aggregation failures.

  2. Command 2 text
    node labs/delegation-capstone/run.cjs solution

    Check: All five integration checks pass.

  3. Command 3 text
    node --test labs/delegation-capstone/candidate.test.cjs

    Check: The unedited starter intentionally fails 4 candidate checks; all 4 should pass after both fixes.

  4. Command 4 text
    node labs/delegation-capstone/worktree-demo.cjs

    Check: Real temporary Git flow: baseline1/80, A-only2/80, worker2/55, unchanged parent1/80, integrated destination2/55; zero agents.

A chain can proceed only when its dependency's evidence is available; independent package work need not wait unnecessarily.

Check your result

  • The handoffs carry input version, owned file, actual evidence and unresolved limits.
  • Integration waits for both implementations and rejects a controlled incomplete candidate.
  • The final verification applies to the latest combined files, not an earlier worker version.
Reference answer & rubric Try the exercise before opening

The useful chain is evidence -> independent implementation packages -> integrated verification. Its handoffs carry source and result evidence rather than status alone.

  1. Record the baseline contract and failed result.
  2. Implement both modules or inspect the supplied reference solution after attempting the task.
  3. Leave B's all-task reduction in a controlled partial candidate and observe wrong doneMinutes.
  4. Accept only a combined candidate that meets normal, invalid-input and preservation requirements.
Think it through

Check your understanding

When should final verification run?

  1. At the same time as the worker, against whatever files happen to exist.
  2. After the intended changes are integrated into the files being verified.
  3. Only when every agent reports confidence.
Reveal the answer and explanation

Answer 2: After the intended changes are integrated into the files being verified.

Verification must observe the actual final state. Earlier checks cannot establish the correctness of later changes.

Take this quiz in the interactive lesson to save your answer in the browser.

When it does not work

The integrator starts while B is incomplete.

Likely cause: A completion dependency was omitted or ignored.

What to try: Wait for both file changes and handoffs; a partial integrated run is diagnostic, not accepted delivery.

An investigator says 'normalization bug' without source details.

Likely cause: The next worker must rediscover the evidence.

What to try: Include the function, input example, expected value and relevant line in the handoff.

Common mistakes

  • Running investigation, implementation and final verification concurrently as if they had independent inputs.
  • Treating a worker's reported pass as evidence that a later edited version still passes.
Source mapping & differences · equivalent

Sequential delegation transfers to Codex, but the parent must route results and enforce dependencies through an explicit task contract.

Source topic: Chaining subagents ↗

Go to the source

Official documentation, checked 21 October 2026. Product names, controls and availability may vary with your version, platform or account.

Continue in the interactive lesson →

Completion and quiz progress are saved
only in the interactive course.