Sub topic 10
Implement one step at a time
This chapter assumes you have an approved plan from the earlier chapters. You should be comfortable with git commits and diffs, and you should be able to run your project's test suite. The goal here is to turn an approved plan into code in small pieces, so you can check each piece before the next one starts.
Why one step at a time
An approved plan lowers the risk of building the wrong thing. It does not remove the risk of a bad implementation. If you tell the agent to "implement the plan" in one go, you get one large diff. A large diff is hard to review. When a test fails, you cannot tell which part caused it. When one decision in step 2 was wrong, steps 3 to 6 are built on top of it.
Working one step at a time gives you three things:
- Small diffs. You can read every changed line in a few minutes.
- Early failure detection. A mistake shows up in the step that caused it.
- Cheap reversal. Undoing one step is a single
git revertorgit checkout, not a hunt through a large change.
The cost is more round trips. Each stop needs your attention. You can decide how much control to keep, and the rest of this chapter covers how to adjust it.
The step loop
Each step follows the same cycle: implement, show, verify, decide.
The loop has a built-in stop. The agent does not move to step N+1 until you say so. That stop is what keeps you in control of the work.
Write the step instruction
The approval message from the previous chapter should already limit the agent to one step. A good step instruction has four parts:
- An explicit approval.
- The scope: which step, and only that step.
- What to show you afterward.
- A stop condition.
Approved. Implement step 1 only, then stop and show me the diff and the test results before moving to step 2.This message names the step number, so the agent can look up the matching step in the plan. It asks for the diff and test results, which are the two things you need to review. It ends with a clear stop.
Compare it with a loose instruction such as "Go ahead." The agent has to guess how much to do. Many agents will do the whole plan, because that seems to be what you want.
Refer to the plan by step number
Steps work best when the plan numbers them. In the rate-limiting example from earlier, the plan had three steps: add the limiter module, call it from the login route, and add tests. You can then say "step 2" and both of you know what it means. If your plan used bullets instead of numbers, ask the agent to number them before you start.
Keep the plan in the conversation
The agent works from the plan as it exists in the conversation. If you revised the plan, make sure the latest version is the one in view. Say so when it matters: "Implement step 2 of the revised plan, the one that uses the shared Redis client." Without that, the agent may mix details from an older version.
Review each step
When the agent stops, review the diff before you read anything else it says. The agent's summary describes what it intended to do. The diff shows what it did.
Use a short set of checks:
- Does the diff only touch files named for this step in the plan?
- Is any change there that the step did not call for, such as a renamed variable, a reformatted file, or an extra helper?
- Do the tests pass, and did the agent run them or only say they would pass?
- Does the code follow the assumptions you approved, for example "use the existing config file"?
You can look at the work yourself with git:
git status
git diffgit status lists the files that changed, including new ones that git diff does not show. Compare that list with the files named in the plan. A file that is not in the plan needs an explanation.
Run the tests yourself
Do not rely only on the agent's report of test results. Run the tests yourself, at least on the first step, so you know the agent is running the right command in the right environment. For the Python example from this tutorial:
python -m pytest tests/test_login_limit.py -v
python -m pytest tests/ -qThe first command runs the new tests. The second runs the whole suite, which catches breakage in code the step should not have affected.
Commit after each good step
Once a step passes your review, commit it. Each commit becomes a checkpoint you can return to.
git add auth/limiter.py
git commit -m "Add in-memory limiter module (step 1 of login rate limit)"Name the step in the message. When you read the history later, the commits line up with the plan.
You can ask the agent to make the commit, but many people prefer to commit themselves. Committing is your sign-off, and it keeps a clear line between "the agent proposed this" and "I accepted this." Whichever you choose, state it in the instruction so the agent does not commit when you did not expect it.
When a step goes wrong
Steps fail in a few typical ways. Each needs a different response.
| Symptom | Likely cause | Response |
|---|---|---|
| Diff touches files not in the plan | Agent widened the scope | Ask why. Revert the extra files, or update the plan if the change is needed. |
| Tests fail in this step | Bug in the step | Ask the agent to fix it within the same step. |
| Tests fail in unrelated code | The step broke something the plan did not expect | Stop. Decide whether to revert and revise the plan. |
| Code works but differs from the plan | Agent chose another approach | Accept it and update the plan, or ask for the planned approach. |
| The step cannot be done as written | The plan had a wrong assumption | Go back to plan revision. Do not let the agent improvise. |
The last row matters most. If the agent finds that a plan assumption is false, for example the client IP is not available on the request object, the right move is to return to the plan. Ask the agent to stop and describe what it found, then revise the plan together. A silent workaround means the final code no longer matches the plan you approved, and your later review has nothing solid to compare against.
Give feedback inside the step
When a step is close but not right, correct it before you commit. Be specific about what is wrong and keep the scope to the current step:
Step 2 is almost right. Two changes before I accept it:
- The limiter is called after the credentials check. The plan says before. Move the call.
- Remove the new `logging` import. It is not used.
Make only those changes, run the auth tests, and show me the diff again.The final line repeats the stop condition. Agents tend to treat a correction as permission to continue, so restate the limit each time.
Adjust the step size
"One step" is a default, not a rule. Choose the size by the risk of the change.
- Smaller than a plan step. If a step touches many files or changes behavior that is hard to test, split it. Ask the agent to do the first half and stop.
- Larger than a plan step. For low-risk, mechanical steps, such as adding tests for behavior you already reviewed, you can approve two steps together: "Implement steps 3 and 4, then stop."
- Edit and review in batches. Once the first steps have gone well and you trust the agent's reading of the plan, you can widen the batch. If a batch goes badly, go back to one step at a time.
A useful rule is to size the step so that you can review its diff in one sitting and revert it without regret.
Keep the agent from drifting
Over a long session, the agent can lose track of the constraints in the plan. Two habits help:
- Restate constraints on risky steps. For example, "Remember: no new dependencies."
- Ask for a plan check. Before the last step, ask: "List which plan steps are done, which remain, and any place where the code differs from the plan." This gives you a status report to compare against your own review.
If the session grows very long or you start a new one, give the agent the plan again, ideally as a file. A later chapter covers keeping the plan as a document for this purpose.
A worked sequence
This is how the rate-limiting plan would run, using the three steps from earlier.
- You send the step 1 message. The agent creates
auth/limiter.pyand shows the diff. You check that it only added that file, run the tests, and commit. - You send: "Step 1 is committed. Implement step 2 only, then stop and show me the diff and the test results." The agent edits
auth/routes.py. You notice the existing error format is intact, as the constraints required. You commit. - You ask for step 3. The agent adds
tests/test_login_limit.py. You run the whole suite, confirm it passes, and commit. - You ask for a plan check, then compare the final diff against the plan, which the next chapter covers.
Each message is short. The control comes from the stop, not from long instructions.
Summary
Implement an approved plan in small steps, with a stop after each one. Name the step, ask to see the diff and test results, and review the diff before the agent's summary. Run the tests yourself, commit each accepted step, and send assumption failures back to plan revision instead of letting the agent improvise. Adjust the step size to the risk.
Exercise
The agent finishes step 2 of a plan and reports "all tests pass." Its diff includes a change to a file that the plan does not list. What should you do before committing, and why?
Show answer
Check the extra file's change in the diff and ask the agent why it was needed. Run the tests yourself instead of trusting the report. If the change is not needed, revert it. If it is needed, update the plan to match so the final review still has an accurate reference. Do not commit until the diff and the plan agree, because an unlisted change is the kind of scope drift that the plan was meant to prevent.
Exercise
Write a message that approves step 3 of a plan, limits the agent to that step, and states what it must show you afterward.
Show answer
"Step 2 is committed. Implement step 3 only. Then stop and show me the diff and the test results. Do not start step 4."