Agent Harness Design: Squeezing from Two Ends
Building capable agents is a game played from two ends: better models generate sensible actions with higher probability; better harnesses induce corrective actions more effectively. This post is about the harness side — what it means to design one well, and what that looks like in practice.
A Mental Picture for Agent Harnesses
To understand what a harness is doing, it helps to be precise about what an LLM is doing. Three ideas frame this:
- The LLM is a probabilistic generator of reasoning tokens and actions — tool calls, structured responses, free-form text — which ultimately receive “feedback” from the external world (tool return values, errors, user responses, rewards).
- That feedback takes many forms: syntactic errors from simple LLM mistakes, inconsistencies between new and previous results in a computational chain, rewards for achieving certain outcomes.
- The harness is an FSM that controls all feedback paths and formats that feedback to steer the LLM’s probabilistic generation toward desirable trajectories.
If the harness can discourage undesirable trajectories more effectively than the underlying LLM’s propensity to produce them, the agent makes meaningful progress. This is the squeeze: every improvement to the harness buys capability independently of model quality, and the two compound.1
The harness designer has four levers to pull:
- FSM design: what states exist, what triggers transitions, and what the LLM sees at each state.
- Schema design: how LLM responses are structured and constrained to extract reliable signal.
- Error surfacing: how failures are detected, formatted, and fed back to steer recovery.
- Reward design (where applicable): how outcomes are scored to shape long-horizon behavior.
The rest of this post develops each of these in turn.
FSM Design
The FSM is the skeleton of the harness; it determines what states the agent can be in, what information is available at each state, and how the agent transitions between them. Two design decisions that pay off well in practice stand out:
- The agent’s working memory must be rendered into context at every thinking step — this is passive feedback that shapes every LLM call, and its quality is easy to underestimate.
- Error recovery should be a first-class, well thought-out FSM state rather than an inline step in the main loop — the distinction keeps recovery logic clean and independently evolvable, and makes it easier to categorize exceptional cases to steer the LLM effectively.
State Rendering
Feedback flows not just through error messages but through the LLM’s view of its own working memory. At each thinking step, the harness renders the agent’s state — notes, stored objects (more on this later), artifacts, … — into the context window. How one structures, orders or compacts that state directly influences the LLM’s next action.
This is a feedback design decision that is easy to overlook. A state render that buries the most relevant information deep in a wall of text,2 or that uses inconsistent formatting across sections, degrades the LLM’s ability to reference its own work correctly. Conversely, a well-structured state render — clear section boundaries, consistent representations, eviction/compaction policies that preserve recency — functions as passive feedback that continuously orients the LLM. This is the FSM design lever operating quietly in the background of every thinking step.
Error Recovery as a First-Class FSM State
When validation or execution fails, the simplest response is to append the error to the conversation and re-prompt. This works, but it conflates two distinct concerns: the main agentic loop (think, act, observe)3 and the recovery logic (decide how to respond to failure). Inline handling becomes hard to reason about and extend as recovery logic grows more complex: Different error types warrant different responses, some failures should escalate to the user, others should cause the agent to give up gracefully.
A cleaner design promotes error recovery to a dedicated FSM state. When a failure occurs, the FSM transitions to the recovery state, which formats the error, applies recovery-specific logic (retry, escalate, or abort), and transitions back to the appropriate next state. The main thinking loop stays clean, and recovery strategies can be evolved independently. The failure modes that matter in practice — tool errors, LLM refusals, dependency failures, unrecoverable state — each get a well-defined path rather than ad-hoc branching in the middle of the main loop.
A dedicated recovery state is also the natural place to detect loops. The characteristic failure of a naive retry policy is an agent issuing the same broken call over and over, receiving the same error each time. Keeping separate error budgets per error type, and treating a repeated identical failure as a signal to change strategy or escalate rather than to retry, turns recovery from a blind loop into a decision.
Schema Design
Schema design is the harness designer’s primary tool for expressing behavioral expectations. A well-designed schema eliminates entire error classes before any validation code runs, exposes the right abstractions to the LLM, and encodes contracts the LLM cannot violate structurally. Two aspects are worth developing: making interpreter memory a first-class schema concept to eliminate object conversion errors, and using schema constraints to enforce multi-state behavioral contracts precisely.
Interpreter: Agent’s Native Environment
Making interpreter memory the agent’s native environment has two equally important benefits.4
The first is eliminating object conversion errors. Tool functions take arguments as JSON — strings, numbers, nested objects — which the harness must convert into actual Python objects before calling the function, then serialize the return value back to JSON for the LLM. Each round trip is an opportunity for mistakes: the wrong type, a nested structure the LLM mis-specifies, a value that serializes differently than the LLM expects. The solution is to assign each stored object a string key and let tool arguments reference those keys directly — the LLM manipulates Python objects via symbolic handles, never touching their serialized form. This structured pointer pattern sits between raw JSON arguments and full code generation on the complexity spectrum: the LLM doesn’t write code, yet it doesn’t serialize everything just to call a function.
# Tools are plain Python functions; type hints become the JSON schema.
def load_table(path: str) -> DataFrame: ...
def summarize(table: DataFrame, by: str) -> DataFrame: ...
# Without storage keys, the LLM must spell the table out as JSON:
{"name": "summarize",
"arguments": {"by": "region",
"table": [{"region": "EMEA", "q3": 1204331}, ...]}}
# With storage keys, results stay in interpreter memory
# and the LLM passes handles instead:
{"name": "load_table",
"arguments": {"path": "sales/q3.parquet", "save_as": "sales"}}
{"name": "summarize",
"arguments": {"by": "region", "substitutions": {"table": "sales"}}}
# A bad handle is caught before any tool runs:
# Storage key 'sales' not found for parameter 'table' in tool 'summarize'
The second benefit is that it unlocks non-serializable objects as first-class values. Many useful Python objects — dataframes, model weights, database cursors, compiled graphs — cannot be round-tripped through JSON at all. With interpreter memory as the native environment, the LLM can receive, store, pass between tools, and compose these objects freely, limited only by what the tools themselves can do. This significantly expands the range of tasks an agent can handle without requiring the harness to flatten everything into a JSON-compatible representation.
Both benefits compound over long-horizon tasks: conversion mistakes and representational limitations accumulate with every step, so eliminating both classes early keeps the agent on track. Making this work cleanly is a schema design problem; the harness must expose storage references in the tool schema so the LLM knows they exist and how to use them.
Schema as Behavioral Contract
Schema design is not a mechanical step — it is the harness designer’s primary tool for expressing behavioral expectations. A schema that is too permissive passes the burden of correctness onto later validation layers; one that is precise eliminates error classes before any validation code runs.
A key principle here is that schema states should be structurally distinct, not conventionally distinct. Whenever a field has multiple meaningful states, the first instinct is often to overload a single type — say, using an empty string as a sentinel for “no value.” But this forces the LLM to learn and respect a convention rather than encoding the distinction in the schema itself. A better design gives each state its own structural form5 so that the schema can reject violations without any custom validation code, and the LLM can express intent precisely.
Schema expressiveness and model compatibility are often in tension. More expressive schemas — disjunctive types, per-value descriptions, rich constraints — give the LLM better guidance but may not be supported uniformly across providers (oneOf is a good example). Simpler, flatter schemas are more portable but shift the burden of disambiguation onto the LLM’s training. The right balance depends on the models you target and how much precision you can encode elsewhere.
Finally, an agent harness has more than one schema surface: the LLM’s structured reasoning response (what action it intends to take) and its tool call arguments are separate channels with separate validation concerns. Treating them as one problem leads to recovery logic that handles both failures the same way — a mistake, since a malformed reasoning response and a bad tool argument are fundamentally different error modes that warrant different responses.
Error Surfacing
Error surfacing is where the harness does most of its active steering work. The goal is to catch failures as early as possible, with messages targeted enough to point the LLM toward a correction rather than merely reporting that something went wrong. Three distinct strategies contribute: exploiting the natural error output of code execution, layering validation across multiple phases before any tool runs, and enforcing tool scheduling/dependency constraints to prevent illegal execution orderings before they produce silent failures.
Code Generation
Whether due to inherent predictable structure, the abundance of training data, or some other fundamental reason, LLMs are great at generating code.6 More importantly for harness design, running code almost always produces concrete, actionable errors on failure — even a syntax error tells the LLM exactly what went wrong and where. This makes code execution one of the most effective error surfacing strategies available.
Strictly speaking, choosing code over discrete tool calls is as much an action space decision as an error surfacing one: it changes what the LLM can express in a single step, and how many tools it needs at all. But its biggest payoff for the harness designer is on the error side.
We already see a reduction (but not elimination) in tool variety as frameworks adopt code-generation approaches (Vercel’s blog post on this, Anthropic’s programmatic tool calling).
Layered Validation
Schema constraints are the first line of defense, but they cannot catch everything — particularly semantic errors that are contextually wrong but structurally fine. A simple example is the presence of a tool argument that references a key that does not yet exist. A well-designed harness adds validation in layers, each catching a different error class at the earliest possible moment:
- Schema enforcement: structurally invalid responses should be rejected immediately, before any processing.
- Parse-time checks: values that are individually schema-valid but mutually contradictory — cross-field constraints that the schema cannot express — are caught when the response is parsed as a whole.
- Pre-execution validation: before any tool runs, the harness checks that arguments are consistent with the current execution context; e.g., whether storage keys exist or will be created by a preceding call, required parameters are present, dependencies are acyclic.
- Type coercion and argument validation: tool arguments are converted from JSON to the expected Python types, with mismatches caught and reported.
Increasingly, there is a layer zero as well: constrained decoding. When a provider’s strict structured-output mode masks invalid tokens during generation, schema violations cannot occur at all, and the first layer becomes a guarantee rather than a check. This is also where the expressiveness tension from the previous section bites hardest: strict modes support only a subset of JSON Schema,7 and constructs like oneOf are often outside it.
Catching errors early matters because tool calls may be expensive or have side effects: an error caught in pre-execution validation avoids running one or more tools only to fail partway through. More importantly, each layer can produce a precisely targeted error message — “storage key ‘result’ not found” is more corrective than “tool call failed.” The harness gets multiple opportunities to steer the LLM back toward a valid trajectory before anything expensive happens.
Tool Scheduling and Concurrency
LLMs often issue bursts of tool calls in a single turn. If those calls are independent, running them concurrently reduces cycle time significantly; if they have dependencies, the harness must serialize them correctly or detect invalid orderings. Functional programming offers a useful lens here: if each tool declares whether it is pure (no side effects, result depends only on inputs) and whether it writes to shared state, the harness can determine a valid execution order automatically.8 Where the LLM has requested an ambiguous ordering — say, two tools that both write to the same storage key without a dependency between them9 — the harness can generate a precise, corrective error rather than silently producing a wrong result.
This is the error surfacing lever applied at the scheduling layer: the harness understands tool semantics well enough to catch a class of LLM mistakes before they cause silent failures downstream.
Reward Design
Reward design — how outcomes are scored to shape long-horizon behavior — is the fourth lever. It is most visible in reinforcement learning settings, where the harness must define what constitutes progress and encode that as a signal the training process can act on. But it is not confined to training: verifiers, test suites and LLM judges score outcomes at inference time too, and a harness can use those scores to choose between candidate attempts or to trigger self-correction. A thorough treatment deserves its own post and is outside the scope of this one; the three levers above apply regardless.
Where This Leaves Us
The four levers compound. A more precise schema reduces the error rate before validation runs; layered validation catches what the schema misses; a dedicated recovery state handles what validation misses; and good state rendering maintains LLM orientation throughout. Each improvement is independent of model quality, and together they multiply the effect of model improvements.
Not every harness gain is permanent, though. The bitter lesson applies here too: scaffolding that compensates for a specific model weakness (heavy validation of outputs that a newer model rarely gets wrong, for instance) tends to be absorbed as models improve. The levers that last are the ones that shape the agent’s environment rather than patch its mistakes: what state it sees, how its actions are typed and scheduled, and how failures are routed.
The current trend toward code generation is, through this lens, a shift in which levers matter most: code execution produces such high-quality error feedback that it partly compensates for weaker schema and validation design. But it doesn’t eliminate the other levers — state rendering, FSM structure, and scheduling remain relevant regardless of whether the LLM is calling tools or writing code.
Both ends of the squeeze have plenty of room to improve: models will keep getting more capable, and harness design is still a relatively young “discipline” with open problems. As the two advance together, agents will be able to take on tasks of greater scope, duration,10 and consequence — and make a proportionally larger impact on the real world.
-
SWE-agent is a clean demonstration: with the model held fixed, redesigning only the agent–computer interface (its commands, feedback format and guardrails) substantially improved results on software engineering tasks. Yang et al., SWE-agent: Agent-Computer Interfaces Enable Automated Software Engineering, NeurIPS 2024. ↩
-
Models are measurably worse at using information placed in the middle of a long context than at its beginning or end. Liu et al., Lost in the Middle: How Language Models Use Long Contexts, TACL 2024. ↩
-
This interleaving of reasoning and acting was popularized by Yao et al., ReAct: Synergizing Reasoning and Acting in Language Models, ICLR 2023. ↩
-
This post focuses on Python-based agents, but the pattern applies broadly. ↩
-
In type-system terms, a tagged union (sum type). The same principle is often summarized as “make illegal states unrepresentable”: Yaron Minsky, Effective ML. ↩
-
Wang et al., Executable Code Actions Elicit Better LLM Agents, ICML 2024, finds that letting agents act through executable Python outperforms JSON or text tool calls. ↩
-
For example, OpenAI documents the subset of JSON Schema its strict mode supports in its structured outputs guide. ↩
-
Given declared dependencies, any topological ordering of the call graph is valid, and calls with no path between them can run concurrently. ↩
-
Processor designers know this as a write-after-write hazard. ↩
-
METR tracks this directly: the length of software tasks (measured by how long they take humans) that frontier agents can complete has been growing exponentially. Kwa et al., Measuring AI Ability to Complete Long Software Tasks, 2025. ↩