The tool names, contracts, and limits below are a proposed design for this guide, not a description of a particular product’s internals.
Edit: change the workspace, then confirm the write
Give the agent an edit tool such asapply_patch. A patch describes a small change (“replace these lines with those lines”). The tool applies it and reports the outcome.
- Prefer a targeted patch over whole-file replacement. To fix one line, patch one line. With whole-file replacement, the model must reproduce every unrelated line exactly, and one slip breaks working code. New files can use a separate
write_filetool or the same patch tool. - Reject stale edits. When the agent reads a file, the harness records its version (for example, a content hash). Before applying a patch, it checks that the file still matches. If the user edited
session.tsin the meantime, the patch is stale: it would overwrite their work. The harness rejects it with a recoverable error, and the agent rereads the file and builds a fresh patch. - Report partial application. The result says which files changed and whether the whole patch applied or only some of it. Alternatively, apply each patch atomically: all of it or none. If an edit failed or only partly applied, the agent must not continue as if it succeeded.
- Review the diff. The agent inspects the before-and-after diff for unintended changes, and confirms the user’s unrelated edits are still in place.
Run: choose a check that can detect the problem
Use a command tool to execute the project’s actual verification commands. Inspect its scripts or contributor instructions rather than guessing commands from the language alone. Each kind of check proves something different:
Start with a check close to the change, then run broader checks required by the repository or justified by the affected area. A documentation edit and a shared authentication change need different verification depth.
The command tool contract
A proposed command interface should accept a working directory and timeout, return bounded stdout and stderr, and distinguish completion from a still-running process. If execution continues asynchronously, return a process handle so the agent can poll or cancel it. Keep larger logs retrievable without inserting all of them into model context.Observe: turn results into the next decision
The harness returns structured facts; the model interprets them. An illustrative completed result might look like:Continue learning
Editing & execution
Return to the loop and the worked example.
Context rot
Continue the core walkthrough with topic 3.