Harness²: Improving Agents by Optimizing the Harness

A reproducible experiment for improving an agent without changing model weights and without assuming that a more expensive model is the answer.
When an agent produces unreliable work, the first reaction is often to change the model. That can help, but it is not the only controllable variable. The surrounding harness—instructions, tools, memory, stopping rules, verification, and output handling—often determines whether the model can turn its capabilities into a correct result.
This article describes an experiment named Harness²: an optimizer proposes changes to an agent harness, an evaluator scores those changes on a custom task set, and an experiment runner keeps only changes that improve held-out quality. The procedure is designed to be repeatable. It does not claim a measured improvement here, because no experiment has been run as part of this article. The commands and configuration below define a protocol that a team can run and report honestly.
The problem: quality is a system property
An agent is not just a model call. A useful abstraction is:
agent = model + harness + task context + external environment
The model may be fixed while the harness changes. A harness can decide whether the model sees a task rubric, whether it is allowed to inspect files, how tool errors are reported, when it must verify its work, and what counts as a complete answer. Each decision changes the behavior that the user experiences.
This creates a practical optimization problem:
Given:
a fixed model M,
a task distribution D,
an editable harness H,
and an evaluator E,
find H* such that:
quality(E(M, H*, D)) is high
cost(M, H*, D) remains acceptable
and failures are observable and reproducible.
The important constraint is that the optimizer must not quietly change the model, the task answers, or the scoring rules. Otherwise the experiment measures a moving target.
What “harness optimization” includes
In this experiment, the harness is a versioned directory rather than one large prompt. Keeping its parts separate makes changes reviewable and makes ablation possible.
- Policy: stable behavioral rules, safety constraints, and scope.
- Task protocol: the sequence for understanding, planning, acting, and reporting.
- Tool policy: when tools may be used, how errors are handled, and how results are checked.
- Memory policy: what context may persist between steps or tasks.
- Verification policy: required checks before the agent declares success.
- Output contract: the exact structure expected from the final response.
- Runtime limits: maximum steps, tool calls, tokens, time, or retries.
The optimizer may edit these files, but it should not edit the task set, hidden reference answers, evaluator code, credentials, or the model identifier. A change that improves the score by weakening the test is not an improvement.
A concrete case: repository change requests
Use a custom task set that resembles real work but is small enough to run repeatedly. One practical case is repository maintenance: each task gives an agent a repository snapshot and a request such as “add a validation rule,” “find the cause of this failing test,” or “update the parser without changing the public API.”
A task should contain only the information an actual agent would receive. The reference package can contain hidden tests, expected constraints, and a human-readable rubric, but those materials must not be exposed to the agent during evaluation.
tasks/
train/
task-001.yaml
task-002.yaml
task-003.yaml
validation/
task-101.yaml
task-102.yaml
test/
task-201.yaml
task-202.yaml
references/
task-001/
rubric.yaml
tests/
task-002/
rubric.yaml
tests/
An example task file might look like this:
id: task-001
kind: repository_change
repository: fixtures/calculator
request: |
Add support for negative operands to the integer parser.
Preserve the existing public function signature.
Add or update tests for the new behavior.
limits:
max_steps: 18
max_tool_calls: 40
artifacts:
required:
- source_change
- test_change
- final_summary
This is an example configuration, not a verified benchmark. The task must be adapted to the language, repository layout, and test runner used by the team conducting the experiment.
Define the baseline before optimizing
The baseline is the unmodified harness. Freeze it in version control and run it before allowing any optimizer proposals. Record the model identifier, model settings, task-set revision, harness revision, evaluator revision, random seeds, tool versions, and timestamps.
A minimal manifest can be:
{
"model": "MODEL_ID_SET_BY_THE_OPERATOR",
"model_parameters": {
"temperature": 0,
"max_output_tokens": 4096
},
"harness_revision": "git:BASELINE_COMMIT",
"task_revision": "git:TASKSET_COMMIT",
"evaluator_revision": "git:EVALUATOR_COMMIT",
"seeds": [11, 29, 47],
"network": "disabled",
"credentials": "none"
}
Use placeholders for model identifiers and never place API keys in the repository, task files, logs, or article output. If the model provider does not offer deterministic generation, repeated runs are still useful, but the report must describe the remaining stochasticity.
Scoring quality without pretending that one number is truth
The evaluator should combine automated checks with a structured rubric. Automated checks are appropriate for properties such as tests passing, required files being present, or an output matching a schema. A rubric can cover reasoning-independent outcomes such as correctness, preservation of constraints, and clarity of the final report.
One possible score is:
task_score =
0.55 * correctness
+ 0.20 * constraint_adherence
+ 0.15 * verification
+ 0.10 * communication
overall_score = mean(task_score across tasks and seeds)
The weights above are illustrative. They are not empirical findings and should be justified for the target workflow. Keep the rubric fixed while comparing harness revisions. If the rubric changes, treat that as a new experiment.
Report the distribution, not only the mean. At minimum, retain per-task scores, pass rates, failure categories, tool-call counts, elapsed time, and token usage when available. A harness that raises the mean by making a small number of tasks excellent while breaking several safety-critical tasks may be unacceptable.
The Harness² loop
The optimizer is itself an agent or program with a narrow responsibility: propose a harness patch from experiment evidence. It does not directly decide that the patch is good. A separate runner evaluates the candidate on frozen data.
- Run the baseline on the training split and collect structured traces.
- Group failures by observable cause, such as missing verification or premature stopping.
- Ask the optimizer for a small, explicit patch to the harness.
- Check that the patch touches only allowed files.
- Run the candidate on the training split.
- Reject candidates that violate hard constraints or exceed resource limits.
- Run surviving candidates on the validation split.
- Keep the candidate only if it passes the promotion rule.
- After the search budget is exhausted, run the selected harness once on the held-out test split.
The promotion rule should be written before the search. For example:
promote(candidate) if:
candidate.train_score >= baseline.train_score + 0.02
and candidate.validation_score >= baseline.validation_score
and candidate.critical_failures <= baseline.critical_failures
and candidate.p95_tool_calls <= baseline.p95_tool_calls * 1.25
The numerical thresholds are examples. Choose them before observing candidate results and preserve the rule in the experiment record.
Suggested repository layout
harness2/
harness/
policy.md
task_protocol.md
tool_policy.yaml
verification.md
output_schema.json
tasks/
train/
validation/
test/
evaluator/
run.py
rubric.yaml
checks/
optimizer/
prompt.md
search.py
runs/
scripts/
baseline.sh
candidate.sh
README.md
The runs/ directory should contain immutable run records. Each record should include the candidate patch, manifest, per-task results, aggregate metrics, failure summaries, and the decision to promote or reject.
Commands for a reproducible run
The following commands describe an interface, not a claim that these scripts exist in every project:
# Install the project's pinned dependencies
python -m venv .venv
. .venv/bin/activate
pip install -r requirements.lock
# Validate task files and harness structure
python -m evaluator.run --check-config
# Run the frozen baseline
python -m evaluator.run \
--harness harness \
--split train \
--seeds 11,29,47 \
--run-id baseline-train
# Generate a candidate patch from recorded failures
python -m optimizer.search \
--input runs/baseline-train \
--harness harness \
--output runs/candidate-001
# Evaluate a candidate without changing the baseline
python -m evaluator.run \
--harness runs/candidate-001/harness \
--split validation \
--seeds 11,29,47 \
--run-id candidate-001-validation
# Evaluate the selected revision on the held-out test split
python -m evaluator.run \
--harness runs/selected/harness \
--split test \
--seeds 11,29,47 \
--run-id selected-test
For a real implementation, add a clean-room check that creates a fresh working directory, copies only the declared inputs, disables network access, and runs the evaluator there. This catches accidental dependence on local files, cached answers, or undeclared environment variables.
How the optimizer should propose changes
Give the optimizer structured evidence rather than an unbounded instruction to “make the agent better.” A useful proposal contains a hypothesis, the affected file, the smallest patch, the expected mechanism, and a rollback condition.
hypothesis:
The agent stops after editing because it treats a successful write
operation as proof that the change works.
evidence:
3 of 5 failed tasks had no test invocation after a source edit.
patch:
Add a verification step requiring the relevant test command after
every source change, unless the task explicitly forbids execution.
expected_effect:
Fewer unverified edits.
risk:
More tool calls and possible timeouts.
rollback:
Reject if validation p95 tool calls rises above the configured limit.
Limit each candidate to one or two coherent changes. Large rewrites make attribution difficult and encourage the optimizer to overfit to particular failures.
Verification and anti-overfitting checks
A harness optimizer can overfit even when it never sees the hidden answers. It may learn quirks of the training tasks, add excessive instructions, or exploit evaluator gaps. Use several safeguards.
- Keep the test split inaccessible until the final selection.
- Use task families so related examples do not appear across every split.
- Track prompt and harness length; reject unexplained growth.
- Run a small adversarial set containing ambiguous requests and tool failures.
- Check that the candidate does not read evaluator or reference directories.
- Compare critical-failure rates separately from aggregate scores.
- Repeat the final candidate with more than one seed when generation is stochastic.
- Inspect traces from both improved and degraded tasks.
A prompt injection test is especially important when the agent reads untrusted repository files, tickets, or web content. The harness should distinguish task instructions from data and should not treat arbitrary file text as an authority.
Failure cases worth designing for
Score hacking
If the evaluator rewards a particular phrase in the final answer, the optimizer may add that phrase without improving the work. Prefer outcome-based checks and review traces for suspiciously easy gains.
Verification theater
Requiring the agent to write “verified” does not prove that it ran a meaningful check. Record actual tool invocations and connect them to the files or claims they are meant to validate.
Instruction accumulation
Repeated optimization can produce a long, contradictory prompt. Set a size budget and periodically consolidate rules. If two rules describe the same behavior, keep one canonical version.
Resource regression
A candidate may improve correctness by taking many more steps. This may be acceptable in some workflows and unacceptable in others. Treat latency, tool calls, and token usage as first-class metrics rather than afterthoughts.
Hidden environment dependence
A candidate can appear better because the local machine contains a cache, installed tool, or uncommitted file. Clean-room execution and a recorded environment manifest are the simplest defenses.
Evaluator disagreement
Automated checks and human judgments can disagree. Preserve the raw evidence and report disagreements instead of silently averaging them away. If human review is used, define the sampling method and reviewer instructions before analyzing results.
A compact experiment record
Every reported result should be traceable to a run directory. A compact record might contain:
run.json
candidate.patch
manifest.json
metrics.json
task-results.jsonl
failure-summary.md
trace-index.json
decision.md
The record should answer five questions without relying on memory:
- What changed?
- Which model and settings were used?
- Which tasks and seeds were evaluated?
- How was quality scored?
- Why was the candidate promoted or rejected?
If any answer is unavailable, label the result incomplete. Reproducibility is not a claim that every reader can obtain identical output; it is the ability to reconstruct the conditions, inputs, code, and decision rule that produced the reported result.
Limitations
Harness² cannot establish that harness optimization is universally better than model changes. It tests one model, one task distribution, one evaluator, and one search budget at a time. A candidate that helps repository maintenance may hurt conversational support or long-running research.
Scores are also proxies. A fixed rubric can miss qualities that matter in production, while a human rubric can introduce reviewer variance. The experiment should therefore be treated as decision support, not as an absolute measure of agent intelligence.
Finally, optimization has a cost. The optimizer consumes model calls, engineering time, and evaluation capacity. Compare that cost with the cost of changing the model, adding tools, or accepting the baseline. The useful question is not whether the harness score increased in isolation, but whether the resulting system is more reliable for its intended work.
What to report after running it
A credible report should include the baseline and selected-harness revisions, the exact task-set split, the promotion rule, the search budget, aggregate and per-task metrics, resource usage, critical failures, and examples of both improvement and regression. State clearly which results are measured and which are hypotheses.
The central result is not a prettier prompt. It is a controlled comparison showing whether a specific harness change improves the agent on unseen tasks while preserving the constraints that matter.
Continue with the guides or look up terms in the glossary.