AI Agent Harness Engineering: The Runtime Around the Model
Tokyo AI Dad•••11 min read
Quick answer: AI agent harness engineering is the design of the runtime around a model: the context it receives, tools it may call, memory it retains, tests it must pass, permissions it holds, and points where a human approves work. Strong models need strong harnesses to perform reliably in real workflows.
The previous two pieces were about scaling laws: how model size, data, and compute shape the economics of AI training.
This piece moves one layer outward.
Lilian Weng's "Harness Engineering for Self-Improvement" is not mainly about making model weights larger. It is about the system around a model:
When the base model is already capable, how does the surrounding runtime help it do long tasks, check itself, remember failures, use tools, and improve over time?
The keyword is harness.
Think of a harness as the model's school, toolbox, notebook, exam system, and safety boundary.
The model is the brain. The harness is the system that decides what the brain sees, which tools it can use, what it remembers, how it checks work, and where a human must step in.

Figure 1: The base model supplies intelligence. The harness controls context, tools, memory, evaluation, permissions, and human oversight.
Why does this matter?
Near-term AI self-improvement may not begin with a model directly rewriting its own weights. A more practical path is:
Improve the system that lets the model work. Better work produces better traces, failures, evaluations, and memory. Those artifacts then improve the next harness.
That is the commercial importance of harness engineering.
What Is a Harness?
A simple formula is:
Here:
- is the base model.
- is the task.
- is the harness design.
- is the whole runtime wrapped around the model.
- is the final output.
Plain chat is closer to:
An agent harness is closer to:
The added parts matter:
- : context, or what the model currently needs to know.
- : tools, such as search, files, code execution, databases, and browsers.
- : memory, including logs, failures, trajectories, and artifacts.
- : evaluators, including tests, scores, audits, and regression checks.
The question is not only "how smart is the model?"
It is:
What kind of working environment is the model placed inside?
Why This Connects to Self-Improvement
Recursive self-improvement sounds dramatic. In practice, the near-term loop is more like disciplined software engineering:
- Current harness runs tasks.
- The system stores traces, errors, tool calls, diffs, and test results.
- An agent mines recurring failure patterns.
- It proposes a small harness edit .
- The edit is tested on held-in and held-out tasks.
- It is accepted only if it fixes the known issue without causing regressions.
Mathematically:
Meaning:
Upgrade only when the new harness fixes known failures and does not damage general performance.

Figure 2: A self-improving harness should mine failures, propose bounded edits, regression-test them, and accept only safe improvements.
Three Design Patterns
Lilian's post organizes several harness design patterns. The three most important are workflow automation, persistent memory, and parallel sub-agents.
Workflow automation
An agent should not answer once and stop. Long tasks need a loop:
plan → act → observe/test → reflect → revise → act again
A coding agent works because it can read files, edit code, run tests, inspect errors, and try again. The product is not only a chat interface. It is a runtime loop.
File system as persistent memory
Long tasks generate too much information for the context window. Raw chat, tool outputs, code diffs, errors, and logs quickly become larger than the prompt can handle.
The harness should keep detailed history in files and place only the distilled state into the context window:
Here is the context-window limit, and is persistent memory.
Figure 3: Raw history grows quickly. A good harness keeps the working context small and stores full history in durable files.
Sub-agents and backend jobs
Humans do not research everything in one thread. We run parallel searches, experiments, and reviews.
Agent systems can do the same:
but with parallel workers:
The harness then needs a small process manager: launch jobs, inspect logs, cancel bad runs, store results, and merge outputs.
Model Capability vs. Harness Quality
This is not either-or.
A strong model in a weak harness is like a smart student with no notebook, tools, feedback, or exam system.
A weak model in a strong harness still has a ceiling.
A useful toy function is:
Here is model capability, is harness quality, and captures the interaction.

Figure 4: Model capability and harness quality multiply. The same model can feel very different in different products.
Harness Optimization
The optimization target has moved:
prompt → structured context → workflow → harness code → optimizer code
Early AI product work optimized prompts. But a prompt is only one part of the system. The deeper design surface includes:
- what enters context,
- when tools are called,
- how failures are classified,
- what logs are preserved,
- what edits can be merged automatically,
- where human review is mandatory,
- how sub-agents split work,
- how evaluators are built.
A harness objective can be written as:
So a good harness is not only high-scoring. It must also be cost-controlled and risk-controlled.
Context Engineering
Context engineering turns memory from a growing transcript into a structured, deduplicated, updateable playbook.
The ACE idea can be simplified as:
| Role | What it does | Student analogy |
|---|---|---|
| Generator | Produces task trajectories | Solves problems |
| Reflector | Extracts lessons from success/failure | Reviews mistakes |
| Curator | Updates structured context | Maintains the notebook |
Meta Context Engineering then asks not only "what should be in the notebook?" but "what is the best method for writing the notebook?"
The bi-level optimization is:
Inner loop: find the best context for a given context-management skill.
Outer loop: find the best context-management skill.
Workflow Search
Workflow design can also be optimized.
A workflow can be represented as a graph:
- are actions such as model calls, code execution, tests, and review.
- are transitions such as "if tests fail, return to edit."
The search objective is:
That is why systems such as ADAS and AFlow matter. They treat agent design as a search space, not just a hand-written prompt.
Self-Harness and Permission Boundaries
The Self-Harness pattern is powerful because it is bounded:
- Mine failure patterns.
- Propose narrow harness edits.
- Test on held-in tasks.
- Test on held-out tasks.
- Merge only if there is no regression.
The danger is equally clear. If a program can freely edit the system that evaluates and constrains it, abstraction boundaries break.
Production systems need at least three boundaries:
| Boundary | Purpose |
|---|---|
| Editable surface | Only small parts of the harness can change |
| Permission control | Critical resources are outside the loop |
| External evaluation | The evaluator cannot be edited by the thing being evaluated |
Self-improvement does not mean self-permissioning.
Evolutionary Search
Some harness questions are hard to optimize with gradients but easy to evaluate.
So we can keep a population of candidate harnesses, mutate them, evaluate them, and preserve the best ones.
One sampling rule can be written as:
High-scoring candidates are sampled more often, but candidates that already have many children are discounted to preserve diversity.

Figure 5: Evolutionary harness search should track score, risk, and diversity. The valuable object is the improving Pareto frontier.
This explains the appeal of AlphaEvolve and Darwin Gödel Machine-style systems. If the task can be evaluated, the system can generate candidates, test them, and keep the better ones.
The limits are just as important:
- slow evaluation makes search expensive,
- fuzzy evaluation makes it self-deceptive,
- bad reward design creates reward hacking,
- short-term scores can damage long-term maintainability.
The Hardest Part Is Evaluation
Self-improvement is not mainly about generating new ideas. It is about judging whether a new idea is actually better.
If the evaluator is unit tests, the agent may overfit tests.
If the evaluator is another model, it may learn to please that judge.
If the evaluator is a benchmark, it may exploit benchmark artifacts.
The agent optimizes:
but the business wants:
The danger is:
This is Goodhart's law in agent form.
Business Implications
First, do not buy only a model. Buy the operating system around the model.
Enterprise value comes from repeatable workflows, auditable traces, recoverable failures, verified evaluation sets, permission systems, and tool connections to real business data.
Second, traces are assets.
Every agent run records what it read, which tools it used, where it failed, how it recovered, which tests exposed the issue, and which paths were useless. That is not junk logging. It is the raw material for harness improvement.
Third, AI organizations must move from prompt management to harness management.
Prompts can live in documents. Harnesses need version control, tests, monitoring, rollback, permissions, and audit trails.
Investment Lens
This is not investment advice. It is a framework.
If model APIs become more commoditized, compounding value shifts upward into the system layer.
Figure 6: Model weights and API access face commoditization pressure. Evaluation systems, trajectory data, workflow ownership, and permission/compliance layers may compound longer.
Ask these questions:
| Question | Good signal | Danger signal |
|---|---|---|
| Does the company own evaluations? | Held-out tests and regression suites | Demo-only claims |
| Does it store trajectory data? | Failures, tool calls, repair paths | Only final answers |
| Can the harness improve safely? | Small edits, verification, rollback | Agents can freely edit the system |
| Are permissions externalized? | Safety layer outside the loop | The optimized system edits its own evaluator |
| Is it embedded in workflow? | Connected to real business systems | A chat-only surface |
| Is cost controlled? | Routing, caching, parallelism control | Every task uses the most expensive model |
Long-term moats may come from workflow ownership, proprietary evals, task trajectories, deep tool integration, human review nodes, compliance systems, and systematic learning from failure.
One-Sentence Summary
Scaling laws explain how AI capability grows through model, data, and compute.
Harness engineering explains whether that capability can reliably do long work in the real world.
The realistic self-improvement loop is:
better harness → better task traces → better evaluation and memory → better harness
It is less cinematic than an AI rewriting itself overnight, but it may be much closer to where AI products compound today.
References
- Lilian Weng, Harness Engineering for Self-Improvement, 2026.
- I. J. Good, Speculations Concerning the First Ultraintelligent Machine, 1965.
- Eliezer Yudkowsky, Recursive Self-Improvement, 2008.
- Zhang et al., Agentic Context Engineering: Evolving Contexts for Self-Improving Language Models, 2025.
- Ye et al., Meta Context Engineering via Agentic Skill Evolution, 2026.
- Lee et al., Meta-Harness: End-to-End Optimization of Model Harnesses, 2026.
- Zelikman et al., Self-Taught Optimizer: Recursively Self-Improving Code Generation, 2023.
- Zhang et al., Self-Harness: Harnesses That Improve Themselves, 2026.
- Hu, Lu, and Clune, Automated Design of Agentic Systems, 2025.
- Zhang et al., AFlow: Automating Agentic Workflow Generation, 2025.
- Novikov et al., AlphaEvolve: A coding agent for scientific and algorithmic discovery, 2025.
- Zhang et al., Darwin Gödel Machine: Open-Ended Evolution of Self-Improving Agents, 2025.
- Trehan and Chopra, Why LLMs Aren't Scientists Yet: Lessons from Four Autonomous Research Attempts, 2026.