Article · · 6 min read
Loop and Harness Engineering: The Work Around the Model
Why the code around a model now matters more than the prompt: harnesses, loops, stopping rules, verification and the token bill.
Two years ago the hard part of building with language models was the prompt. Today the hard part is everything around it. The model is one component. The system that feeds it, checks it, stops it and pays for it is where most of the engineering now lives.
In 2026 that work got two names: harness engineering and loop engineering. I think both names are useful. I also think both ideas are easy to get wrong. This is my view of what they mean, how they fit together and what I would build first.
Who this is for
You have shipped an agent that looked great in a demo. Then in real use it drifted, repeated itself or burned through its budget. Or you are deciding how much freedom to give an agent and want a way to reason about it. Either way, this article is for you.
The model is not the agent
LangChain sums it up in a formula: Agent = Model + Harness. The harness is everything around the model loop: the prompt, the tools and the middleware that shapes behavior.
I agree. I would go further. Two teams using the same model can ship agents that behave very differently. The difference is rarely the model. It is the tools, the context, the permissions and the checks.
There is a good public example. Vivek Trivedy, who leads applied research at LangChain, raised a coding agent’s Terminal Bench 2.0 score from 52.8 to 66.5 without changing the model. The gains came from the environment: better context, time awareness, loop detection and build, verify and fix cycles.
That is the main point of this article. Better engineering around the model can be worth as much as a better model.
What a harness is
A harness is the agent’s working environment. I find it useful to split it into two kinds of parts, a framing I took from codecentric:
- Guides act before the model generates. System prompts, project rules, skill files, tool descriptions and the context you choose to include.
- Sensors act after. Tests, type checks, linters, policy checks, logs and traces.
A good harness also decides what the agent may not do. Sandboxes, permission prompts and allow lists belong to the harness. They are not an afterthought.
My own rule is simple. Every tool an agent can call should have a narrow purpose, a typed input and a safe way to fail. If a tool can do something that cannot be undone, a person or a separate check approves it first.
What a loop is
Loop engineering is the next layer up. Addy Osmani gave it a name in June 2026, a few days after Boris Cherny, who leads Claude Code at Anthropic, said: “I don’t prompt Claude anymore. I write loops that prompt Claude.”
The idea is this. You stop prompting the agent turn by turn. You design a system that prompts it for you, checks the result and decides what happens next.
Osmani lists the building blocks:
- Automations that start runs on a schedule.
- Worktrees so parallel agents do not collide.
- Skills, written project knowledge the agent can read.
- Connectors to tools like issue trackers, usually through MCP.
- Sub-agents, so one agent does the work and another checks it.
- State kept outside the model, in a file or a ticket.
The tools caught up quickly. Claude Code and Codex now have goal commands. You write a condition. The agent keeps working until a separate check says the condition is met.
Harness or loop?
Here is the short version:
- The harness is the environment. What does the agent know? What can it touch? How do I see what it did?
- The loop is behavior over time. When does it run? When does it stop? Who checks the result? What happens after a failure?
The order matters. Context sits at the bottom, the harness sits on top of it and the loop sits on top of that. Each layer inherits the weaknesses of the one below. A loop around a weak harness just repeats the weak result faster.
Four rules I follow for loops
1. Write the stop condition before the start condition. A loop without a clear finish line is a cost leak. “Done” should be something a machine can check: the tests pass, the output matches its schema, the change stays under a size limit.
2. Separate the maker from the checker. The agent that wrote the code should not grade it. Use a different prompt, a different model or a plain deterministic test. Goal commands work this way: a small separate model checks the goal after each turn.
3. Keep state outside the model. Context windows end. Files do not. Anthropic’s pattern for long-running agents keeps a progress log, a feature list and a clean git history, so each new session picks up where the last one stopped. I like it because it is boring and easy to inspect.
4. Treat “done” as a claim, not a proof. A loop can declare success and be wrong. Put a human checkpoint on anything costly, irreversible or public. I made the same argument in my first article: autonomy is a dial, not a switch.
The economics: every loop has a bill
This is the part I think most teams skip.
A single prompt has a predictable cost. A loop does not. Every retry, every sub-agent and every check spends tokens. Sub-agents are the most expensive part, because each one does its own model and tool work. Even Osmani tells readers to be careful with token costs.
So I treat cost as a design input, not a surprise on the invoice:
- Set a budget for every run. Tokens, time and tool calls. When the budget is spent, the loop stops and reports what it has.
- Make the cheap path the default. Use plain code wherever there is a known rule. Use a small model for routing and checking. Save the large model for the hard step.
- Measure cost per finished task, not per call. A loop that costs more per call but finishes in fewer rounds can be cheaper overall.
- Catch loops that never converge. Loop detection is part of the harness. Three identical failures in a row should end the run.
The economic case for loops is real. An agent that works through a backlog overnight can replace hours of manual prompting. But that value only exists if the loop knows when to stop.
Where I would start
If I were adding a loop to an existing agent tomorrow, I would go in this order:
- Tracing first. Every run leaves a record of its plan, tool calls, tokens and errors.
- One goal and one checker. A machine-checkable goal and a check that the working agent does not control.
- Hard limits. A token budget, a time budget and a retry limit.
- External state. Progress lives in a file or a ticket, not in the context window.
- Unattended runs last. Start with low-risk work and widen the scope only when the traces look healthy.
My take
Harness and loop engineering are not new magic. They are good software engineering applied to a component that does not always give the same answer twice. That is exactly why I find them exciting. The skills that matter are ones engineers already respect: clear interfaces, tests, observability and cost control.
Models will keep changing every few months. A well-built harness and an honest loop are what make an agent worth trusting after the next model release too.
Further reading
- Anthropic: Effective harnesses for long-running agents: The progress file, feature list and git pattern described in this article, from the source.
- Anthropic: Effective context engineering for AI agents: The layer under the harness: choosing what goes into the context window.
- LangChain documentation: How LangChain defines the harness and builds agents with middleware.
- Claude Code documentation: A production coding-agent harness you can study and use.
- Addy Osmani: Loop Engineering: The article that named loop engineering and listed its building blocks.
- codecentric: Loop, Harness, Context Engineering explained: A clear side-by-side comparison of the three terms.
- Vivek Trivedy, AI Engineer speaker profile: Talks on harness engineering and the Terminal Bench result mentioned above.