Sheet W-06 / Writing · AI agents
What is an agent harness, and why does your agent need one?
An agent harness is everything around the model: the loop that runs it, the tools it can call, how its context and memory are managed, the guardrails it runs inside, and the checks on its work. Here is why the afternoon demo breaks in production, and what to build instead.
- The model is a function: text in, text out. Everything that makes it an agent, the loop, the tools, the state and the limits, lives in the agent harness.
- Most production failures are harness failures: context that fills up, tools that fail quietly, nobody checking the work, no memory between runs, nothing that bounds a run.
- A longer prompt or the next model does not replace a missing harness. A prompt instructs; a harness enforces.
- Each component compensates for a limit of the model. Build the seven, weight them to how long the task runs, and keep removing parts as models improve.
I keep having the same conversation. A team shows me an agent that worked in a demo last month: it read a ticket, looked up the customer, drafted the reply. Impressive, in the demo. Then they let it run unattended. It drifted on long tasks, called a tool that failed and carried on as if nothing happened, approved its own output, and afterwards nobody could tell me what it had done or what it had cost.
The model was not the problem. The agent harness was missing. In most of these conversations nobody had heard the term, which is why I wrote this.
01 / DefinitionWhat is an agent harness?
An agent harness is the code, configuration and execution logic that wraps a language model so it can finish work. It is the loop that calls the model, the tools the model can use, the way its context and memory are managed, the guardrails it runs inside, and the checks on its output. The model produces text. The harness turns that text into an agent.
Simon Willison defines an agent as a model that runs tools in a loop to achieve a goal. Strike the model from that sentence and what remains, the loop, the tools and the goal, is all harness. Addy Osmani puts it as an equation he borrowed from Viv Trivedy: agent = model + harness. If you are not the model, you are the harness.
Nobody outside the labs trains the model. Everyone who ships an agent builds a harness, whether they call it that or not. Claude Code, Codex and the agent SDKs are harnesses with a model inside: a loop, a tool set, context compaction, permission gates, hooks. When you wire a model to your CRM with a system prompt and a while loop, that is a harness too. Just a thin one, and in my experience the thin ones are where the trouble starts.
02 / Root causeWhy does the agent break in production?
A demo exercises one happy path, once, with a person watching. Production is a thousand runs with nobody watching. Everything that goes wrong is outside the model:
- The context fills up. Long tasks accumulate tool output until the model loses the thread. In Anthropic's experiments with long-running agents, some models also started wrapping up early as they approached what they thought was the end of their context.
- Tools fail quietly. A timeout or an empty result comes back as text. Without a contract that makes failure visible, the model narrates around it and keeps going.
- Nobody checks the work. Anthropic found that agents reliably skew positive when grading their own output. Ask the model whether the task is done and it says yes.
- Nothing is remembered. Each run rediscovers the same facts about your systems, your data and your rules. Sometimes it rediscovers them wrong.
- Nothing bounds it. No permission gate before an irreversible action, no budget that stops a run, no trace to read afterwards.
Why it breaks: each of these is a limit of the model that the demo never reached. The harness is where those limits get handled. Without one, they get handled by luck.
03 / The workaroundWhy a longer prompt is not a harness
The usual response is to add a paragraph to the prompt for every failure you see. Check the tool result. Do not approve your own work. Stop after ten steps. The prompt grows, behaviour improves for a week, and then the next model version arrives and half the instructions fight it. I have done this myself, but it is not the durable solution.
The second response is to wait for the next model. It will arrive, and it will be better, and the agent will still have no trace, no budget and no gate in front of the delete action.
HumanLayer's framing is blunt: most agent failures are not a model problem but a configuration problem. Prompts are instructions; the harness is enforcement. A line in the prompt asking the agent not to drop a table is a request. A hook that blocks the command is a guarantee.
04 / The fixThe seven components of an agent harness
I decide what to build by starting from the limitation I want to get around. In the demo the model had already done the impressive part: read the ticket, found the customer, drafted the reply. Everything that went wrong sat around it. Something has to call it again, catch a lookup that came back empty, remember how this customer's data is actually shaped, hold the send until a person has looked, and leave a record you can inspect to verify. Each component is that something for one limit. You build it because the model will not cover the gap on its own, however much you ask it to in the prompt.
- The loop and control flow. The first call is easy. The second call is the one that makes it an agent, and some piece of your code has to make it: read what came back, go again, retry a tool that timed out, hand a side question to a smaller agent, or decide the run has gone on long enough. That piece is the loop. A budget belongs in the same place, on steps, on tokens, on minutes. Leave it out and a lookup that should have taken two calls will keep going until the invoice arrives. The other six components sit idle unless something is driving them, and the loop is that something.
- Context engineering. For one question you can put everything in the prompt and move on. A longer task is less forgiving. Every tool result comes back and stays, and the thing the model needed, the customer's constraint, the field it had already settled, slides out of the window at the moment it matters. So each call is a decision about what is still in view: the system prompt, the recent turns, the document you retrieved on purpose, and a short account of what you had to drop. Anthropic found context resets essential for one model generation and unnecessary for the next. Keep the ability to compact, and retest the setting when the model changes. On anything that runs longer than a few minutes, this is the piece I would build before the others.
- Tools. The model can draft the reply in its head. It cannot update the ticket until you hand it a tool, and a sloppy tool is where the quiet failures come from. The name could mean three operations, the schema accepts almost anything, the description was pasted from a wiki, and a timeout comes back as an empty string. The model then writes a perfectly reasonable paragraph about a success that never happened. A tool worth having has a name a new teammate would understand, arguments that fail at the boundary, and a result that says the call failed when it failed. When an agent looks dim, check the tools before you blame the model.
- State and memory. End the call and nothing remains. Fine, if you were classifying one email. A problem as soon as the work spans a lunch break, or as soon as tomorrow's run should already know that this tenant keeps orders in two tables and stores the date as a string. State is the run, written where you can open it: a progress file, a scratchpad, the steps still to do. A job that dies at step forty starts again at step forty, and you can see why it died. Memory is the smaller pile you deliberately load next time. Standing notes, the oddities of your systems, the correction you do not want to make twice.
- Environment and permissions. The model has no separate feeling for an action that is hard to undo. Offer it a send, or a delete, and on a long enough run it will take it, including on the afternoon nobody is watching. So the decision lives outside the model. Where does the command actually run, in a sandbox or on the live account? What is on the allow-list? Which calls stop and wait for a person? Those three questions are the whole component. They are dull. They are also why a mistake stays in a log instead of landing in a customer's inbox.
- Verification. There has to be a way for the work to fail a check the model does not grade itself. A test against the result, a linter, a schema the output has to fit, or a second model that sees only the original task and the artefact, with no draft of its own to defend. Anthropic found that agents skew positive when they grade their own output, and it matches the runs I get called about: ask whether the migration worked and the answer is yes, plus a tidy summary. The summary is the model being agreeable. The check is only useful if it is allowed to say no.
- Observability and evals. Afterwards the question is always what it did, and what it cost. "It is in the chat somewhere" is not a way to operate anything. A trace gives the run an address: this step, this tool, this result, this many tokens, so a strange afternoon has somewhere to start reading. Evals are how you avoid congratulating yourself when you change the harness. Take a few cases that actually happened, run them again, and see whether the change helped. The one ticket you had open while you were tinkering is a terrible witness.
The effect: the agent becomes a system you can run, inspect and improve, rather than a prompt you hope works in all cases. When a run fails, the trace says where. When a model improves, you remove a component and retest.
It is important to scale the harness weight together with the task horizon. Often, you will not need all seven components in your harness. A classifier that runs for a second needs a schema check and a retry, but an agent that migrates data pipelines needs most of the list.
| Task horizon | Example | Harness weight |
|---|---|---|
| Seconds, one call | Classify an email, extract fields from a document | Loop with schema validation and retries. No memory, no evaluator. |
| Minutes, a few tools | Answer a support question from the knowledge base and the CRM | Tools with contracts, a permission gate on writes, a trace per run, a hand-off path. |
| Hours, many steps | Migrate a data pipeline, build and test a feature | State in files, context resets or compaction, a separate evaluator, a cost ceiling, hand-off points. |
Anthropic's own numbers make the trade-off concrete. In their experiment a solo run took 20 minutes and cost $9, and its central feature did not work. The full harness took 6 hours and $200 and produced a working result. The harness is not free, and it is not always worth it. Match it to the horizon.
06 / PrincipleBuild the harness for the model you have
Each of those components is an assumption about what the model cannot do reliably. That is the point of it, and also its expiry date. Anthropic dropped context resets between one model generation and the next, and later removed their sprint construct altogether, because the assumptions behind them stopped being true.
So build the harness for the model you have, test it extensively, run it on real cases, read the traces, and keep removing parts as the model improves. That is most of what harness engineering is: retesting assumptions, not accumulating instructions.
07 / QuestionsFrequently asked questions about agent harnesses
Is an agent harness the same as an agent framework?
No. A framework such as LangGraph, the OpenAI Agents SDK or the Claude Agent SDK gives you building blocks for a harness: a loop, tool calling, state. The harness is the specific assembly for your task: which tools, which guardrails, what gets verified, when a person steps in. You can build a harness without a framework, and a framework without the rest is still a demo.
What is harness engineering?
Harness engineering is the work of designing and maintaining that assembly: choosing the components, running the agent unattended, reading the traces and removing what the model no longer needs. The term grew up around coding agents, but the practice applies to any agent that runs without a person watching.
Do I still need a harness if I use Claude Code or a hosted agent product?
You are already using one. Claude Code, Codex and similar products are harnesses with a model inside: a loop, a tool set, context compaction, permission gates and hooks. The question is whether their harness fits your task, and what you add around it: your tools, your guardrails, your checks, your trace.
Is harness engineering the same as prompt engineering?
No. A prompt instructs the model; the harness enforces. A line in the prompt asking the agent not to delete data is a request. A hook that blocks the command is a guarantee. Good agents need both, but only one of them holds when the model changes.
How do I know which harness components my agent needs?
Start from the failures. Run the agent unattended on real cases, read the traces, and add the component that would have caught each failure: a contract for the tool that failed quietly, a verifier for the output that was wrong, a ceiling for the run that did not stop, a hand-off for the decision a person should have made.
What does datalyft build?
We design, build and run AI agents for business workflows and treat the harness as the deliverable: the tools, guardrails, evaluation and traces, built in your environment and handed over to your team with the documentation to run it.
08 / ReferencesReferences
- Anthropic Engineering, Harness design for long-running application development, Prithvi Rajasekaran, 24 March 2026 www.anthropic.com
- Addy Osmani, Agent harness engineering, addyosmani.com, 19 April 2026 addyosmani.com
- Simon Willison, Designing agentic loops, 30 September 2025 simonwillison.net
- HumanLayer, Skill issue: harness engineering for coding agents, 12 March 2026 www.humanlayer.dev
- Birgitta Böckeler, Harness engineering for coding agent users, martinfowler.com, 2 April 2026 martinfowler.com
- Anthropic Engineering, Building effective agents, December 2024 www.anthropic.com