Egor Urvanov

Harness engineering in practiceTurning AI agent mistakes into rules of its environment (HDD)

Harness engineering is the work of shaping the environment around an AI agent: instructions, connected systems, permissions and checks. Harness-Driven Development (HDD) is a working method built on it: every agent mistake becomes a rule of that environment. You start with an AGENTS.md or CLAUDE.md instructions file and a log of agent mistakes: once a week, log entries move into rules, tests or hooks.

The HDD loop

The loop works like this. The agent gets a task and produces a result. Sensors (a test, a linter, a review) check the result. If everything passes, the task is closed. If a sensor finds a mistake, a person changes the agent’s environment, the harness: adds a line to the instructions, a test or a hook. The next task runs with that rule, and the mistake does not repeat.

Task → agent → result → sensors → mistake → rule in the harness → next taskharnessTaskAgentResultSensorsNew ruleinstruction · test · hookproducescheckpassedmistakewon't happen again

Mitchell Hashimoto's principle: when the agent makes a mistake, change the harness so that mistake can't happen again Faros

A prompt fixes one request, context fixes what the model knows, the harness fixes every following run. Example: the agent edits code and does not run the tests.

ONE MISTAKE · the agent edits code and does not run the testsWHAT CHANGESHOW TO FIX ITWHERE THE FIX LIVESAGENT RUN1234① Promptthe request wordingAdd to the request:“run the tests after the edit”Only in this request:the next request starts from scratch✓✗✗✗② Contextwhat the model knowsWrite into the project instructions:“run the tests after each edit”In the instructions file: the model reads it,but is not forced to follow it✓✓~✓③ Harnessthe agent’s environmentAdd a hook: the tests run on their ownafter every editIn the environment: runs without the modeland blocks the result if it fails✓✓✓✓✓ tests run · ~ the model may skip it · ✗ forgotten

Stages as described by Faros and marmelab

The table shows one mistake (the agent edits code and does not run the tests) and three ways to fix it. Prompt: add “run the tests after the edit”. That works for one request only, and the next one starts from scratch. Context: write the same into the project instructions file. The model reads it but may skip it. Harness: add a hook that runs the tests itself after every edit. It runs without the model, so the fix holds in all following runs.

Takeaway
In this exampleA mistake caught by the sensors goes into the harness as a new rule, and the agent gets that rule on every following run.
In generalA result fixed by hand helps once. A rule in the harness (an instruction, a test or a hook) applies to all future tasks, so the harness gets more precise over time without changing the model.
Next stepAdopt a rule: any agent mistake you had to fix by hand becomes a line in the instructions or a test on the same day.

How a harness is laid out: 3 × 3

Three domains of the loop and three contexts in each — nine canons. Every canon has exactly one domain and one context.

→skill → spec of its domain·a commit hook script checks the direction
snapshota table, updated after each new measurement
livea protocol, fresh every time, nothing stored

The matrix reads as three questions. Expectation: what the result should be (for example, “after the edit the tests pass”). Observation: what it actually turned out to be, which a sensor records. Loop: compares the two and decides what to do. Each of the three rows has three kinds of support: spec (what must be true), skill (how to act) and memory (what to lean on). The words “domain” and “canon” are just names here: a domain is a row of the matrix, a canon is one cell, for example the Expectation spec. The diagram below shows the direction of links: Expectation and Observation feed the Loop, and it yields either a patch (fix the action) or a revision of the rules. There is no link back to the Loop, so the domains do not tangle into each other. The memory modes: snapshot is a table updated when a new measurement arrives; live means the data is taken from the live system (for example through MCP) each time and is not stored.

Takeaway
In this exampleThe loop splits into Expectation, Observation and Loop, each with its own spec, skill and memory. Loop reads the other two domains; they never read Loop.
In generalIt is a negative feedback loop: the target value is compared with the measured one, and something changes only on a mismatch. A strict reference direction keeps the domains from tangling, and the same concept repeating in two domains is not a defect.
Next stepSort the files of your harness into the nine cells and check that no Expectation or Observation file refers to Loop.

The double loop

The double loop answers the question of what exactly to change after a mistake. Take the same mistake: the agent did not run the tests. In a single loop you remind the agent, it runs the tests, and the rules stay as they were. In a double loop you ask which rule allowed the mistake and change it: now a hook runs the tests after every edit. The idea comes from the theory of organizational learning (Chris Argyris and Donald Schön): a single loop corrects the action, a double loop revises the rules the action followed from. Wikipedia: Double-loop learning.

single loopfix the action under the same rules
double loopchange the rules themselves
Patches without a new predictionfix it with a rule
Several complaintsfirst test for a shared cause
A new ruleaccepted only if old cases follow from it
No external checkdiscard it, with a record

The loop applies to itself: every run ends with the residual risk, never with a “done” status.

Changing the rules after every complaint is risky: the harness starts to sprawl from chance edits. So the Loop applies four checks. If the fixes only plug holes and predict nothing new, they are replaced by one rule. If there are several complaints, first test whether they share a cause. A new rule is accepted only if the old cases are still explained with it. A rule without an outside check is dropped, but the record says what was dropped and why. The caption under the cards means the Loop applies to itself too: a run ends with a statement of the residual risk.

Takeaway
In this exampleA series of patches, complaints, a new rule and an external check are four checkable principles the Loop uses to decide whether to fix the action or change the rules.
In generalA single loop fixes the result within the old rules. A double loop changes the rules themselves, and does it by checkable principles, so the harness learns without drifting from random edits.
Next stepWhen the same fix comes up a third time, stop and ask which rule causes it. Change the rule only if it also explains the old cases.

Guides and sensors

Checks in a harness split by two features. The first is when they fire. Guides work before the agent acts and set the course: types, code templates, instructions, specs. Sensors work after the action and catch deviations: tests, a linter, an AI review. The second feature is how a check is built. Computable checks (types, tests, linter) fire in seconds and do not err within their rule. Checks through AI (an AI review, a model judge) are more flexible and more expensive, so they are kept for meaning: style, clarity, fit to the intent.

Split as described in Birgitta Böckeler, martinfowler.com

Takeaway
In this exampleFour cells: guides set the course before the agent works, sensors catch deviations afterwards, and each can be computational or AI-based.
In generalComputational checks run in seconds and don't make mistakes within their rule, so use them wherever a rule can be written down formally. Keep AI-based checks for meaning: style, clarity, fit with the intent.
Next stepFor each rule in the agent's instructions, ask whether a test or linter could check it. If so, move it there.

Three check layers

Checks are laid out in three layers. Code quality: style, formatting, types, simple errors. Architecture: module boundaries and dependencies between them, speed requirements. Behavior: whether the product does what the user needs. The bars in the picture show how well that layer has been learned to be checked automatically: the first bar is almost full, behavior has the shortest.

Layer maturity as assessed by Birgitta Böckeler, martinfowler.com

Takeaway
In this exampleCode quality is the easiest to check today, and product behavior the hardest.
In generalLinters and formatters cover the first layer almost immediately. Architecture is checked with dependency rules and performance requirements. Behavior still needs good scenario tests and a human eye.
Next stepStart with the first layer: run a linter and formatter on every agent run, then add one rule for module boundaries.

Earlier is cheaper

Any check fires at some moment, and the earlier it does, the cheaper the mistake is to fix. The picture shows four moments: before the agent works (instructions and specs), at write time (hooks and a linter), in CI (an automatic build and tests when code is pushed to the repository) and in a human review. The $ signs show the rising price of a mistake.

Tests are run by engines such as QUnit, Jest and Vitest. How they differ and which to take is covered in the article Vitest vs Jest: which to pick for a JavaScript project, and when QUnit is enough. Behavior rules that ordinary tests cannot check are found by a model in Quint.

Takeaway
In this exampleThe same mistake costs least before the agent starts and most at human review.
In generalPut fast checks as early as possible: the agent fixes the problem itself while the task context is still in front of it, and only the debatable points reach a person.
Next stepWire tests and the linter into a hook the agent runs after every edit, in addition to CI.

Where people matter

The harness takes over routine checks: style, types, tests, module boundaries. A person decides what a formal check cannot cover: architecture, product questions and new rules. The numbers in the picture show an example ratio: 36 checks for the harness and 6 for a person.

"A good harness keeps the human in the loop and directs their attention to where it matters most" — paraphrasing Birgitta Böckeler, martinfowler.com

Takeaway
In this exampleThe harness takes most of the checks; the person keeps the decisions and the work of improving the harness.
In generalAn experienced developer carries an implicit harness in their head: knowledge of the architecture, team habits, a feel for risk. HDD moves that knowledge into explicit rules, so every agent run gets it.
Next stepAfter each review of the agent's code, write down one comment that keeps coming up and turn it into a rule.

HDD and specs

A spec and a harness complement each other. The spec answers “what should come out”, the harness checks that exactly that came out. In the picture the spec sets the needed result, the harness checks it, and code is accepted by the results of checks rather than by reading every line.

"Specs define the target state, the harness is the control system" — Loiane Groner. More on specs in the talk Spec-Driven Development in practice

Takeaway
In this exampleThe spec answers "what are we building", the harness answers "how do we know we built it".
In generalWithout a spec the harness has nothing to check, and without a harness the spec stays a document. Together they let you accept the agent's code based on checks instead of reading every line.
Next stepFor each requirement in the spec, write down which test or check will confirm it is met.

Where to start

A harness does not have to be designed whole. Start with five steps: the first two set up the environment at once, the other three start the “mistake → rule” loop. A progress file is needed when a task is longer than one session: it holds a list of features with a status, and a new agent session continues from the same place.

  1. 1
    An instructions file for the agent
    AGENTS.md or CLAUDE.md in the project root: how to build, how to test, what not to do
  2. 2
    Linter and tests after every edit
    a hook the agent runs itself before handing over the result
  3. 3
    An agent mistake log
    every mistake fixed by hand gets a line with its cause
  4. 4
    Mistake → rule
    once a week, move log entries into instructions, tests or hooks
  5. 5
    A progress file for long tasks
    a feature list with statuses and the commit history, so a new session picks up where the last one stopped Anthropic
Takeaway
In this exampleFive steps: two set up the harness right away, three start the "mistake → rule" loop.
In generalNobody designs a harness in full up front. It grows out of the agent's real mistakes in your project, and within a few weeks the agent stops repeating the most common ones.
Next stepToday, create the instructions file and the mistake log. In a week, move the first log entries into rules.

Frequently asked questions

What is harness engineering?

Setting up the environment around an AI agent: instructions, tools, permissions and checks.

What is HDD?

Harness-Driven Development: a method where every agent mistake becomes a rule of the environment, an instruction, a test or a hook.

Why is a rule better than a manual fix?

A result fixed by hand helps once, while a rule in the harness works for every future task.

How do you start with HDD?

Create an instruction file for the agent and a log of its mistakes, and once a week move log entries into rules, tests or hooks.
Terms and the layer split follow the sources linked in the captions under the diagrams.
© 2026 Egor Urvanov