Sub topic 5
Breaking a coding task into delegable units
This chapter assumes you know what a subagent is and that it starts with a fresh context. You should also be comfortable with Git branches and with reading a test run. Here you learn how to split a large coding task into pieces you can hand to subagents.
What makes a unit delegable
A unit is delegable when a subagent can finish it using only a written brief, without asking the parent questions. Check each candidate unit against four properties:
- Self-contained: The needed context fits in a short brief and a few files.
- Bounded: It touches a known set of files or one module.
- Checkable: A command or observable result shows it is done, such as a passing test or a successful build.
- Small enough to review: You can read the result in a few minutes.
If a unit fails one of these, split it further or keep it with the orchestrator.
A decomposition procedure
- State the end goal in one sentence.
- List the changes needed, by file or module.
- Mark dependencies. Ask of each change: does it need the output of another change?
- Group changes that touch the same files into one unit, so two subagents never edit the same file.
- Give each unit a finish condition.
Suppose the goal is "add a --verbose flag to the CLI." The changes are:
| Unit | Files | Depends on | Finish condition |
|---|---|---|---|
| Add the flag to `parse_args` | `src/cli.py` | none | `parse_args(["--verbose"]).verbose` is `True` |
| Unit tests for `parse_args` | `tests/test_cli.py` | flag exists | `pytest tests/test_cli.py` passes |
| Update README usage | `README.md` | flag name only | README documents `--verbose` |
The README unit needs only the flag name, which you already know. It does not need the finished code, so it can start immediately. The tests need the flag to exist, so they wait.
The diagram shows the shape that comes out of this process. Independent branches can run at the same time. A dependent unit waits for its predecessor. Chapter-level details on running them live in the parallel and sequential execution chapter.
Common decomposition mistakes
- Splitting by layer instead of by outcome. "One agent writes all the code, another writes all the tests" often forces them to agree on interfaces neither has seen. Prefer vertical slices that each produce a working result.
- Overlapping file ownership. Two units editing
src/cli.pycause merge conflicts or silent overwrites. Merge them into one unit or run them in sequence. - Hidden dependencies. A unit that quietly needs a renamed function from another unit will fail or invent its own version. Write shared names into both briefs, or sequence the units.
- Units too tiny. A brief costs tokens to write and a subagent costs time to start. Delegating a one-line change usually costs more than doing it.
- No finish condition. Without one, you cannot tell success from a plausible-looking summary.
Keep the integration step
Some work should stay with the orchestrator: choosing the interface, resolving conflicts, and the final check across all units. Treat these as units too, assigned to yourself.
Exercise
You plan to delegate "add a --output option" as three units: (1) add the option in src/cli.py, (2) add tests in tests/test_cli.py, (3) document it in README.md plus a fix to a helper in src/cli.py. Which problem will you hit, and how do you fix it?
Show answer
Units 1 and 3 both edit src/cli.py, so parallel subagents could conflict. Move the helper fix into unit 1, so each file has one owner. Unit 3 then covers only README.md. Unit 2 still waits for unit 1, unless the option name is fixed in its brief so it can be written against that name.