How an agent uses tools and feedback
An agent is a system in which a model can choose actions as work proceeds. A coding agent might read a file, run a test and use the result to choose an edit. The tool executes outside the model. The surrounding application, sometimes called a runner or harness, validates the request, performs the operation and returns its result to the model.
For example, asking a tool to read csv.js is a proposed action. The returned file contents supply the observation the next step can use. Asking to run a test supplies no result until the command executes and returns output. This distinction explains why a completion message needs actual test evidence.
A fixed workflow specifies the steps in advance. Converting a supplied table into a fixed report may need only one model request and a format check. An agent loop is useful when the next step depends on what the previous tool discovers. A test failure might lead to a different file, another input or a revised diagnosis. Each additional action costs time, so choose a process that matches the uncertainty in the work.
Follow a missing-row repair end to end
Suppose a small importer loses its final record when the file has no newline at the end. CSV is a format that separates fields with commas and records with newlines. Real CSV also supports quoting and other rules. To make this bug easy to trace, our fictional importer accepts only nonempty, unquoted rows with a comma between fields. The example below is a teaching parser for that restricted format.
A regression test preserves a defect as an input with an expected result, so a later change can check whether the defect returns. An assertion is a check inside a test, such as requiring the returned rows to equal the expected rows. An assertion reports a failure when the values disagree.
Fix the missing-final-row bug in csv.js locally.
Reproduce input "A,1\nB,2" in csv.test.js.
It must return two rows. Preserve the existing behavior
when the input ends with a newline.
Keep this patch limited to the parser and its tests.
Run the regression and existing importer tests.
Return the diff and actual test results; do not publish.In the prompt, \n represents a newline inside a text string. The expected output is two rows, each containing two text fields. JavaScript represents those rows with arrays, ordered lists of values. The agent first reads the implementation and the test file. Imagine that the relevant implementation is:
export function parseRows(text) {
const lines = text.split("\n");
lines.pop();
return lines.map(line => line.split(","));
}In JavaScript, split separates a string at each matching delimiter, and pop removes the final array item. If the text ends in a newline, splitting produces an empty final item. The unconditional pop removes that item. Without a final newline, the last item is “B,2,” so the same pop removes a real record. This gives a specific explanation to test.
Input text: A,1\nB,2
Expected rows: [["A","1"],["B","2"]]
Original rows: [["A","1"]]The agent adds or runs the missing-newline test before editing. A failure with the original rows above reproduces the report and connects it to this implementation.
The smallest repair keeps the removal conditional on an empty final item. It preserves the final record when the input has no trailing newline:
export function parseRows(text) {
const lines = text.split("\n");
if (lines[lines.length - 1] === "") {
lines.pop();
}
return lines.map(line => line.split(","));
}Run both forms of the input. They should now produce the same two rows. This check tests the reported defect and the behavior the patch must preserve:
import { expect, test } from "bun:test";
import { parseRows } from "./csv.js";
test("keeps the final record with either newline form", () => {
const expected = [["A", "1"], ["B", "2"]];
expect(parseRows("A,1\nB,2")).toEqual(expected);
expect(parseRows("A,1\nB,2\n")).toEqual(expected);
});Bun is the JavaScript runtime and test runner used by this example. Saving the two files as csv.js and csv.test.js lets a reader with Bun installed run bun test csv.test.js. The expected outcome after the repair is that both assertions succeed; an actual agent must retain the output from its own run. For a real CSV importer, keep the existing parser and its format tests instead of replacing a maintained CSV library with this simplified split implementation.
Choose the next action from the observed failure
If the same regression still loses the last row after an edit, the proposed repair has not established success. Inspect which function the test imported and trace its changed branch on the failing input. An edit in an unused helper can look correct while leaving the called function unchanged. Another speculative rewrite would add uncertainty before resolving that observation.
If the runner instead reports “Cannot find module ./csv.js,” the assertions never ran. Check the file path and import before changing parsing logic. A tool error about setup and a test assertion about behavior require different next actions. Read enough of the output to distinguish them.
Keep retries bounded by a diagnosis. After repeated failures under the same hypothesis, compare the expected and actual values and reassess the assumption. More workers or broader permission cannot correct a misunderstanding of the input. Independent tasks can run in parallel when their outputs combine cleanly, such as inspecting format documentation while one worker reproduces a defect. Give one writer ownership of the parser.
Hand off the patch and its evidence
A diff shows how files changed. Review it after the tests so that an unrelated edit or removed check does not hide behind a successful command. The request above ends with a local patch. Publishing that patch changes another resource and requires authority for that action.
Changed csv.js to remove only an empty final split item.
Added the missing-newline case in csv.test.js.
Checked: bun test csv.test.js
Result: the two-row assertions succeed with and without a final newline.
Existing importer suite: report its actual command and result here.
Publication: none; the request was a local patch.The existing suite line must contain the real outcome in a finished handoff. If it could not run, record the exact command, error and unchecked behavior. Avoid turning an expected example outcome into a claimed execution result.
For a document-summary task, the same loop uses different evidence: read the current document, draft from its passages and check each claim against them. A file-not-found result calls for source recovery. A request for a draft ends with the draft, even when a sending tool is available. The lab’s checkpoints ask you to apply these choices to observed states; they do not run tools or edit files.
Try the skill
Fixed local fixture. No model or external tool is called.