Take one tool (a web search API, say) and put it in front of two different agent setups. In the first, the agent calls it three times with overlapping queries, pastes 40,000 tokens of raw results into its own context, loses track of the original question, and answers a slightly different one. In the second, the same tool gets called once with a tight query, returns five results, the agent reads two pages and answers with citations. Same tool. Same model, often. The difference is the harness: the runtime layer that decides which call runs, checks its arguments, enforces its permissions, handles its failure, and decides what its result is worth.
Most tool-use failures blamed on models live in that layer. The sections below take it piece by piece: what it is, the six jobs it does, what the engineering teams who run agents in production have published about building it, and the order to build it in when you are starting from a bare loop of model-plus-tools.
The tool is rarely the problem
When an agent misuses a tool, the instinct is to swap the tool or upgrade the model. Sometimes that is right. More often the evidence points one layer down. Anthropic's engineering team, writing about the evaluations they run on their own agents, describes reading failure signals off the harness rather than the model: total tool calls, redundant calls, tool errors, and invalid-parameter errors. A spike in invalid-parameter errors, in their account, usually means the tool description is unclear. The model was not stupid. The interface was ambiguous, and the harness passed the ambiguity straight through to a real call.
Their earlier guidance on the agent-computer interface makes the same point from the design side: spend at least as much effort on how the agent uses tools as you would on a human interface. One of their examples has become the standard illustration. On their SWE-bench agent, the model kept making relative-path mistakes against a code-testing tool. They changed the tool to require absolute filepaths, a change that made the error structurally impossible, and the model used the tool flawlessly from then on. No model upgrade. No prompt pleading. A harness-level fix to the shape of the call.
This is why AgentsUse now runs a Harness pillar next to its catalog. The catalog answers which tools exist and how they are set up. The pillar answers what has to surround a tool before an agent can be trusted with it. The two questions fail independently: a verified, well-documented tool inside a careless harness still double-sends the email.
What the harness actually is
A harness is everything in the execution path that is not the model and not the tool: the dispatcher that turns a model proposal into a call, the validator that checks arguments against the tool schema, the policy engine that decides whether this call needs a human, the retry and timeout logic around the transport, the budgeter that trims results before they re-enter the context, and the log that records what happened. Frameworks ship machinery for all of it. LangGraph alone documents retry policies with defaults, approval interrupts with a decision vocabulary, durable checkpointing, and two kinds of timeout. Your harness is what you decide with that machinery.
A note on the word, because precision matters here. Anthropic's engineering posts, which are the best public documentation of this layer, do not use the word harness in the pieces this pillar draws on. They write about tool design and the agent-computer interface, about context engineering, about workflow patterns. We use harness as the umbrella term for one practical reason: a builder needs a name for the layer they own, the layer that is theirs to configure, test, and blame. Call it the runtime, the control layer, the glue. The jobs are the same.
There are six of them. The harness must constrain calls (check arguments before execution), budget results (decide what a tool's output is worth in context), gate the consequential ones (permissions and human approval), recover from failure (bounded retries, timeouts, cancellation, safe re-runs), record what happened (structured logs and grounded claims), and coordinate the sequence (order, parallelism, checkpoints). The patterns library on this site devotes a sourced page to each pattern under these jobs: the failure it prevents, how it works, when to soften it, and a checklist.
Design the interface like you would for a new hire
Anthropic's tools guidance reads, at first, like advice for tool authors: choose tools the model can use without contorting itself, namespace related functions, return meaningful names instead of opaque identifiers, keep responses token-efficient. Read it again and it is harness guidance, because the harness is where a team enforces these properties across tools it did not write. You cannot rewrite a vendor's API, but your harness chooses which of its endpoints the model sees, renames parameters at the boundary, and trims what comes back.
The token numbers deserve attention because they are the rare published ones. Anthropic describes a response_format choice in their examples where a detailed tool response ran 206 tokens and a concise one 72, roughly a third, with the detail (names, identifiers for downstream calls) reserved for the steps that need it. Their agent product caps tool responses at 25,000 tokens by default. Put together, the principle is that a tool result is spending from a fixed budget, and the harness, not the tool's default verbosity, should decide the amount. Context researchers on the same team named the underlying effect context rot: as the window fills, the model's grip on what is in it weakens. Every uncatalogued result you paste in spends some of that grip.
Format choices at the boundary pay compound interest. Absolute paths instead of relative ones. Enums instead of free text. Human-readable slugs instead of UUIDs, which Anthropic reports improved their retrieval precision because the model could reason about what it was holding. None of these require the vendor's cooperation. All of them belong to the layer you control.
Where validation actually lives: model API, server, and harness
Argument validation is not one check but three, and they sit in different places. At the model API, some providers can constrain the model's output to a schema. OpenAI's function-calling guide documents a strict mode with two requirements: additionalProperties must be false for each object in the parameters, and every field in properties must be marked required, with optional fields expressed by adding null as a type option. A strict request with a schema that does not conform is rejected with details about the missing constraints, and the guide notes that strict mode does not support every JSON Schema feature. Anthropic documents a strict flag on tool definitions too, which it says guarantees that tool inputs always match the schema (both checked 2026-11-03). Strict modes remove a class of malformed calls before your code sees them, and they leave the other two layers untouched.
At the tool server, the MCP specification says servers must validate all tool inputs, implement access controls, rate limit tool invocations and sanitize tool outputs. At the client, it says clients should show tool inputs to the user before calling, validate tool results before passing them to the model, implement timeouts and log tool usage (tools section, 2025-11-25 and 2026-07-28 revisions, checked 2026-11-03). The harness is the place where these separate duties either meet or leave a gap. A strict-mode schema does not check that a recipient address is allowed, that a path stays inside a sandbox, or that this call, on this account, is permitted. Those are your predicates, and they run after the schema check and before dispatch.
A schema gate also keeps the cheapest failure cheap. The script below is a dependency-free check for flat schemas: required fields, basic types, enums, and additionalProperties false. It is deliberately small. A production gate should use a full JSON Schema validator for the draft your tools declare (MCP tool schemas default to JSON Schema 2020-12 when no dollar-schema field is present). What matters here is the shape of the output: each message names the field, the expectation and the received value, which is the wording a model can act on.
// Minimal pre-dispatch gate for a flat tool schema (dependency-free).
// Handles: required, type (string|number|integer|boolean), enum, additionalProperties:false.
function gate(schema, args) {
const errs = [];
const props = schema.properties ?? {};
for (const k of schema.required ?? []) if (!(k in args)) errs.push(`missing required field "${k}"`);
for (const [k, v] of Object.entries(args)) {
const p = props[k];
if (!p) { if (schema.additionalProperties === false) errs.push(`unknown field "${k}"`); continue; }
const t = Number.isInteger(v) ? "integer" : typeof v;
const ok = p.type === "number" ? (t === "integer" || t === "number") : p.type === t;
if (!ok) errs.push(`field "${k}" must be ${p.type}, got ${t}`);
else if (p.enum && !p.enum.includes(v)) errs.push(`field "${k}" must be one of ${JSON.stringify(p.enum)}, got ${JSON.stringify(v)}`);
}
return errs;
}
const schema = {
type: "object",
properties: { to: { type: "string" }, priority: { type: "string", enum: ["low", "high"] }, retries: { type: "integer" } },
required: ["to"],
additionalProperties: false,
};
console.log(gate(schema, { to: "a@example.com", priority: "urgent", cc: "b@example.com" }));
console.log(gate(schema, { to: "a@example.com", retries: 2 }));
console.log(gate(schema, { priority: "low", retries: "2" }));The three sample calls produce, in order: a message that priority must be one of ["low","high"] and that cc is an unknown field; an empty list for a valid call; and a missing-field message plus a type message for retries given as a string. Each message is short enough to return as the content of an error result, and none of them asks the model to guess.
What production runs add
Past interface design, the published production accounts converge on four additions. The first is checkpointing: save run state often enough that a failure resumes near where it broke. Anthropic describes pairing deterministic safeguards (retry logic, regular checkpoints) with model adaptability, and human-in-the-loop middleware in LangGraph resumes a paused graph from its checkpoint with the human's decision injected. The second is timeouts with real cancellation. The MCP specification, which governs a growing share of tool traffic, advises timeouts on all requests, defines a cancellation notification carrying a request id and a reason, and tells both sides to log when it fires. Latency without a ceiling is not patience; it is an unbounded liability.
The third is permission with vocabulary. A gate that only says yes or no teaches the model nothing. The richer decision set in current frameworks is approve, edit, reject, respond: run it, run this modified version, block it with a reason the model can learn from, or answer the agent with information instead of executing. The OpenAI Agents SDK adds a detail worth copying in any stack: when tool arguments are malformed, its approval flow fails closed, meaning the tool is not invoked and the call goes to a human. Unparseable goes to a person, never to the tool.
The fourth is evidence. MCP's host guidance reads like an audit checklist: show tool inputs to the user before calling, confirm before sensitive operations, validate results before passing them to the model, log tool usage for audit purposes. Anthropic runs full production tracing on its multi-agent research system and evaluates against a fixed set of example queries, watching decision patterns rather than reading conversation contents. The harness that produces that evidence on purpose, structured per call with outcome and cost attached, turns every incident from archaeology into arithmetic.
Six jobs, examined one at a time
Constrain comes first because it is cheapest. Every outgoing call gets checked against the tool's schema inside the harness, and rejections come back worded for the model. The MCP specification builds the whole pattern on a JSON Schema input definition per tool and puts validation on both parties; the harness is simply where a client honors its half. Teams skip this because the model usually gets the arguments right. The point is the tail: the one call in fifty that is malformed is the one that deletes the wrong directory.
Budget is the job teams discover latest and regret most. A tool result is not free text; it is a recurring charge against a finite window, re-read on every subsequent step. The mechanisms are unglamorous: a per-tool token cap (Claude Code's documented default is 25,000), response shapes the caller can size down (the concise-versus-detailed choice Anthropic measured at 72 against 206 tokens), pagination with steering text, and clearing results once the run has extracted their value. The failure this prevents has a name in Anthropic's context research, context rot, and it presents as forgetfulness, which is why it gets misdiagnosed as a model problem for months.
Gate is where consequence lives. The harness sorts tools into auto-run, ask-first, and never-autonomous, and the sort key is what a bad call costs, not how the tool is categorized in a store listing. Vendors already ship signals for this: MCP annotations mark tools read-only, destructive, and idempotent, and the GitHub MCP server can be launched read-only with a flag that overrides friendlier settings. A gate with only approve and deny starves the model; the frameworks converging on approve, edit, reject, and respond are solving a real teaching problem, not adding ceremony.
Recover covers everything between a failure and a decision. Bounded retries with error classification (LangGraph refuses to retry programming errors by default and retries server failures; that distinction is the whole pattern), timeouts with cancellation that both sides honor, and resume that restarts at the failed step rather than the first one. Anthropic's multi-agent system pairs this with checkpointing and telling the model the tool is failing, so it adapts instead of repeating. Recovery also includes the unsafe-replay problem: any step that restarts must know which of its effects already landed.
Record is the job that makes the other five debuggable. One structured line per call, args redacted, outcome classified, result size attached. From that single habit flow the metrics Anthropic publishes for its own agents (call volume, redundant calls, invalid-parameter rates per tool), the audit trail a permission gate needs to mean anything, and the evidence behind every claim a finished run makes. Grounding belongs to this job too: results validated before the model sees them, provenance kept attached, and uncited claims cut at write-up. A run you cannot replay on paper is a run you are operating on faith.
Coordinate decides what runs together and what waits. Dependencies between calls become data (this step consumes that step's output) instead of hopes embedded in a prompt. Independent calls fan out in parallel, which Anthropic credits with large time savings in its research system; dependent calls chain with gates between them, so a write never precedes the read that justifies it. This job is where harness design most resembles ordinary distributed-systems engineering, because it is ordinary distributed-systems engineering, with a language model as one of the unreliable components.
Who owns each duty: a division of labor
Teams lose time when a duty belongs to no one, or when two layers each assume the other has it. Written down with the sources, the split looks like this.
- Model API: tool_choice controls whether a call happens. Anthropic lists auto, any, tool and none, and says some current models return a 400 error for any and tool, recommending auto with strict tool use instead. OpenAI lists auto, required, a forced function, allowed tools and none. Parallel calls are controlled on OpenAI by parallel_tool_calls, where false ensures zero or one tool is called (both checked 2026-11-03). Your harness must not assume forced tool use is available on the model you run.
- MCP server: input validation, access control, rate limiting and output sanitizing are the server's duties under the specification's security section. It also owns the choice between a protocol error and a tool execution error, and the clarity of the message in the second.
- MCP client or host: confirmation prompts for sensitive operations, showing inputs, validating results, timeouts and audit logs. The spec says there should always be a human in the loop with the ability to deny invocations.
- Your harness: pairing every call with a result, enforcing the tool-count and token budgets, deciding which tools the model sees at all (OpenAI suggests aiming for fewer than 20 functions available at the start of a turn, as a soft guideline), and recording outcomes.
The pairing duty deserves emphasis because it is the one most often forgotten. Both major APIs require each tool result to reference the call it answers, by tool_use id on the Anthropic side and call_id on the OpenAI side. A harness that times out a call and then writes nothing breaks the next request. The rule that follows is simple and worth building in early: every dispatched call produces exactly one result, even if that result is an error saying the call did not finish. The companion guide on diagnosing tool-call failures shows how the orphaned-call error looks when this duty is missed.
One boundary case shows why the division matters. When a harness aggregates tools from several MCP servers, tool names that are unique inside each server can collide across them. The 2026-07-28 tools page says name uniqueness is scoped to a single server and that aggregating clients should use a disambiguation strategy such as prefixing names with a server identifier; the 2025-11-25 page has no such note. Nothing in the protocol does that for you. Whichever layer builds the combined tool list, which is usually yours, owns the naming rule, and it should be decided before the first collision silently routes a call to the wrong server.
The build order
You do not build six jobs at once. Start where failures are most frequent and fixes are cheapest. Argument validation first: check every outgoing call against the tool schema in the harness, and return rejections worded for the model (which field, what shape, one example). It is an afternoon of work and it clears the most confusing failure class, malformed calls that execute anyway. Add a per-call timeout with cancellation at the same time; a call that cannot hang cannot stall a run overnight.
Next, classify your tools by consequence and gate the irreversible ones. Read the vendor's own signals first: MCP annotations mark tools read-only, destructive, or idempotent, and at least one major server sets them per tool. Gates go on sends, deletes, purchases, and permission changes, with the four-decision vocabulary, and malformed arguments route to a person by default. If the agent cannot yet be trusted with a tool ungated, the answer is a gate, not a better prompt.
Then the record: one structured log line per call, secrets redacted, outcome classified, result size recorded. This is what makes the rest tunable. Retry policy becomes tunable once you can see first-attempt failure rates per tool. Context budgets become settable once you can see which tools return 40,000 tokens a call. Sequencing and idempotency work lands last because it is the most design-heavy, and because the logs will show you exactly where duplicate effects and step races actually occur in your runs rather than where you imagined they might.
What a harness cannot fix
Three problems live outside this layer. A tool that returns wrong data quickly and consistently will defeat every pattern here except grounding, and grounding only catches shape errors, not falsehoods; that is a vendor problem, settled by switching tools, which is what a verified catalog is for. An incoherent task stays incoherent under a perfect harness: if nobody can state what done looks like, gates and checklists merely formalize the wandering. And a tool with no safe repeat semantics and no idempotency support caps how autonomous the run around it can be. Naming those limits is part of harness engineering. The layer is powerful and it is not magic.
The thirty-day version
Compressed into a month, the build order looks like this. Week one: validation and timeouts. Wire schema checks into the dispatch path, set a per-call timeout from a week of observed latencies, and make cancellations real. The visible effect is immediate: malformed calls stop executing, hangs stop stalling runs, and both start appearing in the open as counted rejections and timeouts instead of mysteries. Week two: the consequence table and the gates. Sort every tool into auto-run, gated, and never-autonomous, attach the four decisions to the gated set, and make malformed arguments fail to a human. This is the week the agent stops being a liability with write access.
Week three: the record. One structured line per call, metrics aggregated per tool, and a standing monthly review with a name on it. Nothing about behavior changes this week, and everything about the following weeks does, because retry bounds, result budgets, and sequencing choices stop being guesses. Week four: spend what the data justifies. The tool with the worst invalid-parameter rate gets its boundary rewritten. The tool returning the fattest results gets a budget. The step that cannot be replayed safely gets its idempotency fix. A month in, the harness is not finished (it is never finished), but it has crossed the only line that matters: every common failure now has an owner, a mechanism, and a number.
What it can do, it does decisively. Most teams who instrument their runs find the same thing Anthropic found in theirs: the failures cluster in fixable places, unclear descriptions, unbounded results, missing gates, absent logs. Build the layer that watches those places, in the order above, and the tool you already have starts behaving like the tool you thought you bought.
Start smaller than this guide. Pick the one failure your runs produced this week (a malformed call that executed, a stall with no error, a result that ate the context), open the pattern page that owns it from the hub, and ship its checklist row. Harness engineering compounds because each fixed layer makes the next failure legible. The teams whose agents run unattended did not get there with a platform rewrite. They got there one owned failure at a time, with the receipts to prove each one stayed fixed.
One last framing, because it decides budgets. The model is rented; the harness is owned. Models will change under you this year, probably twice, and every harness property in this guide (the validation at the boundary, the gates, the budgets, the logs) survives the swap and usually works better on the stronger model. That is the economic argument for building the layer properly: it is the only part of the stack whose improvements you keep.
From the AgentsUse catalog
Published profiles for the tools and frameworks this guide discusses, with setup, limits, and maintenance signals checked against primary sources.
Continue in the Harness pillar
The pattern pages behind this guide: the failure each one prevents, the mechanism, and the implementation checklist.
Frequently asked questions
Is the harness just the framework by another name?
No. LangGraph, CrewAI, and the OpenAI Agents SDK ship harness machinery: retry policies, approval interrupts, checkpointing, guardrails. Your harness is the configuration and policy you build with that machinery: which tools run ungated, what the retry bound is, what gets logged, what a result may claim. Two teams on the same framework run different harnesses, and their agents behave differently because of it.
Which pattern should I build first?
Argument validation, then a per-call timeout. Both are an afternoon of work and together they remove the two most confusing failure classes: malformed calls that execute anyway, and calls that never come back. Add approval gates before the agent touches anything irreversible, and logs before it runs unattended. The production checklist guide orders all of it.
Can a better model substitute for harness work?
It changes the failure rate, not the failure list. A stronger model writes cleaner arguments and recovers from errors more gracefully, and Anthropic's own guidance is to spend effort on the tool interface first because capable models amplify good interfaces. A hung call still hangs, a duplicated side effect still duplicates, and an unlogged run is still unaccountable, whatever model sits inside.
Where do I check facts like retry defaults and token caps?
Every pattern page in the Harness pillar ends with a sources section and a checked date. The numbers used in this guide (LangGraph retry defaults, the 25,000-token tool-response cap in Claude Code, the concise-versus-detailed token comparison) come from the LangGraph documentation and Anthropic's engineering posts, fetched in October 2026.
Does strict mode on a model API replace validating arguments in my own harness?
No. Strict modes constrain the shape of the arguments the model produces (types, required fields, no extra properties). They do not check whether a value is permitted for this user or this resource, and they do not cover calls routed through other paths. Keep a harness check for permission predicates and for the tools that run without strict mode (checked 2026-11-03).
Sources
- Model Context Protocol specification, Tools (2025-11-25)Read 2026-11-03
- Model Context Protocol specification, Tools (2026-07-28)Read 2026-11-03
- Anthropic API docs: Define toolsRead 2026-11-03
- Anthropic API docs: Handle tool callsRead 2026-11-03
- OpenAI API docs: Function callingRead 2026-11-03
Keep reading
Guide
Building Agent Error Recovery
Agents fail. The engineering question is whether failure degrades gracefully or corrupts state. A failure taxonomy and the recovery patterns that contain it: classified retries, fallbacks, circuit breakers, and idempotent re-runs.
2026-09-29
Guide
Agent Tool Permissions Done Right
Every tool you grant an agent is risk you accept. How to size blast radius, tier permissions, gate irreversible actions, design tools for least privilege, and audit what agents actually did.
2026-09-29
Guide
Diagnosing Tool-Call Failures: Read the Run, Fix the Layer
An agent run failed and the transcript will not say why. A field method for separating six failure layers (arguments, tool, transport, context, permission, sequencing) from per-call records, with the fix that belongs to each one.
2026-10-08