Harness engineering explained: the work around the AI model
An AI coding agent is a model plus a harness: the context, tools, guardrails and checks around it. Here is what that means, with diagrams and a worked example from the Knowby platform.
Give two engineers the same AI model and they can get very different results. One gets code that compiles, passes its tests and follows the house rules. The other gets code that looks right, drifts from the design and breaks something two files away.
The difference usually isn't the model or a clever prompt. It's everything the engineer has built around the model. That surrounding system has a name now: the harness, and designing it is harness engineering.
This post explains what a harness is, how it works, and what it looks like in practice, using the harness I built for the Knowby platform as the worked example.
Agent = model + harness
The model is the part that reasons and writes. On its own, it can't see your code, run a command or remember yesterday. Everything that lets it do useful, safe work is the harness:
- Context: what the agent reads before it starts. Project rules (in Claude Code, a
CLAUDE.mdfile), the spec, the plan, and source-of-truth documents such as a fact sheet. - Tools: what it can act with. Reading and editing files, running shell commands, driving a browser, and calling your own systems through MCP servers.
- Guardrails: what it's allowed to do. Permission rules, hooks that run before or after an action, and sandboxes.
- Feedback: how it finds out whether it worked. Tests, linters, type checks, builds and reviews.
- Memory: what carries over between sessions. Decisions, notes and lessons, written down where the next session will read them.
- Orchestration: how big jobs are split up. Plans broken into tasks, a fresh subagent per task, and a progress ledger so work survives a long session.
A useful way to think about it: the model is the engine, and the harness is the rest of the car. Nobody judges a car by its engine alone.
The agent loop
An agent works in a loop. Most of the steps in that loop belong to the harness, not the model.
- Read context. The harness hands the model the rules, the task and the result of the last step.
- Plan and call a tool. The model decides what to do next, such as editing a file or running a command.
- Guardrail check. The harness decides whether that action is allowed. Some actions run straight away, some need a person's approval, and some are never allowed.
- Run it. The harness carries out the action, ideally somewhere a mistake can't do damage.
- Test, lint, build. The harness checks whether it actually worked.
If a check fails, the error message goes straight back into the context, and the loop runs again. The agent doesn't need to be told it's wrong; the failing test tells it, precisely. If everything passes, the work is done, and "done" means proven, not assumed.
That last point is the heart of it. An agent without checks will tell you a feature works because the code compiles. An agent with checks has to show it.
Guides and checks
Most harness parts fall into two groups.
Guides steer the agent before it acts. Rules, specs, plans, reusable skills and good examples all make the right result more likely.
Checks catch problems after it acts. Tests, linters, link checks and a second agent reviewing the work all make a wrong result visible.
You need both. Guides alone are advice the agent can misread or forget halfway through a long session. Checks alone mean the agent wanders until it hits a wall. Guides make the first attempt good; checks make sure the last one is right.
A practical rule I follow: if something must always be true, don't just write it in the rules. Write a check for it too.
A worked example: the Knowby platform
The best harness I've built is the one around the Knowby platform: a SaaS used by 15,000 people a day, with .NET Core servers, a React web app, native iOS and Android apps, a Flutter app, a Chrome extension and an internal admin tool, all in one repository. I work in that repository with AI coding agents, so its harness has had plenty of real mistakes to learn from. Here is what's in it.
Context, split by area. A root CLAUDE.md (592 lines) covers the whole repository: the architecture, the critical rules, the testing strategy and how to run the stack. The servers have their own (954 lines), and so does each app. The root file says which one to read, and to read it before any change that crosses areas. An agent fixing an iOS screen doesn't need to wade through the caching rules for the servers, but an agent changing an API does.
Rules that carry their reasons. The working rules section opens with one line that sets the tone: "Each rule is the owner's, with the failure it prevents." Some examples:
- Dapper and raw SQL only, no Entity Framework. Schema changes land in the development migrations first, never straight into UAT or production.
- A method is named for what it does, never
Core,Base,InternalorImpl. - Docs say what the code is and does now, never its history. And no counts of things in docs or comments: a count is wrong on the next commit. Stale context is worse than none, because the agent believes it.
A testing strategy, not just tests. The file says which layer proves what: "Test a behaviour at the lowest layer that can prove it reliably, and prove it once." Server integration tests own the business rules; API contract tests prove the boundary; client tests prove client logic; end-to-end tests cover every screen a person can reach, with happy days and unhappy days. Without that, an agent writes the same test at every layer, or at none.
Checks the agent can't talk its way past.
- Every new test is watched failing first. Break the thing it covers, see the test fail, then restore it. A test that has never failed has proved nothing.
- Flaky tests get a cause, not a retry. Never re-run until green, never add a sleep, never skip it.
- Verify before claiming. Never say fixed, passing or complete without the command output in front of you.
- Failures come from a fault proxy, never a mocked network. End-to-end tests run the real app against the real servers, and the proxy injects the outages, timeouts and dropped connections. The databases are reseeded before every test, so no test depends on another.
Guardrails around judgement. Some decisions aren't the agent's to make. A real question goes to the owner, and the work waits for the answer. A ticket is never started unasked. A review finding that would change a documented rule, or any change to the UI or behaviour, goes to the owner as a question, never as a fix.
Skills for the repeated jobs. Project skills cover adding a backend feature, adding a web feature, fixing a web bug, reviewing web changes and writing end-to-end tests. Each one carries the project's conventions, so the hundredth feature is built the same way as the first. The bug-fix skill, for example, starts with a real reproduction before any fix.
Lessons written down after things went wrong. Two of my favourite sections read like short incident reports:
- Rebuild every service, never just the one you changed. Nearly every server shares a common library, so a one-file change reaches all of them. Rebuilding only the edited service leaves the others on old code, and the failure that follows looks exactly like a real bug.
- Never run a long command silently. A test suite that runs for ten minutes needs progress reported and a monitor that watches for failure, not just progress, because "silence is indistinguishable from still running".
The whole delivery loop is part of the harness
A harness isn't only what happens inside one agent session. On Knowby, the written process covers the whole journey of a change, from the ticket to a person testing it, and the agent follows it every time.
- Ticket. The owner says which ticket to work on, and when. Attached mocks are the UI spec, so a ticket whose attachments can't be downloaded isn't started until they're sent.
- Plan. Every feature ships with tests at the right layers, covering happy days and unhappy days: the intended paths, and the refusals, outages and empty states a person will meet. A plan missing a layer is incomplete.
- Build and test. Work happens on a feature branch. Each new unit and integration test is watched failing before it counts.
- Review loop. Once the unit and integration tests pass, the code is reviewed, fixed and re-reviewed until a round finds nothing.
- End-to-end. Only the end-to-end tests the change's code reaches are run, against a freshly rebuilt stack, with faults injected through the proxy. Running the whole suite for a small change costs hours and proves nothing new.
- Review again. Anything the end-to-end runs made change gets its own review round. No pull request opens without a round that found nothing.
- Pull request. It says which falsification was run for each new test, so the reviewer can see the tests were proven, not just written. A server's full suite runs once before it merges.
- Jira. The ticket gets a comment saying what changed and why, how it was tested, how the tester should test it, and whether it needs an app build or a server deploy. Then it moves to Ready for UAT. A bug that can't be reproduced gets a comment asking the reporter for logs, and moves to Blocked.
- A person tests it in UAT before it's released.
None of those steps is new. Good teams have always worked this way. The difference is that every step is written down precisely enough for an agent to follow, and each one leaves evidence a person can check: a failing-then-passing test, a clean review round, a ticket comment.
How code reviews work
Reviews get the most detailed rules, because a weak review lets everything else slip through.
- The session that did the work runs every review itself. On many projects I use a separate reviewer agent. On Knowby the rule is the opposite, because a fresh reviewer starts without the context the work was done in, and loses it. Neither choice is right everywhere. The point is that it's a decision, written down with its reason.
- Read the whole diff and the code around it, not just the changed lines.
- Measure, don't assume. Any claim about PostgreSQL, a driver or the stack is checked on the real system before acting on it.
- Every fix is proven by a test that fails first. A review finding isn't closed by a code change alone.
- Know whether a failure is yours. A failing test is reproduced at the merge base before anyone says it was already broken. Reasoning that a change couldn't have caused it isn't evidence.
- Some findings aren't the reviewer's to fix. A finding that would change a documented rule, or any UI, UX or behaviour change, goes to the owner as a question.
- Timing matters. The review loop runs after the unit and integration tests pass and before the end-to-end runs, because a problem found then costs minutes, and one found after an hour-long end-to-end run costs the run again.
For the web app, a review skill adds a strict, line-by-line pass against that app's own conventions, reporting each finding with a corrected snippet.
Fix the harness, not the prompt
The single most useful habit in harness engineering is what you do after a mistake.
When an agent gets something wrong, the tempting fix is to correct it in the chat and move on. That fixes this one mistake, in this one session. Next week, a new session makes it again.
The better question is: what made this mistake possible? Then change the harness so it can't happen again:
- If the agent didn't know something, add it to the context.
- If it knew but drifted, add a check that fails when it drifts.
- If it did something it never should, add a guardrail that blocks it.
- If it kept doing a tedious job badly by hand, give it a tool that does the job properly.
Each fix is small. Over weeks they add up to a harness that encodes how a project is done. That's also why a well-harnessed project gets faster over time instead of slower.
The harness reaches into your systems too
Tools are the part of the harness that touches the outside world, so they need the most care. When I built the MCP server for the Knowby platform, the same thinking applied: the assistant signs in as a real person with that person's permissions, anything it creates starts as a private draft, and a person reviews it before it goes live. Those are guardrails and checks, just pointed at production instead of a code base. I covered that in MCP explained: letting AI assistants use your systems safely.
Getting started
If you're bringing AI coding agents into a team, start with the harness, not the model choice:
- Write the rules down. A short project file with how the code is structured, how it's tested, and the decisions already made.
- Make "done" checkable. Tests, a linter and a build the agent can run itself, with one command.
- Turn every important rule into a check. If it matters, it fails the build.
- Keep the dangerous actions behind a person. Deploys, deletions and anything outward-facing.
- Plan big work in small tasks, with a review after each one.
- Write down the whole delivery loop, from ticket to UAT, including how reviews run and what each step must leave behind as evidence.
- After every mistake, fix the harness. Then the mistake stays fixed.
The models will keep getting better. The harness is what turns a capable model into dependable work on your project, and it's engineering in the ordinary sense: design, test, and improve it every time it fails.