A language model on its own only turns text into text. Everything that makes it an agent, such as reading files, running commands, remembering what it did, asking permission and stopping at the right time, is built around it by the harness. Two products using the same model can behave completely differently because their harnesses differ. Harness engineering is the discipline of designing that surrounding system. This lesson takes a harness apart into its components, follows one request through all of them, and explains which design decisions have the biggest effect on quality, safety and cost.
- Define an agent harness and list its main components
- Trace one user request through the loop, tools and context
- Explain why the same model behaves differently in different harnesses
- Identify the design decisions that matter most in a harness
- Read an open-source harness's code and map it to the components
Agent = model + harness
The harness is the software that runs a model as an agent. It builds the prompt, offers tools, executes the tool calls the model requests, feeds results back, manages what fits in the context window, enforces permissions, isolates side effects, records what happened and decides when to stop. Coding agents in a terminal or IDE, browser-using agents and customer-support agents all contain the same components in different proportions.
| Component | Responsibility |
|---|---|
| System prompt and instructions | Role, rules, project conventions, output style |
| Tool layer | Tool definitions, argument validation, execution, result formatting |
| Agent loop | Call model, run tools, repeat; stop conditions and budgets |
| Context manager | What goes into each request; truncation, summaries, retrieval |
| Permissions | Which actions run automatically, need approval or are denied |
| Sandbox | Isolates commands and files from the host and network |
| State and memory | Session history, task lists, persistent notes |
| Extension points | Hooks, plugins, MCP servers, skills |
| Telemetry | Traces of every step, tokens, cost, errors |
| Interface | Terminal, IDE, web or API; streaming and interruption |
Following one request
- The user types "fix the failing date test". The interface sends it to the harness with the session state.
- The context manager assembles a request: system prompt, project instructions, tool definitions, recent history and the new message.
- The model replies with reasoning and a tool call: run the test suite.
- The permission layer checks the call. Running tests is allowed automatically; the command runs in the sandbox.
- The tool layer captures output, truncates it to fit, and appends it to the history as a tool result.
- The loop calls the model again. It reads the failing file, proposes an edit, and the permission layer asks the user to approve the write.
- After tests pass, the model replies with a summary and no tool call, so the loop stops. Telemetry records every step.
Every numbered step is a design decision. How much test output to keep, whether edits need approval, what the project instructions say, and when to stop all change the outcome more than many model upgrades do.
The minimal loop
def run_agent(task: str, tools: dict, max_steps: int = 30) -> str:
messages = [{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": task}]
for step in range(max_steps):
reply = call_llm(messages, tools=[t.schema for t in tools.values()])
messages.append(reply.as_message())
if not reply.tool_calls: # no tool requested: final answer
return reply.text
for call in reply.tool_calls:
if not permitted(call):
result = "denied by policy"
else:
result = tools[call.name].run(**call.args)
messages.append({"role": "tool", "id": call.id, "content": fit(result)})
log_step(step, reply, messages)
return "stopped: step budget reached"Everything else in a production harness elaborates on this loop: permitted grows into a policy engine, fit into a context manager, tools into a registry with schemas and sandboxes, and log_step into tracing. Later lessons in this track build out each of those pieces.
Decisions that matter most
- Tool surface: few, well-described, composable tools beat many overlapping ones.
- Tool result design: concise, structured and actionable results (including helpful error messages) drive the next step.
- Context policy: what is always present, what is fetched on demand, and what gets summarised or dropped.
- Autonomy level: which actions need approval; too strict and the agent is useless, too loose and it is dangerous.
- Isolation: whether commands run on the host, in a container, or in a remote sandbox.
- Stop conditions and budgets: step, token, time and cost limits, and what happens when they are hit.
- Observability: whether you can replay exactly what the agent saw and did.
To learn harness design fast, read the source of an open-source coding agent and find each component in this lesson's table. Note where the system prompt lives, how a tool is defined, how output is truncated and where approvals happen.
Why the harness is an engineering discipline
Harness changes are product changes, and they interact. Adding a tool changes which tools the model chooses; a longer system prompt pushes history out of the context window; a stricter permission rule changes how often users approve without reading. That is why harness engineering pairs naturally with the evals in the first half of this track: every harness change should be measured on a benchmark of realistic tasks, with success, cost and safety reported together.