Delegate Agent Work with Isolation and Merge Contracts
Parallel agents save wall time only when the work is independent. Otherwise they convert one clear task into a coordination problem with a faster failure rate.
Lesson 45 of 54Learn + Build~70 minutesPython (stdlib)
Before this: Lessons 39 and 44 of Phase 14
On this page
Learning Objectives
- Decide whether delegation is justified by real independence.
- Give each worker exclusive file ownership and explicit proof.
- Compute execution waves from dependencies.
- Design a merge contract for combining agent work safely.
The Parallelism Test
Do not delegate because more agents are available. Delegate when at least one of these is true:
- two investigations can answer different unknowns independently;
- two implementations own disjoint files and contracts;
- a reviewer can inspect a completed artifact without changing it;
- a slow external check can run while local work continues.
Keep work serial when agents need the same files, the same unresolved decision, or the same mutable environment.
A Work Unit Is a Contract
Each delegated unit needs:
| Field | Meaning |
|---|---|
| Goal | One observable result |
| Owner | One accountable worker |
| Paths | Exclusive write ownership |
| Dependencies | Completed units required before starting |
| Proof | Exact evidence returned to the integrator |
| Handoff | Files changed, decisions made, remaining risk |
“Handle the backend” is not a work unit. “Implement the duplicate check in app/accounts.py and prove it with the focused account test” is.
Isolation Has Three Layers
- Filesystem isolation: separate worktrees or sandboxes prevent accidental shared edits.
- Ownership isolation: contracts prevent two workers from intentionally editing the same path.
- State isolation: separate logs and outputs prevent one worker from overwriting another worker’s evidence.
Filesystem isolation does not solve ownership. Two clean worktrees can still produce conflicting designs. The merge contract must resolve shared interfaces before work begins.
The Integrator Does Not Rebuild the Work
The integrator should:
- confirm each handoff matches its assigned scope;
- read the proof output, not just the worker’s summary;
- combine changes in dependency order;
- run the full cross-unit gate;
- reject hidden scope expansion;
- record conflicts as new decisions, not silent edits.
If integration requires rewriting most of a worker’s result, the original decomposition was wrong.
Human and Agent Roles
Delegation does not remove human judgment. The human still owns choices that change public behavior, risk, authority, or irreversible cost. Agents can own bounded investigation, implementation, verification, and review.
This is calibrated autonomy: the system grants freedom where evidence and rollback are strong, and requires a checkpoint where consequence is high.
Build It
The lab checks path overlap, validates dependencies, computes safe execution waves, and writes outputs/delegation-plan.json.
Run:
python3 code/main.py
python3 -m unittest discover code/tests -v
Change the docs unit to own app/. The plan should block because that parent path overlaps the API unit.
Exercises
- Decompose a real change into two independent work units and one integrator.
- Find a proposed parallel split that only looks independent. State the shared decision.
- Add a read-only research worker whose output is a fact table.
- Add a merge gate that checks the final changed-file set against all unit contracts.
- Define a cancellation rule for a worker whose dependency becomes invalid.
Further Reading
- Reid Smith, The Contract Net Protocol, for an early formal treatment of distributed task allocation and result reporting.
- Eric Horvitz, Principles of Mixed-Initiative User Interfaces, for deciding when automation should act and when it should return control to a person.
What You Keep
Keep outputs/delegation-plan.json. It records why the split is safe, who owns each path, and what proof integration must receive.
Check yourself
Quick quiz
When is parallel delegation justified?
- When work has real independence in decisions, paths, or waiting time
- For every task over ten minutes
- Whenever more agents are available
- Only for documentation
Show the answer
A. When work has real independence in decisions, paths, or waiting time Parallelism helps only when units can progress without shared mutable decisions or ownership.
Which guarantee does filesystem isolation not provide?
- Exclusive design and path ownership
- Independent command execution
- Recoverable branches
- Separate directories
Show the answer
A. Exclusive design and path ownership Two isolated worktrees can still implement conflicting designs.
Why must each work unit name proof?
- To avoid a handoff
- To increase concurrency
- So the integrator receives reproducible evidence
- So the worker can claim success
Show the answer
C. So the integrator receives reproducible evidence The integrator must verify results, not trust summaries.
What should happen when two units own overlapping paths?
- Let the last worker win
- Merge without review
- Run them faster
- Block and redesign the split
Show the answer
D. Block and redesign the split Overlapping write ownership creates avoidable conflict and ambiguity.
What is calibrated autonomy?
- Manual work only
- Freedom where evidence and rollback are strong, checkpoints where consequence is high
- Full automation
- Random approvals
Show the answer
B. Freedom where evidence and rollback are strong, checkpoints where consequence is high Authority should follow consequence and reversibility.
What is the integrator's final responsibility?
- Delete handoffs
- Choose a larger model
- Rewrite every unit
- Run the full cross-unit verification gate and enforce scope
Show the answer
D. Run the full cross-unit verification gate and enforce scope Unit proof does not replace end-to-end integration evidence.
Questions people ask
When does it make sense to run AI agents in parallel?
When tasks do not share files, decisions or environments, such as researching two separate questions or building two unrelated parts. If they need the same files or wait on the same decision, run them one after another.
How do you merge work from multiple AI agents?
Give each agent exclusive ownership of certain files, a defined goal and required proof. Combine results in an order based on dependencies, and run tests after each merge to catch conflicts early.
Lessons from AI Engineering from Scratch by Rohit Ghumare and contributors, MIT license. Notes for owners by Lozo. License