Structure work so agents can complete it reliably

Once an agent can find the right context, the next risk is losing the thread halfway through the work.

Break long work into stages

Eight bounded delivery stages hand evidence forward to a delivery report.
Figure 7. Eight bounded stages, each leaving an artifact.

Long runs often fail quietly. The agent forgets an earlier decision, skips verification, changes direction halfway through, or stops as soon as code exists even though the task is still incomplete. There may be no crash and no obvious error, just a confident final message attached to unfinished work.

Consider a feature that touches an API client, domain logic, a shared component, navigation, tests, and device behavior. A single open-ended instruction asks the agent to make assumptions across all six areas at once. A staged workflow brings those assumptions into view before they spread through the diff.

A substantial delivery workflow might look like this:

  1. Inspect the relevant code, documentation, and constraints.
  2. Write a plan with identified unknowns.
  3. Define or confirm interfaces.
  4. Implement within a bounded scope.
  5. Run focused checks.
  6. Inspect the application when behavior depends on the runtime.
  7. Review the complete diff.
  8. Prepare the result for acceptance under the approved policy.

Each stage should leave something the next stage can inspect: a plan, a list of affected files, a test report, a patch, a device recording, or a failure summary.

One practical option is a file such as .ai/runs/<ticket>.md on the working branch. It can record the scope, plan, decisions, changed files, checks, blockers, and next action. Every worker reads it before starting and appends its result before handing off. Before removing temporary coordination files from the product diff, preserve the delivery record in the issue, pull request, or durable artifact storage. Keep decisions, evidence, reviewed revisions, blockers, and the next action available for recovery and retrospectives.

A small file like this solves a surprisingly large problem. The state of the task no longer lives only in a conversation window, and a partial run becomes much easier to resume.

Specify the task before orchestrating it

Resolve product decisions before implementation spreads assumptions across several workers. Start with a short interview: one question at a time, with a recommended answer. Matt Pocock's grill-me skill is one way to structure it.

Spec areaRecord before implementation
Outcome and scopeProblem, intended outcome, scope, non-goals, and observable acceptance criteria
Source factsSource locations at a named revision or recorded command output; unsupported facts remain open questions
Interfaces and stateInterfaces, shared values, and existing code that reads or writes the same state
Failure and recoveryFailure outcomes, bounded waits, concurrent operations, and what survives a restart
VerificationTests, device checks, and required hardware for the acceptance criteria

Turn the requirements into a plan recording decisions, affected boundaries, dependencies, and verification. Its purpose is to give every worker the same contract, regardless of which model it uses.

Check the spec from a fresh context

Give a checker the written spec, binding repository rules, relevant ADRs, and read-only source access. Leave the interview conversation behind.

Have it dry-run implementation by naming the code and tests needed for each acceptance criterion. Then imagine the feature has failed and identify likely causes. Finally, require a status for each relevant category: contradictions, unsupported facts, undefined terms, untested behavior, failure modes, shared-state interactions, cross-task overlap, and device requirements.

Resolve blocking gaps, then have a person approve the spec and plan. Record that approval explicitly, for example with a ready state in the issue tracker. Agents may resolve minor gaps only within an approved decision scope; consequential ambiguity parks the work with a clear handoff.

Orchestrate the workflow

The orchestrator owns the order of the stages. It tracks progress, checks the artifacts, resolves decisions that cross boundaries, and decides whether the workflow may continue.

For a substantial factory, keep the orchestrator focused on coordination. It delegates implementation, review, and verification, then reads short reports naming the stage, revision, outcome, evidence, blockers, and next action. It does not write the code it accepts. Validate report structure where possible; a valid report still needs supporting evidence.

Code review belongs in that sequence as an independent stage with its own workers, inputs, and output. Section 6 describes how to brief review agents, separate them from the implementation context, and combine their findings.

Use custom agents and sub-agents deliberately

Questions for keeping one agent or dividing work among workers.
Figure 8. Keep one agent unless the work is substantial and separable.

Custom agents and sub-agents work best in bounded roles: repository exploration, implementation, testing, or review. Role-specific instructions give each worker the context it needs without loading every repository rule into every task. Coordination and final verification stay with the orchestrator.

Fresh context still needs task truth. Give a reviewer or verifier the product requirements, acceptance criteria, relevant repository rules, and the artifact it must inspect. Leave the implementation agent's conversation out unless a detail is required to reproduce the environment. The worker can then judge the result without inheriting the author's explanations for why it should be correct. Sections 6 and 7 apply this pattern to code review and device verification.

Delegation has a price. Treat a sub-agent as a fresh worker: the orchestrator must transfer the task, constraints, relevant context, and acceptance criteria, then verify the result on return. For a small, well-understood change, writing that briefing can consume more tokens and lose more fidelity than doing the edit in the agent that already has the context.

Keep one agent on the taskDivide the work
Small changeSubstantial change
Parts depend closely on one anotherParts have clear boundaries
One agent already has the contextA focused handoff saves time

For example, keep one agent on a narrow form-validation bug when investigation, implementation, and tests all touch the same feature module. Use an orchestrator for a cross-platform change that can be split into independent iOS and Android investigations, followed by implementation and device verification against a shared plan. Give each worker a clear scope, context, allowed actions, output, and stop condition. Delegate when the time saved by independent work or focused verification exceeds the briefing, coordination, and integration cost; keep small or tightly coupled tasks where the context already lives.

A skill packages a reusable workflow; a fresh worker provides context isolation and role-specific tools. Check how the harness executes each: loading a skill does not by itself create an independent reviewer.

Route models by role and verification cost

Model categories matched to repository tasks, specialist tasks, and ambiguous work.
Figure 9. Route each role to the cheapest model that can verify its output.

Model choice follows the same logic. Match the model to the role, ambiguity, and verification cost:

  • Use capable lower-cost models for bounded repository search, documentation retrieval, file discovery, and other tasks with clear outputs.
  • Use frontier-level models for ambiguous design decisions, complex implementation, debugging, and final synthesis.

Defining a model for each role yourself may be easier to configure and evaluate. Where the harness supports it and the orchestrator can reliably assess the task, you may let it choose models automatically. Define the permitted models and escalation rules, and record each choice so you can evaluate the results and cost.

A specialized model may change that calculation. Apex is Callstack’s coding model for React Native. Evaluate it on representative tasks from your repository and compare verified success rate, time to a verified result, and total cost against the models you already use. Treat any performance or cost comparison as specific to the models, task set, evaluation date, success criteria, and cost measure reported; don’t generalize it without those details.

Test this routing on real tasks. Measure success rate, token usage, and total cost together. A cheaper model that fails and retries can cost more than a frontier model that succeeds once.

React Native Evals provides a starting point. The open benchmark runs models against real-world React Native tasks across navigation, animation, async state, lists, and platform APIs. It reports success rate, token usage, and cost across repeated runs. Use it as a reference while building an evaluation suite around your own codebase.

Set the limits before execution begins. Define the maximum number of fix attempts, the directories that may change, the permitted patch size, and the failures that require a person. When a check remains red after the retry budget is gone, the agent should preserve the evidence and report the blocker.

Run agents in parallel deliberately

Three parallel worktree runs share one leased device lane.
Figure 10. Each run owns a worktree; device runs queue behind one lease.

Parallel work adds a new class of failure: two individually reasonable runs can interfere with each other.

Give each run an isolated workspace such as a separate branch, worktree, or container. Record its declared scope in the progress artifact, and partition the work so two runs do not modify the same packages. When overlap is unavoidable, decide the order in advance.

Shared resources need the same discipline. Require each run to rebase against the integration branch before review. Treat merge conflicts as a decision for the orchestrator or a person, not for the agent that produced one side of the conflict.

Reserve devices, test accounts, and seeded environments per run, or serialize the stages that need them. One agent changing shared state can quietly invalidate another agent's evidence.

An instruction to "use simulator A" breaks down when several workers can claim it at the same time. Back the reservation with shared state: each run requests a lease, records its owner, and releases it when the device stage ends.

A device-leasing service such as Simlock can hand out an iOS simulator or Android emulator that is already booted, health-checked, and unused by another run. Further requests can provision another device or wait in a fair queue when the machine reaches capacity. The lease remains advisory when device commands can bypass it. Stronger setups require the lease at the device-command boundary.

Use a dedicated device lane: one verification worker owns the lease, installed build, automation session, and evidence for that run. Builders request verification rather than taking over shared devices. Serialize work when the host cannot safely support parallel device runs.

For example, an orchestrator might give one worker a fixed budget to inspect the iOS flow, another the same budget to inspect Android, and a third a separate implementation budget after reviewing both reports. Cap each worker and the total run, and stop or ask for human input when the shared limit is reached. Cost compounds: several reasonable runs can still produce an unreasonable bill.

Parallelism pays off for work that is both substantial and separable. Scope partitioning makes cross-cutting refactors harder, and two tiny tasks can spend more on two briefings than one agent would spend completing both.

Serial and parallel workflows need the same final contract. Use the pull request description as the delivery report. Record what changed, important assumptions and decisions, checks that passed, failed, or were skipped, obstacles encountered, knowledge or requirement gaps, and anything that still needs human verification.

When the same obstacle appears across several reports, the problem has moved beyond one task. The repository guidance, the requirements, or the workflow itself needs attention.

To do:

Break substantial work into bounded stages, leave evidence between them, and delegate only when the task can repay the handoff.