An agent harness is the runtime scaffolding that wraps a Large Language Model and turns it from a text predictor into a goal-directed actor that can perceive, decide, and affect the world. Without a harness, an LLM is just prompt → completion. With one, it becomes an agent.
If the LLM is the CPU, the harness is the operating system — memory, syscalls, drivers, and the loop that keeps the whole thing alive.
The Five Ingredients
A harness is the smallest amount of code that supplies these five things:
- The Loop — repeatedly: assemble context → call model → execute tool calls → feed results back → until the model stops calling tools. This is the core of AI Agents - How They Work.
- Tools — functions the model can invoke (read files, run shell, edit code, search the web). Quality matters more than quantity (Agent Tools - Design Principles).
- Context management — what enters the prompt this turn, how history is preserved or compacted, what files the agent loads. The primary lever for agent quality (Context Engineering).
- I/O surface — how a human (or another program) talks to the agent: TUI, print mode, JSON stream, RPC, SDK.
- Provider abstraction — swap models without rewriting the loop.
Strip any one of these and the agent collapses: no loop → single-shot chatbot; no tools → text generator; no context management → amnesia after every turn.
Why a Harness is Necessary
A raw model API gives you completions. To get an agent, somebody has to:
- give the model tools the host environment trusts
- run those tools safely with the user’s permissions
- maintain conversational state across many turns and many tool calls
- expose all of that to a human or upstream system
That “somebody” is the harness. No harness, no agent. This is the deeper reason Self-Extending Agents are possible at all — the harness is the substrate the agent extends itself into.
Pi as Reference Implementation
Pi (Coding Agent) is the harness used to build and maintain this vault. It is deliberately minimal, which makes it a clean specimen for studying what a harness is vs. what is merely fashionable in current tools.
| Harness concern | Pi’s answer |
|---|---|
| Loop | A small agent loop in pi-agent-core |
| Tools | Four built-ins: read, write, edit, bash |
| Context | Sessions, compaction, AGENTS.md / CLAUDE.md context files |
| I/O | Interactive TUI, -p print, --mode json, --mode rpc, SDK |
| Providers | Anthropic, OpenAI, Gemini, xAI, Groq, Cerebras, OpenRouter, … via pi-ai |
| Extensibility | Skills, Prompt Templates, TypeScript Extensions, Themes, Pi Packages |
| Persistence | Sessions stored to disk; --continue, --resume, --fork, branching trees |
Notice what is absent: MCP, plan mode, sub-agents, todos, permission popups, background bash. These are workflows Pi refuses to bake in so they don’t get imposed on every user. See the Pi (Coding Agent) “Deliberate Omissions” table for the full rationale.
Design tension every harness must resolve
Every built-in feature is a workflow imposed on every user. Every extension point is a workflow enabled but not imposed. Minimal harnesses (Pi) push almost everything into extensions. Maximal harnesses (Claude Code, Cursor agents) bake decisions in. Neither is wrong — they are different bets about who the user is.
Harness vs. Agent vs. Model
A common confusion. Keep these separate:
- Model — the LLM weights behind an API. Generates tokens. Stateless.
- Agent — a behavior that emerges when a model is wired into a loop with tools and goals. Not a thing — a pattern.
- Harness — the code that produces that behavior. The thing you install, configure, and extend.
You can have one model serve many harnesses. You can have one harness drive many models. The agent is what happens between them.
Agent harness vs. evaluation harness
Two different things, same word. The agent harness is what runs in production (this page). The evaluation harness wraps around it to run tasks at scale, capture transcripts, and apply graders. When evaluating “an agent,” you’re always evaluating the harness and the model together. Change either and the eval scores can shift. See Evaluating AI Agents.
The Memory Illusion (read this first)
The single most important fact about how a harness works — and the one most people get wrong:
Key
A coding agent is a goldfish with a very expensive scribe.
The model forgets everything between turns. The harness re-reads the entire conversation aloud, plus all the rules, plus all the tool descriptions, before every single response. What looks like a thinking partner is actually a stateless function being repeatedly re-briefed at full cost.
The LLM never touches anything
When you ask Pi to “read notes.md and summarize it,” the LLM does not read the file. The LLM cannot read files — it is a text-in/text-out function. What actually happens:
- Pi sends your message to the model along with a system prompt that advertises the available tools (
read,write,edit,bash) and their argument schemas. - The model emits text of the form: “I want to call
readwithpath: notes.md.” - Pi — not the model — executes
fs.readFile("notes.md")locally. - Pi sends a second API call containing the original message + the model’s tool-call request + the file contents as a “tool result.”
- Now the model has the file in its context and generates a summary.
The LLM only ever produced text. Every action that touched the world was performed by the harness, on the model’s behalf, in response to text the model emitted. Agency is an illusion the harness creates by parsing the model’s text for tool-call intent and executing it.
The API is stateless — “memory” is re-sent every turn
There is no server-side session. Every API call is a pure function:
response = api.call({
system: buildSystemPrompt(), // ← rebuilt every turn
tools: [read, write, edit, bash], // ← schemas re-sent every turn
messages: [...fullHistory, newMsg], // ← entire transcript every turn
});What feels like memory is actually the harness paying for it in tokens, every turn:
| What feels like memory | What’s actually happening |
|---|---|
| ”The model remembers my project structure” | Harness re-sends CLAUDE.md / AGENTS.md every turn |
| ”The model remembers we’re working on auth.py” | Harness re-sends the entire conversation every turn |
| ”The model remembers the file it just read” | The tool result is in the transcript, which is re-sent every turn |
| ”The agent remembers its plan” | Either (a) the plan is in the transcript, or (b) the agent wrote it to PLAN.md and re-reads it when needed |
This is why coding agents cost roughly quadratically in long sessions: turn N re-pays for turns 1…N−1 every time. It is also why Pi (Coding Agent) rejects MCP, built-in todos, and bloated tool sets — every byte in the system prompt is rent paid on every single turn for the entire session.
Corollary: attaching is permanent, reading is transient
A direct consequence of the stateless API: anything that enters the transcript stays in the transcript until the session ends, gets compacted, or gets branched away. This radically changes how you should think about file attachments.
When you attach 3 PDFs to a message:
- The harness converts them to text (or document/image blocks) and inserts them into your user message.
- That message joins the transcript.
- The transcript is re-sent on every subsequent turn.
- The PDFs are now glued to every future API call until the session ends.
A worked example: attach three 30k-token PDFs on turn 1. By turn 20 you are paying ~120k tokens per turn — already past the 50% degradation point in a 200k window, and most of that cost is re-paying for documents the current turn doesn’t need.
Contrast this with the Pi-style read-on-demand pattern: keep the PDFs on disk, let the model call read("docs/a.pdf", offset, limit) only when relevant. The file contents live in one tool-result message, contain only the relevant pages, and can be compacted away later when no longer needed.
Key
Attaching is a permanent cost. Reading is a transient cost.
Attach only what every turn will need (small spec files, the question itself). Put everything else on disk and let the agent read it on demand.By this rule,
CLAUDE.md/AGENTS.mdis the one file you have explicitly chosen to attach to every turn forever — a choice that should be earned, not casual.
This is the same principle as the file-as-state pattern in Pi (Coding Agent): large data lives on disk, enters context only when needed, leaves context when it isn’t. It is also why Pi’s design centers on the read tool rather than upfront attachments — attachments are a UX convenience that hides a per-turn tax.
Where to see it yourself
Pi’s system-prompt assembly lives in dist/core/system-prompt.js (source: src/core/system-prompt.ts) inside the pi-coding-agent package. The function buildSystemPrompt() constructs, on every turn, a prompt that contains:
- Pi boilerplate (“You are an expert coding assistant operating inside pi…”)
- The tools list with one-line descriptions
- Guidelines (concise responses, show file paths, etc.)
- Pi documentation pointers
# Project Context— yourCLAUDE.md(orAGENTS.md) inlined verbatim- Skills section (if any are loaded)
- Current date and working directory
To inspect raw payloads on the wire, use claude-trace or Pi’s session export. Once you’ve seen it once, the “memory illusion” goes away forever.
What Belongs in the Always-Attached Set
A direct corollary of the per-turn cost model: the system prompt and any context files (CLAUDE.md, AGENTS.md) form an always-attached set — every byte in them is rent paid on every API call for the entire session. Choosing what goes in that set is the most consequential design decision in any project that uses an agent harness.
The “every turn” test
Before adding anything to a context file, apply this test:
“Is this still relevant on a turn where the user asks about something completely unrelated to it?”
- Yes → it belongs in the always-attached set (it is a per-turn invariant; the rent is earned)
- No → it belongs on disk, loaded only when the task matches (skill files, READMEs, source files the agent reads via
read)
The three-layer rule
Applied to a project like this vault, the test produces a clean hierarchy that mirrors WikiLLM’s own three-layer architecture:
| Layer | What lives here | Cost model | Examples |
|---|---|---|---|
CLAUDE.md (always-attached) | Identity + invariants that apply to every turn | Per-turn, forever | ”Use [[wikilinks]]”, “frontmatter must include created:”, “never modify Sources/” |
| Skills / READMEs (on-demand) | Procedures that apply to some turns | Per-use, when needed | ”How to ingest a YouTube video”, “How to handle a PDF source”, “How to lint the vault” |
| Wiki pages (content) | Facts, ideas, summaries | Per-read, when relevant | ”Pulp Fiction (1994)”, “Agent Harness”, “Mario Zechner” |
Key
CLAUDE.mdanswers “who am I and what rules always apply?”
Skills answer “how do I do X when X comes up?”
Wiki pages answer “what do I know?”Confusing these three layers is the most common cause of bloated context files, ineffective agents, and rising API costs.
How harnesses implement on-demand loading
Pi and Claude Code both implement the on-demand layer via a skills mechanism: each skill is a markdown file on disk, but only its name and one-line description (~30 tokens) appear in the always-attached set. The full procedure is read into context only when the task matches. This is the architecture in miniature: a tiny advertisement in the always-attached set, full instructions on disk, lazy-loaded on demand.
See Pi’s docs/skills.md for the implementation, and ~/.pi/agent/skills/ for the skills currently registered on this machine.
What context files actually do to model behavior
A common misconception: that CLAUDE.md makes the LLM “deterministic.” It doesn’t. LLMs sample tokens from a probability distribution, and that sampling stays stochastic regardless of how detailed the system prompt is. What context files actually do is redirect where the variability lives.
Two kinds of variability matter:
| Kind | Description | Affected by CLAUDE.md? |
|---|---|---|
| Structural conformance | File naming, frontmatter schema, link syntax, folder placement, required fields | Yes — explicit rules collapse the distribution to ~99% conformance with frontier models |
| Surface variability | Word choice, ordering, phrasing, judgment calls (which tags, which aliases, how to summarize) | No — remains wide, by design |
Worked example — “Create a wiki page for The Matrix (1999)” run three times:
- Without
CLAUDE.md: three different filenames (the-matrix.md,The Matrix (1999).md,matrix-1999.md), three incompatible frontmatter schemas, three different opening structures. The vault becomes incoherent within a week. - With
CLAUDE.md: all three runs produce the same filename and the same frontmatter schema. The variation moves into which tags, which aliases, how to phrase the opening — i.e., the substance, not the form.
Key
CLAUDE.mddoes not eliminate randomness — it redirects it.
Explicit rules collapse variability in the dimensions you constrain (form, structure, conventions). Variability remains in the dimensions you leave open (word choice, judgment, synthesis). This is the right trade-off: stable containers holding fresh content.If output is drifting unpredictably, the answer is almost always “add a more explicit rule.” If prose feels templated and lifeless, you’ve over-constrained — pull back and let the model think.
Two caveats:
- Temperature (the API’s sampling-randomness parameter, 0–1+) is the dial behind this. Pi defaults to model-appropriate values; you rarely touch it directly. Lower temp = less surface variability across runs.
- Frontier models follow rules dramatically better than older ones. Claude Sonnet 4.5 and GPT-5 obey explicit system-prompt rules ~95–99% of the time. Older models drifted even with explicit instructions. Minimal harnesses like Pi work now in part because instruction-following capability finally matured.
What happens when two rules in the always-attached set contradict each other is a separate problem with its own discipline — see Writing Conflict-Free Instructions. What happens when the always-attached set plus the transcript starts approaching the model’s context window is yet another problem — see Context Window Management Strategies.
What the Harness Does Per Turn
┌─────────────────────────────────────────────────┐
│ AGENT HARNESS │
│ │
│ ┌──────────┐ ┌──────────┐ ┌───────────┐ │
│ │ Context │──▶│ LLM │──▶│ Tools │ │
│ │ Assembly │ │ (remote) │ │ (local fs,│ │
│ └────▲─────┘ └──────────┘ │ shell) │ │
│ │ └─────┬─────┘ │
│ └────── tool results ──────────┘ │
│ │
│ Extensions │ Skills │ Prompts │ Sessions │
└─────────────────────────────────────────────────┘
▲ ▲
│ user (TUI / CLI / RPC / SDK) │ filesystem
- Before the call — assemble system prompt + context files (e.g. this vault’s
CLAUDE.md) + session history + new user message. - During the call — stream tokens, detect tool-use blocks.
- After the call — execute tool calls locally, capture stdout/stderr/files-read, append everything to the transcript, loop.
The harness’s quality is mostly determined by step 1 (what makes it into context) and the affordances of step 3 (which tools, how observable, how reversible).
The Loop: Who Drives, Who Executes
A single turn is straightforward. Multi-turn loops — where the agent reads files, runs commands, edits code, and only eventually returns control to you — are where most confusion about agents lives. Two questions matter: what stops the loop? and who is actually steering it?
What the stop condition actually is
Tool-calling APIs return responses as a list of content blocks. Each block is either a text block or a tool_use block:
{
"stop_reason": "...",
"content": [
{ "type": "text", "text": "Reading auth.py..." },
{ "type": "tool_use", "name": "read", "input": { "path": "auth.py" } }
]
}The harness’s loop is brutally simple:
while (response.content has any tool_use blocks) {
execute each tool_use
append tool_result blocks to history
response = api.call(history) // next turn
}
// Exit: response had only text blocks. Show it to user.Equivalent shorthand using the API’s stop_reason field:
stop_reason === "tool_use"→ loop continuesstop_reason === "end_turn"→ loop exits, control returns to the user
There is no “task complete” signal. The model has no way to send one (it only emits text — see “The Memory Illusion”). The loop simply ends when the model’s response contains no tool calls.
Safeguards the harness must implement
The model has no awareness of being in a loop. It has no counter, no “retry limit,” no way to detect repetition unless the prior repetitions are visible in the transcript and pattern-match strongly enough to influence the next emission. Every safeguard is the harness’s job:
| Safeguard | Purpose | Pi’s implementation |
|---|---|---|
| Iteration cap | Hard limit on tool calls per user turn | Configurable; aborts loop with an error |
| Token budget | Per-call max_tokens, optional session cap | Standard API parameter |
| Context window check | Refuse the call if transcript would exceed window | Triggers compaction or errors |
| User interrupt | Immediately halt the loop | Esc / Ctrl+C |
| Tool-level timeouts | Each tool call has its own time limit | bash accepts a timeout argument |
| Loop / repeat detection | Spot identical tool calls repeating | Sophisticated harnesses; Pi: minimal |
| Cost limits | Halt if running cost exceeds a cap | Pi displays running cost; some harnesses enforce hard caps |
Without these, a confused model can burn through a context window in seconds, run up large bills, or oscillate forever between competing edits. The user’s Esc key is the most important safeguard a harness ships — it is the only one guaranteed to work when the model itself is the source of the problem.
The reactive-executor principle
The most important and least-discussed fact about agent harnesses:
Key
The harness is reactive infrastructure. The model is the driver.
The harness doesn’t decide what the agent does next — it only decides whether to let the agent do what the model asked for. The agent’s entire trajectory (which files to read, which edits to make, when to stop) is determined turn-by-turn by the model’s tool-emit pattern. The harness’s role is to (a) faithfully execute those requests, (b) feed the results back, and (c) enforce safety limits. That’s it.
This is a strange architecture if you come from traditional software:
- In a normal program, you write the control flow and call libraries.
- In an agent, the model writes the control flow at runtime by emitting tool calls. The harness is the library.
The model is your runtime control flow — a probabilistic, non-deterministic control flow you cannot unit test, single-step, or formally verify.
Three consequences
1. Reliability is leverage at the edges, not at the center.
You cannot reach into the model’s reasoning. The only places you have leverage are:
- What tools exist (fewer, sharper, cheaper — see Agent Tools - Design Principles)
- What’s in the context (every byte shapes the next emission — see Context Engineering and Writing Conflict-Free Instructions)
- Safety limits (caps, interrupts, observability)
You cannot make an agent reliable by telling it to be reliable. You make it reliable by constraining what it can see, what it can do, and how long it can do it for.
2. Observability is non-negotiable.
If the model is driving and you can’t see the steering wheel, you’ve lost the loop. This is the deep reason behind Pi (Coding Agent)‘s deliberate omissions:
- No background bash → every command runs visibly
- No sub-agents by default → no opaque inner loops
- No plan mode → plans live in
PLAN.mdwhere you can read them - Session trees & branching → the model’s trajectory is a versioned, browseable artifact
- Per-turn token + cost display → you see the meter run
Maximal harnesses (Claude Code Internals) hide loop behavior in conveniences — auto-compaction, hidden quota checks, sub-agent dispatch. Each of those is a place where the model is driving and you can no longer watch.
3. Booboo compounding is structural, not a model bug.
Every turn’s input is the previous turn’s output. If the model misreads a file on turn 3 and forms a wrong belief, turn 4 acts on that wrong belief, turn 5 acts on the wrong action’s results, and so on. The harness has no way to detect “the model went off the rails three turns ago” — it just keeps executing. By turn 15 you have a confidently-wrong agent that has edited 8 files based on a misread on turn 3. This is why Agentic Coding - Risks and Discipline emphasizes slowing down: the harness amplifies early errors rather than dampening them.
The unifying principle
Key
An agent harness is a faithful executor of model intentions, not a controller of model behavior.
The model emits the agent’s trajectory turn by turn through its choice of tool calls. The harness’s job is execution, observation, and bounded safety — not steering. Reliability comes from shaping the model’s inputs (tools, context, constraints), never from overriding its outputs.This is why agents feel weird: you are not “programming” them. You are configuring an environment where their probabilistic decisions tend to produce useful work. When agents fail, the failure is rarely “the harness did the wrong thing” — it is almost always “the model emitted tool calls that, when executed faithfully, produced bad results.”
What a Real API Trace Looks Like
Everything above is abstract until you see the literal JSON. This section walks through a 3-turn loop on Anthropic’s Messages API — the actual format Pi sends and receives — so the abstractions collapse into something concrete.
Scenario: User says “Read auth.py and tell me what it imports.” Pi has tools read, write, edit, bash registered.
Turn-by-turn sequence diagram
User Harness (Pi) LLM API Filesystem
│ │ │ │
│ "Read auth.py" │ │ │
├───────────────▶│ │ │
│ │ │ │
│ │ TURN 1 REQUEST │ │
│ │ system + tools + │ │
│ │ [user msg] │ │
│ ├─────────────────────▶│ │
│ │ │ │
│ │ TURN 1 RESPONSE │ │
│ │ content: [text, │ │
│ │ tool_use], │ │
│ │ stop: "tool_use" │ │
│ │◀─────────────────────┤ │
│ │ │ │
│ │ fs.readFile("auth.py") │
│ ├──────────────────────────────────────────▶│
│ │ "from flask import Flask..." │
│ │◀─────────────────────────────────────────┤
│ │ │ │
│ │ TURN 2 REQUEST │ │
│ │ system + tools + │ ◀─ system, tools, │
│ │ [user msg, │ and prior turns │
│ │ assistant msg, │ RE-SENT every │
│ │ tool_result] │ turn (stateless) │
│ ├─────────────────────▶│ │
│ │ │ │
│ │ TURN 2 RESPONSE │ │
│ │ content: [text], │ │
│ │ stop: "end_turn" │ ◀─ no tool_use blocks │
│ │◀─────────────────────┤ → loop exits │
│ │ │ │
│ "auth.py imports│ │ │
│ Flask, jwt..." │ │ │
│◀─────────────────┤ │ │
▼ ▼ ▼ ▼
Turn 1 — the LLM’s literal response
This is the actual JSON body that comes back from POST /v1/messages:
{
"id": "msg_01Aq3kf8x9LpVw7...",
"type": "message",
"role": "assistant",
"model": "claude-sonnet-4-5-20250929",
"content": [
{ "type": "text", "text": "I'll read auth.py to see its imports." },
{
"type": "tool_use",
"id": "toolu_01Bv8mP3qR2sN4...",
"name": "read",
"input": { "path": "auth.py" }
}
],
"stop_reason": "tool_use",
"usage": { "input_tokens": 2543, "output_tokens": 64 }
}Observe:
contentis an array of blocks, not a string. The model can mixtextandtool_usein one response.tool_use.idmust be echoed back so the model can match the result to the request.stop_reason: "tool_use"is the API’s signal: “continue the loop.”input_tokens: 2543for an 8-word user message — the other ~2,500 tokens are the system prompt + tool schemas +CLAUDE.md, re-sent on this turn and every turn afterward. The per-turn rent made concrete.
Turn 2 — Pi sends the result back
Note the tool_result is wrapped in a user-role message (the harness simulating the world’s response on the model’s behalf — a quirk worth knowing):
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "toolu_01Bv8mP3qR2sN4...",
"content": "from flask import Flask, request, session\nfrom werkzeug.security import check_password_hash\nimport jwt\n..."
}
]
}Turn 2 — the LLM responds, loop exits
{
"id": "msg_02Lm9pQ4xT8wK6...",
"role": "assistant",
"content": [
{ "type": "text", "text": "auth.py imports Flask, request, session, check_password_hash, jwt, and os..." }
],
"stop_reason": "end_turn",
"usage": { "input_tokens": 2891, "output_tokens": 67 }
}Loop exit conditions visible in this single response:
contentcontains onlytextblocks. Notool_use.stop_reason: "end_turn".
Pi’s while loop sees zero tool calls, exits, and prints the text to the terminal. Control returns to the user.
OpenAI’s equivalent (one note)
OpenAI’s Chat Completions API uses a parallel tool_calls array on the assistant message and role: "tool" for results, with finish_reason: "tool_calls" instead of stop_reason: "tool_use". Same idea, different wrapping. Pi’s pi-ai package abstracts over both formats so the rest of the harness doesn’t care which provider it’s talking to.
What this trace makes obvious
Three things click into place once you see real JSON:
- The “agent” is just JSON ping-pong over HTTP. Each turn is one round-trip. There is no hidden state, no daemon, no “thinking in the background.”
- “I want to call a tool” and “I’m done” are structurally indistinguishable in the model’s output — the only difference is whether
tool_useblocks are present. That’s the entire loop condition. - The per-turn tax is visible in
usage.input_tokens. Every turn pays for the system prompt, tool schemas, and full transcript history, regardless of how short the user’s actual message was.
How to see your own traces
Don’t take this on faith — inspect a real session yourself. Do this at least once:
- claude-trace — Mario Zechner’s tool that intercepts LLM API traffic and logs every request/response payload to disk
pi --export <session-id> trace.html— produces a browsable HTML view of every turn including raw payloads- Provider dashboards — the Anthropic Console and OpenAI logs page show recent API calls with full bodies
Once you’ve stared at one real trace, every section of this page becomes physically visible — the per-turn cost, the re-sent system prompt, the tool_use blocks, the stop-reason loop condition. The abstraction collapses into mechanics.
The Cluster, Compressed
This page launched a six-page deep-dive on harness architecture. Each companion page applies the same underlying rule to a different concern:
| Page | Concern | Application of the rule |
|---|---|---|
| Context Window Management Strategies | Context | Don’t let the model silently rewrite its own past (auto-compaction); keep the user able to edit history visibly (branch, file-as-state, rewind) |
| Streaming in Agent Harnesses | Interrupts and sub-agents | Streaming is the only mechanism that lets the user supervise an LLM in flight; sub-agents are scoped auto-compaction and inherit its failure modes |
| Tool Design for Agent Harnesses | Tools | Burden of proof is on first-class tools; minimal toolsets concentrate model probability on well-trained pathways and stay out of the way for everything else |
| Self-Extending Agents | Extensibility | Minimal toolset and the extension substrate (filesystem) share a substrate, so reliability and extensibility are the same property |
| Session Observability and Replay | History | Capture both actions and the conditions under which the actions occurred, or the record is internally consistent but externally meaningless |
| Provider Abstraction in Agent Harnesses | Providers | Hide what’s different where it doesn’t matter; surface what’s different where it does; cross-provider replay is what you get when every other ingredient is right |
Key
A good harness enforces what the model can’t enforce on itself, preserves what the user can’t reconstruct on their own, and stays out of the way for everything else.
Tools, context, sub-agents, extensions, sessions, providers — every architectural decision in the cluster is an application of this rule. Pi’s minimalism is a strategy, not an aesthetic: minimal pieces compose, maximal pieces don’t, and the value of a harness is exactly the value of its ingredients composing.
Why “Harness” is the Right Word
The term comes from test harnesses and embedded systems: a fixture that holds a component in place, supplies it with inputs, captures its outputs, and lets a human reason about its behavior. An LLM dropped into a coding loop is exactly that — a powerful but unbounded component that needs to be held, fed, observed, and constrained.
A good harness:
- constrains — the model can only do what its tools allow
- observes — every tool call, every result, is visible and replayable
- reversesibly extends — you can add capabilities without rewriting internals (see Self-Extending Agents)
- stays out of the way — it doesn’t impose workflows the user didn’t ask for
What Drives Harness Quality
A common question once people understand what a harness is: which parts actually make agents good? The “model vs harness” framing (roughly 30% model, 70% harness) is too coarse to act on. Decomposed, the picture is sharper.
These numbers are directional, not science. They reflect the working consensus across Anthropic’s Building Effective Agents and ACI work, OpenAI’s harness-engineering writeups, the Vercel “removed 80% of tools, got better results” anecdote, and practitioner reports from Manus, LangChain, and Cursor.
| Component | Rough share | What sits here |
|---|---|---|
| Model | ~30% | The LLM weights. You select; you cannot tune. The 1 to 3 point benchmark gap between frontier models is not where wins live. |
| Tool design | ~25% | Which tools exist, how few, how sharp, how their descriptions read. Tool descriptions are prompts the model reads on every turn. Anthropic doubled performance on some tasks just by rewriting them. See Agent Tools - Design Principles, Tool Design for Agent Harnesses, Agent-Computer Interface (ACI). |
| Context management | ~25% | What enters the prompt this turn. CLAUDE.md / AGENTS.md, on-demand retrieval, compaction strategy, what stays on disk, attach-vs-read. The biggest source of quiet failures. See Context Engineering, Context Window Management Strategies. |
| Prompting | ~15% | The always-attached system prompt, the project context file, the per-turn user prompt. Real leverage, smaller than people think. See Writing Conflict-Free Instructions. |
| Loop, safeguards, observability | ~5% | Iteration caps, plan mode, hooks, permissions, session trees, interrupt UX, replay. Mostly invisible until something breaks. See Session Observability and Replay. |
Key
Model 30, harness 70. Of the harness 70, prompting is roughly a third. The other two thirds are tool design and context management.
The instinct to “fix the prompt” is the cheapest move and the smallest lever. Senior practitioners stop talking about prompts because they have already moved on to tools and context.
Where “prompting” actually lives
What people call prompting usually bundles three different things, only one of which is the per-turn user prompt:
- The user prompt (what you type today). High variance, low ceiling. A great user prompt on a bad harness still fails.
- The system prompt + context files (always-attached, see What Belongs in the Always-Attached Set above). Real leverage, but written once and amortised over thousands of turns. Closer to harness configuration than prompting.
- Tool descriptions (per registered tool). The model reads these to decide which tool to use and how. Counts as prompting in spirit but lives inside the tool layer.
If you collapse all three into “prompting”, the share rises to roughly 40 to 45%. That’s only because the relabelling absorbed tool design and context engineering. The decomposition above keeps them separate because the disciplines are separate: rewriting a CLAUDE.md is not the same skill as designing a tool surface.
Order of leverage
Where to spend effort, ranked by yield:
- Pick a good model. Free 30%. Do not fight a weak model with a clever prompt.
- Fix tool design. Fewer tools, sharper tools, descriptions written like docstrings. The Vercel “remove 80% of tools” pattern is the canonical example.
- Curate context. Apply the “every turn” test (see What Belongs in the Always-Attached Set). Decide what lives in CLAUDE.md vs on disk vs loaded on demand.
- Write conflict-free instructions. Conditional rules, explicit precedence, no contradictions (Writing Conflict-Free Instructions).
- Improve per-turn prompts. The smallest lever. Helps, but will not save a bad harness.
- Add loop and safety controls. Important for production trust, marginal for output quality on simple tasks.
The reason the industry talks about prompting first is that it is the most visible. The reason Anthropic spent more time on tool descriptions than the system prompt when building Claude Code is that tools and context dominate the variance.
Choosing or Building a Harness
Questions to ask:
- What tools does it ship, and can I see the source? (Agent Tools - Practical Starter Kit is a useful baseline.)
- How is context assembled each turn? Is the system prompt visible? Can I add my own context files? (Context Engineering)
- What does it refuse to do, and why? Refusals reveal design taste.
- How do I add capability without forking? Skills, extensions, plugins, MCP — what’s the extension model?
- Can I observe and replay? Session storage, branching, export.
- Can I drive it from another program? RPC / SDK / JSON mode.
- Cost and provider lock-in? Single-provider harnesses age badly.
For most personal use, picking a minimal harness (Pi (Coding Agent)) and extending it beats fighting a maximal one.
Related Concepts
-
Harness Engineering — the discipline of designing, tightening, and pruning the harness over time; the verb form of this page’s noun
-
The Ratchet - Every Mistake Becomes a Rule — the central practice of harness engineering: every failure becomes a permanent constraint
-
Pi (Coding Agent) — the reference minimal harness; this vault’s daily driver
-
Self-Extending Agents — the philosophy that complements a minimal harness
-
Context Window Management Strategies — the six strategies for handling transcript growth, and why auto-compaction is dangerous
-
Streaming in Agent Harnesses — what changes when responses arrive token-by-token: UX, interrupt semantics, and why sub-agents are scoped auto-compaction
-
Tool Design for Agent Harnesses — why fewer tools produce more reliable agents; what a first-class tool has to earn; first-class vs skill/CLI
-
Session Observability and Replay — the post-hoc completion of the observability thread: 11 needs, three meanings of “replay,” and why context-as-it-was is load-bearing
-
Provider Abstraction in Agent Harnesses — the fifth ingredient as a deep-dive: what providers genuinely disagree about, the two-faces design, and why cross-provider replay/fork/routing is what every other ingredient compounding looks like
-
Context Engineering — what the harness’s context-assembly step is doing
-
AI Agents - How They Work — the loop the harness implements
-
Agent Tools - Design Principles — what makes the tool layer good
-
CLI Tools Pattern — how to add capability to a harness without MCP
-
Claude Code Internals — a maximal harness, dissected; useful contrast to Pi
-
MCP Tools vs Custom Function Tools — a harness-level extension-model question
-
Agentic Coding - Risks and Discipline — what goes wrong when the harness lets the model do too much
-
12-Factor Agents — twelve production properties that map onto the five ingredients; argues for a sixth explicit one, the thread
-
Agent State and Resumability — the thread as the harness’s durable state; unify execution + business state, pause between tool selection and invocation
Open Questions
- Where is the boundary between “harness feature” and “skill/extension”? Pi pushes almost everything outward; Claude Code pulls almost everything inward. Is there a principled rule, or is it taste?
- What’s the minimum harness that still produces a useful coding agent? (Pi is one data point; could it be smaller?)
- How should harnesses handle long-horizon tasks where context exceeds even compacted history? File-as-state (Pi (Coding Agent)‘s pattern) vs. memory systems (Agent Memory) — when does each win?