Harness Engineering for Agents
Agent Equals Model Plus Harness
A language model, on its own, is a function from text to text. You give it some tokens and it returns more tokens. It cannot open your repository, run your test suite, remember what it did ten minutes ago, or stop itself when it starts repeating a mistake. Yet the tools people use every day, which read files, edit code, run commands, and keep working for an hour, all rely on that bare function. The question this topic answers is simple: what is the rest of the system, and why does it decide whether the agent is useful?
The answer is a equation you can hold in your head: agent = model + harness. The model supplies judgment, the ability to propose the next action given what it has seen. The harness is everything else: the code that calls the model, carries its output into the world, feeds results back, remembers the history, enforces limits, and decides what is allowed to happen. Two agents built on the same model can behave very differently because their harnesses differ. That difference is where most of the engineering lives.
Prompt Context and Harness Engineering Compared
Three disciplines are often mixed up, and they differ by how much of the system each one controls. Prompt engineering is the craft of wording a single request: the instructions, examples, and format you hand the model. Context engineering is the choice of what the model sees on each call: which messages, documents, and tool outputs go into the window, and which get trimmed, summarized, or dropped. Harness engineering is the control of the whole loop: when the model is called, what its requested actions do, what state survives between calls, when the run must stop, and what it is permitted to touch.
These layers nest. A prompt lives inside a context, and a context is assembled by a harness. A useful test is to ask, for any failure, which layer could have prevented it. An agent that writes vague summaries is usually a prompt problem. An agent that forgets the file it read five steps ago is usually a context problem. An agent that loops for four hundred steps, or deletes a directory because a tool call said so, is a harness problem. Rewording the prompt will not stop an infinite loop, because the loop never consults the prompt. It consults a counter in code.
The layers also interact. The harness decides what context gets assembled, and the context decides what the prompt can usefully say. If a tool returns three thousand lines of log output, context engineering decides how much of that enters the window, and the harness decides whether the tool's output is capped before it ever reaches that stage. Good harness design makes good context design possible, and good context design makes a prompt's job smaller.
Runtime Infrastructure in Production Coding Agents
Think of a professional kitchen. The chef matters enormously, but the chef is one person in a building with ovens, ticket rails, refrigeration, timers, a fire suppression system, and a rule that nobody cooks with the walk-in door propped open. Remove the chef and the kitchen is idle. Remove the kitchen and the chef cannot feed anyone. In a production coding agent, the model call is the chef's single act of deciding what to chop next. Almost everything else is kitchen.
Concretely, runtime infrastructure is the machinery that surrounds each model call. It includes the loop that takes the model's request for an action, validates that request against a declared schema, checks it against permissions, executes it in an isolated environment, and writes the result back into a transcript. It also includes the state store that keeps the transcript and task progress safe across crashes, the budgets that cap steps and retries, the cancellation path that stops a run cleanly, and the logging that lets someone reconstruct what happened. Each of these pieces answers a question the model cannot answer for itself: what is actually allowed, what already happened, what is still running, and what do we do when things break.
This is why the share of infrastructure in a serious agent is so large. The model produces text that proposes an action. The runtime decides whether that action occurs, whether it succeeds, and whether its result is trustworthy. A model that suggests rm -rf build/ has done nothing until the harness passes the request through a permission check, and the harness is the component that makes that check meaningful. The model supplies flexibility; the runtime supplies the guarantees. The rest of this topic follows that split: once you see the model as a proposal generator inside a larger machine, every later design choice in the course becomes a question about which layer should own a given responsibility.
spec: static diagram of one agent step as a closed loop, titled "One step of a harness". Boxes arranged in a circle, connected by arrows in clockwise order: "Model call (proposes an action)", then "Parse and validate tool arguments against schema", then "Permission check (allow, ask, or deny)", then "Execute in isolated sandbox", then "Format result and append to transcript", then "Budget and stop check (step cap, retries, cancellation)", with an arrow from the last box back to "Model call". Mark the "Model call" box in a distinct colour and label it "the only part the model controls"; label all other boxes as runtime infrastructure. Text labels only, no numbers beyond those shown.
AI-generated study article from SophistAI. Sign up free to study it with an AI tutor.