Skip to main content
Editing & execution introduced the Read → Edit → Run → Observe loop. This page covers how the edit and command tools should behave, and how the agent should read their results.
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 as apply_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_file tool 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.ts in 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:
A nonzero exit code alone does not identify the cause. Read the failure details and distinguish a wrong implementation from a missing dependency, incorrect command, timeout, or unrelated existing failure. Likewise, exit code zero may mean no tests were discovered; inspect the runner’s summary before calling verification successful.
Design decision: Edits report exactly what applied, commands return bounded and structured results, and the agent chooses its next step from that evidence.

Continue learning

Editing & execution

Return to the loop and the worked example.

Context rot

Continue the core walkthrough with topic 3.