Harness Engineering for Self-Improvement
This comprehensive survey by Lilian Weng systematically examines the critical role of harness engineering in recursive self-improvement (RSI) for AI systems. A harness is the system layer surrounding a base model that orchestrates execution, context management, tool calling, persistent state, and workflow design. The post synthesizes three design patterns (workflow automation, filesystem as persistent memory, sub-agents and backend jobs) and dives into frontier works: context engineering (ACE, MCE), meta-optimization (Meta-Harness), workflow automation search (ADAS, AFlow), self-improving harnesses (STOP, Self-Harness), and evolutionary search (AlphaEvolve, Darwin Gödel Machine). It concludes with open challenges: weak evaluators, memory management, diversity collapse, reward hacking. Essential reading for AI engineers and agent researchers.
The concept of recursive self-improvement (RSI) dates back to I. J. Good (1965), where he defined an “ultraintelligent machine” as a system that can surpass humans in all intellectual activities and design better machines to improve itself. Yudkowsky (2008) used the phrase “recursive self-improvement” for a specific feedback loop: an AI uses its current intelligence to improve the cognitive machinery that produces its intelligence.
递归自我改进(RSI)的概念可追溯至 I. J. Good(1965),他将“超智能机器”定义为一种在一切智力活动中超越人类并能设计更好的机器来改进自身的系统。Yudkowsky(2008)用“递归自我改进”指代一个特定的反馈循环:人工智能利用其当前的智能来改进产生其智能的认知机制。
This feedback loop in modern AI may indicate the model rewriting its own weights directly, or more broadly the model improves the training pipeline and the deployment system, which in turn enables a better successor model with improved performance across economically valuable tasks. The speed of research development in AI has been shown to drastically accelerated in frontier labs (Anthropic; OpenAI).
在现代AI中,这个反馈循环可能意味着模型直接重写自身权重,或者更广泛地,模型改进训练流程和部署系统,从而催生性能更优的后续模型,在经济上有价值的任务中表现更佳。前沿实验室(Anthropic;OpenAI)的研究开发速度已显著加快。
I explicitly mention “deployment system” because the layer between the raw model and the real-world context seems to be as important as the model’s raw intelligence (i.e. the evals right after pretraining). Harnesses are important components of AI deployment, as shown by successful coding agent products such as Claude Code and Codex. A harness is the system surrounding a base model that orchestrates execution and decides how the model thinks and plans, calls tools and acts, perceives and manages context, stores artifacts, and evaluates results.
我特意提到“部署系统”,因为原始模型与现实世界之间的那一层,似乎与模型的原始智能(即预训练后的评估)同等重要。Harness是AI部署的重要组成部分,成功的编码智能体产品如Claude Code和Codex便是例证。Harness是围绕基础模型的系统,负责编排执行、决定模型如何思考与规划、调用工具并行动、感知和管理上下文、存储工件以及评估结果。
This one post will focus on research around harness engineering and how it contributes to RSI. Much recent work on auto-research, self-improving agents, and evolutionary program search can be organized around this question. Other work on model self-play, synthetic data, test-time training and a broader theme of continual learning also matches the RSI vision (e.g. Yuan et al. 2024, Chen et al. 2024), Zhao et al. 2025, Choi et al. 2026)) but they will not be the focus of this post.
本文将重点围绕 harness 工程的研究及其如何促进RSI展开。近期关于自动研究、自我改进智能体和进化程序搜索的许多工作都可以围绕这个问题进行组织。其他关于模型自对弈、合成数据、测试时训练以及更广泛的持续学习主题的工作也符合RSI的愿景(例如 Yuan et al. 2024, Chen et al. 2024, Zhao et al. 2025, Choi et al. 2026),但它们不是本文的重点。
Compared with early agent frameworks, “agent = LLM + memory + tools + planning + action”, harnesses engineering additionally include workflow design (e.g. loop engineering), evaluation, permission controls, and persistent state management. It is no longer only prompt templates, but closer to runtime and software system design: how the model observes, acts, memorizes, checks itself, and improves.
与早期的智能体框架“智能体 = LLM + 记忆 + 工具 + 规划 + 动作”相比,harness 工程额外包含了工作流设计(例如循环工程)、评估、权限控制和持久状态管理。它不再仅仅是提示模板,而是更接近运行时和软件系统设计:模型如何观察、行动、记忆、自我检查并改进。
The design should be deliberately simple and generic to enable generalization, likely with reference to existing software engineering practices to benefit from prertaining knowlege. There is also a strong analogy between operating systems and harnesses. Similar to an OS, a harness should encapsulate complicated logic while keeping the interface simple. Meanwhile, configs, tool interfaces and other protocols may gradually become standardized across the industry.
设计应刻意保持简单和通用,以实现泛化,并可能借鉴现有软件工程实践以受益于预训练知识。操作系统与harness之间存在强烈的类比关系。与操作系统类似,harness应封装复杂的逻辑,同时保持接口简单。与此同时,配置、工具接口和其他协议可能会逐步在行业内标准化。
Defining a workflow in which the model can operate, test, and iterate is a key design for automation. Karpathy’s autoresearch repo (https://github.com/karpathy/autoresearch) is a clean example of how such a workflow can be constructed. A common workflow follows a goal-oriented loop of plan, execute, observe/test, improve, and execute again until the goal is achieved. The process may trigger proactive requests to users for clarity in task specification or execution preference.

A simplified Codex agent loop: the agent calls tools and tool responses affect the model's next generation.
(Image source: OpenAI codex agent post)
The workflow graph also emphasizes the model analyzing its own trajectories and failure cases and then iterating on its progress through an “agent runtime” rather than a static prompt template.
定义一个模型可操作、测试和迭代的工作流是实现自动化的关键设计。Karpathy的autoresearch仓库(https://github.com/karpathy/autoresearch)是一个清晰的例子,展示了如何构建这样的工作流。常见的工作流遵循一个目标导向的循环:计划、执行、观察/测试、改进、再次执行,直到达成目标。该过程可能主动向用户请求明确任务说明或执行偏好。

简化的Codex智能体循环:智能体调用工具,工具响应影响模型的下一轮生成。
(图片来源:OpenAI codex agent post)
工作流图还强调模型分析自身轨迹和失败案例,然后通过“智能体运行时”而非静态提示模板来迭代其进展。
A recurring pattern in long-horizon agent systems is simple control over rich states and artifacts. A harness should not carry the entire workflow and all logs in context; instead, it should keep durable state in files. In long-horizon agentic rollout, artifacts such as experiment logs, code diffs, paper summaries, error traces, and past rollout trajectories often grow much longer than the context window that the model has trained for.
Learning how to read, write, and edit the file system (commonly via bash commands) is a foundation skill for LLMs, and thus managing persistent memory in the simple form of files naturally benefits from improvements in core model capability.
在长周期智能体系统中,一个反复出现的模式是对丰富状态和工件的简单控制。Harness不应将整个工作流和所有日志承载在上下文中,而应将持久状态保存在文件中。在长周期智能体执行中,实验日志、代码差异、论文摘要、错误轨迹和过去执行轨迹等工件,其长度往往远超模型训练所用的上下文窗口。
学习如何读、写和编辑文件系统(通常通过bash命令)是LLM的基础技能,因此以文件这种简单形式管理持久记忆,自然能从核心模型能力的提升中受益。
A harness can spawn multiple subagents to execute in parallel and monitor backend jobs. This is useful when the main agent needs to search multiple hypotheses, run experiments concurrently, or delegate isolated subtasks without polluting the main context. The parent agent then needs a small process manager: launch jobs, inspect logs, cancel failed runs, and merge results back into the main agent thread.
The key design choice is to make parallelism explicit and inspectable. If subagent outputs only live in a transient chat context, they quickly become obselete and hidden. If they are stored as files, logs, and status records, the model can recover after interruptions and reason over its own execution history.
Harness可以生成多个子智能体并行执行并监控后台任务。当主智能体需要搜索多个假设、并发运行实验或委托隔离的子任务而不污染主上下文时,这很有用。父智能体需要一个小的进程管理器:启动任务、检查日志、取消失败的运行,并将结果合并回主智能体线程。
关键的设计选择是使并行性显式且可检查。如果子智能体的输出仅存在于瞬时的聊天上下文中,它们会很快变得过时和隐藏。如果它们被存储为文件、日志和状态记录,模型可以在中断后恢复并推理自己的执行历史。
The core interface of mainstream coding agents has become stabilized across Claude Code, Codex, OpenCode, and Cursor-style agents. They commonly use a loop like:

With access to a set of tools, the coding agent is able to develop and debug issues in a given repository, similar to how human developers are equipped with IDEs.
(Not a comprenhensive list; shown for demonstration. Read this if interested.)
Group Tool definitions
File system
-
File discovery: glob, grep, ls
-
File read: read, read_many
-
File modification: write (a whole new file); edit (string exact-match replacement); multi_edit; apply_patch (applies a structured patch/diff)
Shell execution Run commands: bash, PowerShell
IO lsp, git tools like git_status, git_diff, git_commit
External context MCP tools, Skills
Web search web_search, web_fetch, browser tools
Artifacts Read docs, images; generate HTML, images
Backend processes Such as: CronCreate, CronDelete, CronList
Agent delegation Such as: spawn_agent, resume_agent, wait_agent, list_agents, close_agent, interrupt_agent, etc.
主流编码智能体的核心接口已在Claude Code、Codex、OpenCode和Cursor风格智能体中趋于稳定。它们通常使用如下循环:

通过访问一组工具,编码智能体能够像人类开发者配备IDE一样,在给定仓库中开发和调试问题。
(非详尽列表,仅用于演示。如有兴趣请阅读。)
组别 工具定义
文件系统
-
文件发现:glob, grep, ls
-
文件读取:read, read_many
-
文件修改:write(写入全新文件);edit(字符串精确匹配替换);multi_edit;apply_patch(应用结构化补丁/diff)
Shell执行 运行命令:bash, PowerShell
IO lsp, git工具如git_status, git_diff, git_commit
外部上下文 MCP工具, Skills
网络搜索 web_search, web_fetch, 浏览器工具
工件 读取文档、图像;生成HTML、图像
后台进程 例如:CronCreate, CronDelete, CronList
智能体委托 例如:spawn_agent, resume_agent, wait_agent, list_agents, close_agent, interrupt_agent等
It is hard to forecast how much the future of RSI will rely on harness engineering, but the near-term path of RSI is unlikely to start as a model directly rewriting its weights. My prediction of a practical near-term path is:
Harness engineering will evolve in the direction of meta-methodology (i.e. improving the machinery for getting better answers, not just improving the answer itself). The harness system itself becomes an optimization target, with fewer heuristic rules and more general mechanisms.
In turn, mature harnesses enable auto-research for model self-improvement loop and smarter models prevents harnesses from overengineering and keep the system sustainable.
Eventually it is possible that many harness improvements will be internalized into core model behavior, but the interface with external context and tools should remain. We have seen a softer version of this pattern with prompt engineering: manual prompt tricks became less central as instruction tuning and model reasoning improved, but the need to specify goals, constraints, context, and evaluation did not disappear.
很难预测RSI的未来在多大程度上会依赖harness工程,但RSI的近期路径不太可能始于模型直接重写自身权重。我对近期实用路径的预测是:
Harness工程将朝着元方法论(即改进获取更好答案的机制,而不仅仅是改进答案本身)的方向发展。Harness系统本身成为优化目标,启发式规则更少,通用机制更多。
反过来,成熟的harness能够实现模型自我改进循环的自动研究,而更智能的模型能防止harness过度工程化,保持系统可持续性。
最终,许多harness改进可能被内化到核心模型行为中,但与外部上下文和工具的接口应保留。我们在提示工程中看到了较软的版本:随着指令调优和模型推理能力的提升,手动提示技巧变得不那么核心,但指定目标、约束、上下文和评估的需求并未消失。
The progression in the object being optimized in the harness system is roughly: instruction prompts → structured context → workflow → harness code → optimizer code. As the model becomes more intelligent and powerful, we move toward more complex targets and generic methods.
Simply appending all the tool responses and model generations into the context can quickly grow out of control as the agentic job horizon increases significantly. Context management is a layer to construct a more structed and concise context for LLM and manage persistant states. There is no doubt that long-context research will keep on making progress but at the moment long-context intelligence and context engineering sometime intertwines.
Agentic Context Engineering (ACE; Zhang et al. 2025) treats context as an evolving playbook rather than an increasingly lengthening prompt. It has three components to maintain one context playbook of bullet points, each with an identifier and a description.
Generator: produces task trajectories, with reference to bullet points.
Reflector: distills insights from successful and failed trajectories.
Curator: updates the structured context with incremental, itemized entries.
Harness系统中优化对象的演进大致为:指令提示 → 结构化上下文 → 工作流 → harness代码 → 优化器代码。随着模型变得更加智能和强大,我们趋向于更复杂的目标和通用方法。
仅仅将所有工具响应和模型生成附加到上下文中,会随着智能体任务时长的显著增加而迅速失控。上下文管理层是构建更结构化、更简洁的LLM上下文并管理持久状态的层。毫无疑问,长上下文研究将持续进步,但目前长上下文智能与上下文工程有时相互交织。
智能体上下文工程(ACE;Zhang et al. 2025)将上下文视为一个不断演化的行动手册,而非越来越长的提示。它包含三个组件来维护一个由要点组成的上下文行动手册,每个要点有标识符和描述。
生成器:生成任务轨迹,参考要点。
反射器:从成功和失败的轨迹中提炼见解。
策展人:以增量、逐项的方式更新结构化上下文。
To prevent context collapse and brevity bias during iterative rewrites, one key design choice in ACE is that the curator does not rewrite a full prompt blob. It instead outputs a collection of structured, itemized bullets in the form of (identifier, description), and these bullets are merged into a structured context logbook with deterministic logic. The context items are refined and deduplicated periodically.
The fact that ACE learns insights from rollouts helps us move toward self-managed memory, but the update rules and the overall workflow are still handcrafted. To move toward a more self-improving loop, Meta Context Engineering (MCE; Ye et al. 2026) separates the mechanism (how to manage context) from the artifact content (what is in context), running skill evolution at the meta-optimization level and context optimization at the base level.
An MCE skill $s \in \mathcal{S}$ defines a context function $c_s=(\rho_s,F_s)$ and maps an input $x$ to context $c = F_s(x;\rho_s)$, where:
$\rho_s = {\rho_1,\dots,\rho_m}$ are static components (prompts, knowledge bases, code libraries).
$F_s = {F_1,\dots,F_k}$ are dynamic operators (search, selection, filtering, formatting).
The bi-level optimization is to find the best context $c_s^*$ given skill $s$ on the training data, while the outer loop finds the optimal skill that provides the best performance on the validation set:
$$ \text{Inner: }c_s^=\arg\max_{c_s}J_\text{train}(c_s;s)\quad \text{Outer: }s^=\arg\max_{s\in\mathcal{S}}J_\text{val}(c_s^*) $$
The skill database tracks the history of previous skills, context functions and eval metrics $\mathcal{H}{k-1} = {(s_i,c_i,J_i^\text{train}, J_i^\text{val})}{i=1}^{k-1}$. A meta-level agent performs agentic crossover over prior skills to create a new skill given a task $\tau$: $s_k=\text{crossover}(\tau,\mathcal{H}_{k-1})$.
Then a base-level context engineer executes the skill $s_k$ and learns the context function from rollout feedback $\mathcal{R}k$, guided by the current skill: $c_k=\text{engineer}(\tau,s_k;c{k-1}^*,\mathcal{R}_k)$.
为了防止在迭代重写过程中上下文崩溃和简洁性偏差,ACE的一个关键设计是策展人不重写整个提示块。而是输出一组结构化的、逐项列出的要点,形式为(标识符,描述),这些要点通过确定性逻辑合并到结构化的上下文日志簿中。上下文项会定期精炼和去重。
ACE从执行中学习见解有助于我们走向自我管理记忆,但更新规则和整体工作流仍是手工打造的。为了走向更自我改进的循环,元上下文工程(MCE;Ye et al. 2026)将机制(如何管理上下文)与工件内容(上下文中有什么)分离,在元优化层面运行技能进化,在基础层面运行上下文优化。
MCE技能 $s \in \mathcal{S}$ 定义一个上下文函数 $c_s=(\rho_s,F_s)$,并将输入 $x$ 映射到上下文 $c = F_s(x;\rho_s)$,其中:
$\rho_s = {\rho_1,\dots,\rho_m}$ 是静态组件(提示、知识库、代码库)。
$F_s = {F_1,\dots,F_k}$ 是动态算子(搜索、选择、过滤、格式化)。
双层优化是在给定技能 $s$ 的情况下,在训练数据上找到最佳上下文 $c_s^*$,而外层循环找到在验证集上提供最佳性能的最优技能:
$$ \text{内层:}c_s^=\arg\max_{c_s}J_\text{train}(c_s;s)\quad \text{外层:}s^=\arg\max_{s\in\mathcal{S}}J_\text{val}(c_s^*) $$
技能数据库跟踪以前技能、上下文函数和评估指标的历史 $\mathcal{H}{k-1} = {(s_i,c_i,J_i^\text{train}, J_i^\text{val})}{i=1}^{k-1}$。元级智能体对先前的技能执行智能体交叉,以创建给定任务 $\tau$ 的新技能:$s_k=\text{crossover}(\tau,\mathcal{H}_{k-1})$。
然后,基础级上下文工程师执行技能 $s_k$,并从执行反馈 $\mathcal{R}k$ 中学习上下文函数,由当前技能引导:$c_k=\text{engineer}(\tau,s_k;c{k-1}^*,\mathcal{R}_k)$。
Meta-Harness (Lee et al. 2026) moves another level deeper: the optimized object is the code that determines and optimizes what information should be stored, retrieved, and presented to the model. “Meta-” in its name means it is a harness for optimizing harnesses.

The Meta-Harness outer-loop optimization algorithm. (Image source: Lee et al. 2026)
The proposer for creating a new harness is itself a coding agent and the final output is a collection of harness candidates on the Pareto frontier.
The entire execution history is accessible via a file system, and thus the coding agent uses commands like grep or cat to read through it instead of shoveling everything into a single prompt context.
The proposed harness is a dictionary in the file system containing its own source code, scores, rollout trajectories, and state updates.
The mete-harness loop iteratively creates new harnesses, and only qualified ones are kept.

The performance of Meta-Harness on (Left) text classification with a small number of iterations and (Right) TerminalBench-2. Note that the search in the TerminalBench-2 experiment is initialized from Terminus-KIRA and Terminus-2, two very strong harnesses. (Image source: Lee et al. 2026)
Still, the important lesson is clear: once harness design becomes an executable search space, a strong coding agent can exploit the same design space human engineers use.
元Harness(Lee et al. 2026)又深入了一层:优化的对象是决定和优化哪些信息应被存储、检索并呈现给模型的代码。其名称中的“元”意味着这是一个用于优化harness的harness。

元Harness的外层循环优化算法。(图片来源:Lee et al. 2026)
创建新harness的提议者本身就是一个编码智能体,最终输出是帕累托前沿上的一组合格harness候选。
整个执行历史可通过文件系统访问,因此编码智能体使用grep或cat等命令读取,而不是将所有内容塞入单个提示上下文。
提议的harness是文件系统中的一个字典,包含其自身的源代码、得分、执行轨迹和状态更新。
元harness循环迭代创建新harness,仅保留合格的。

元Harness在(左)少量迭代下的文本分类和(右)TerminalBench-2上的表现。注意TerminalBench-2实验中的搜索从Terminus-KIRA和Terminus-2(两个非常强的harness)初始化。(图片来源:Lee et al. 2026)
然而,重要的教训是清晰的:一旦harness设计成为一个可执行的搜索空间,一个强大的编码智能体就能利用人类工程师所使用的同一设计空间。
Workflow design in harness engineering can be handcrafted by domain experts. Taking auto-research as an example, various frameworks have been proposed and tested. The AI Scientist system (Lu et al. 2026) builds a pipeline to propose research ideas, write code, run experiments, analyze results, write a manuscript, and perform peer review. Meng et al. (2026) make verifiability the central design constraint in ScientistOne, where every claim (citation, numerical, methodological, conclusion) must trace to an evidence source and is audited by Chain-of-Evidence checks.
Harness工程中的工作流设计可由领域专家手工完成。以自动研究为例,已有多种框架被提出和测试。AI科学家系统(Lu et al. 2026)构建了一个管道,用于提出研究想法、编写代码、运行实验、分析结果、撰写手稿并执行同行评审。Meng et al.(2026)将可验证性作为ScientistOne的核心设计约束,其中每个声明(引用、数字、方法、结论)都必须追溯到证据来源,并通过证据链检查进行审计。
The Autodata agent (Kulikov et al. 2026) is designed to work as a data scientist for generating training and evaluation data. The main agent manages a challenger that proposes problems, a weak solver, a strong solver, and a verifier/judge, aiming to synthesize data at the “just right” level of difficulty, meaning that the strong solver succeeds but the weak solver fails.
In Autodata, the challenger prompt is updated iteratively according to feedback from the solvers and verifier. The limitation here is that synthesized tasks are used to fine-tune weak solvers but not strong solvers; if the loop cannot iteratively improve the strong model, it is more like indirect distillation over a generated prompt distribution, with less RSI flavor.

Autodata agentic workflow design for generating synthetic training and evaluation data around challenger, solver, and verifier roles. (Image source: Kulikov et al. 2026)
Autodata智能体(Kulikov et al. 2026)被设计为数据科学家,用于生成训练和评估数据。主智能体管理一个挑战者(提出问题的智能体)、一个弱求解器、一个强求解器和一个验证器/评判者,旨在合成“恰到好处”难度的数据,即强求解器成功而弱求解器失败。
在Autodata中,挑战者提示会根据求解器和验证器的反馈进行迭代更新。局限性在于合成任务仅用于微调弱求解器而非强求解器;如果循环无法迭代改进强模型,它更像是生成提示分布上的间接蒸馏,RSI的味道较少。

Autodata智能体工作流设计,围绕挑战者、求解器和验证者角色生成合成训练和评估数据。(图片来源:Kulikov et al. 2026)
The design space for workflow is enormous, and naturally we can think of workflow design as a search problem, and therefore we should be able to find good solutions by algorithms rather than only manually craft them. Following this direction, Automated Design of Agentic Systems (ADAS; Hu et al. 2025) formulates agent design itself as an optimization problem, “meta-agent search” where a meta-agent proposes new designs of agentic workflows.
Initialize an archive of agentic workflows with simple agents such as CoT and self-refine.
Ask a meta-agent to program new agents, all in code, inspired by existing solutions in the archive.
The meta-agent first generates a high-level description of the new workflow, and then implements it in code.
The draft program then goes through two self-refine steps (i.e. ask the model to provide feedback and then ask the same model to refine the previously generated outputs based on the feedback; Madaan et al. 2023) by the meta-agent to check its novelty.
Evaluate each new candidate and add successful ones back to the archive.
Repeat steps 2-3 until the maximum iteration count is reached.
工作流的设计空间巨大,很自然地,我们可以将工作流设计视为一个搜索问题,因此应该能够通过算法而非仅靠手工找到好的解决方案。沿着这个方向,智能体系统的自动设计(ADAS;Hu et al. 2025)将智能体设计本身表述为一个优化问题,即“元智能体搜索”,其中元智能体提出新的智能体工作流设计。
用一个由简单智能体(如CoT和自精炼)组成的智能体工作流存档进行初始化。
要求元智能体以代码形式编写新的智能体,受存档中现有解决方案的启发。
元智能体首先生成新工作流的高级描述,然后用代码实现。
草稿程序然后经过两个自精炼步骤(即让模型提供反馈,然后让同一模型基于反馈精炼先前生成的输出;Madaan et al. 2023),由元智能体检查其新颖性。
评估每个新候选,将成功的添加回存档。
重复步骤2-3,直到达到最大迭代次数。
AFlow (Zhang et al. 2025) represents an agentic workflow as a graph, where nodes represent LLM-invoking actions and edges implement logical operations in code. The workflow optimization relies on MCTS (Monte Carlo Tree Search):
Initialize the starting workflow $W_0$ in the tree with a template.
Select a workflow node using a soft mixture of score and uniform exploration.
Expand it by asking an LLM to produce a modified workflow conditioned on its evaluation performance.
Execute and evaluate the new workflow.
Add it back to the tree if the new workflow shows improvement within a budget of $N$ rounds.
Repeat steps 2-5 and stop when the top-$k$ average score plateaus or hit the budget.

AFlow optimization process over a tree of workflow candidates. (Image source: Zhang et al. 2025)
Experiments of AFlow in QA, code, and math tasks showed decent improvement of AFlow over manually designed workflows and ADAS.

AFlow experiments in comparison to manual methods and ADAS. (Image source: Zhang et al. 2025)
AFlow(Zhang et al. 2025)将智能体工作流表示为一个图,其中节点代表调用LLM的动作,边实现代码中的逻辑操作。工作流优化依赖于MCTS(蒙特卡洛树搜索):
在树中以模板初始化起始工作流 $W_0$。
使用得分与均匀探索的软混合选择一个工作流节点。
通过请求LLM生成一个基于其评估性能的修改工作流来扩展它。
执行并评估新工作流。
如果新工作流在 $N$ 轮预算内显示出改进,则将其添加回树中。
重复步骤2-5,直到top-$k$平均得分停滞或达到预算。

AFlow在工作流候选树上的优化过程。(图片来源:Zhang et al. 2025)
AFlow在QA、代码和数学任务上的实验显示,其比手工设计的工作流和ADAS有显著改进。

AFlow与手工方法和ADAS的实验对比。(图片来源:Zhang et al. 2025)
Either context engineering or workflow design is only one part of a harness. We need to search through the entire design space and optimize context-management logic, workflow, permissions, and many other harness components together. As we have seen in work like Meta-Harness, ADAS, and AFlow, ✨code✨ is a universal language for defining programs and systems. In simple words, a harness is code that programs how prompts, tool calls, subagents, control flow, memory, and workflow logic work together. If an LLM can optimize the code that executes agents, it can access a much larger design space than hand-written prompts.
无论是上下文工程还是工作流设计,都只是harness的一部分。我们需要搜索整个设计空间,并同时优化上下文管理逻辑、工作流、权限以及许多其他harness组件。正如我们在Meta-Harness、ADAS和AFlow等工作中所见,✨代码✨是定义程序和系统的通用语言。简单来说,harness就是代码,它编程了提示、工具调用、子智能体、控制流、记忆和工作流逻辑如何协同工作。如果LLM能够优化执行智能体的代码,它就能访问比手写提示大得多的设计空间。
Self-Taught Optimizer (STOP; Zelikman et al. 2023) is one of the early examples of recursive scaffolding improvement. A seed improver $I_0$ at step $t=0$ takes an initial solution $s$, a utility function $u$, and a black-box language model $M$, and returns an improved solution $s’$, that is, $s’ = I(u, s; M)$. The goal of STOP is not directly to improve $s$ but to improve the improver $I$ itself.
First, let’s define the meta-utility as the average utility of a given improver function $I$ over a collection of downstream tasks $\mathcal{D}$:
$$ \hat{u}(I) \triangleq \frac{1}{\vert\mathcal{D}\vert}\mathbb{E}_{(u,s)\sim \mathcal{D}}[u(I(u,s; M))] $$
Because improving the improver function is an optimization problem itself, we can recursively get a new version of $I_t$ based on $I_{t-1}$’s performance measured by meta-utility via a self-improvement update:
$$ I_t=I_{t-1}(\hat{u},I_{t-1};M) $$
In Zelikman et al. (2023)’s experiments, the improved improver discovered various strategies, such as genetic algorithms, decomposing and improving parts, multi-armed prompt bandits, simulated annealing, varying temperature, and beam/tree search. This is analogous to how a harness workflow can be represented as an object for optimization.
A cautionary result in their findings is that STOP improved mean downstream performance across iterations with GPT-4 but degraded with weaker models like GPT-3.5 and Mixtral. Recursive structure alone is not enough. The base model must be capable enough to improve the mechanism. This implies that harness improvement enables better deployment of the model but intelligence is still the core.
自我教导优化器(STOP;Zelikman et al. 2023)是递归脚手架改进的早期例子之一。种子改进器 $I_0$ 在步骤 $t=0$ 时接受初始解决方案 $s$、效用函数 $u$ 和黑盒语言模型 $M$,并返回改进后的解决方案 $s’$,即 $s’ = I(u, s; M)$。STOP的目标不是直接改进 $s$,而是改进改进器 $I$ 本身。
首先,将元效用定义为给定改进器函数 $I$ 在一组下游任务 $\mathcal{D}$ 上的平均效用:
$$ \hat{u}(I) \triangleq \frac{1}{\vert\mathcal{D}\vert}\mathbb{E}_{(u,s)\sim \mathcal{D}}[u(I(u,s; M))] $$
由于改进改进器函数本身就是一个优化问题,我们可以通过自我改进更新,基于 $I_{t-1}$ 由元效用衡量的性能,递归地获得 $I_t$ 的新版本:
$$ I_t=I_{t-1}(\hat{u},I_{t-1};M) $$
在Zelikman等人(2023)的实验中,改进后的改进器发现了多种策略,例如遗传算法、分解和改进各部分、多臂提示老虎机、模拟退火、变温度和束/树搜索。这类似于harness工作流可以表示为优化对象的方式。
他们发现的一个警示性结果是,STOP在GPT-4上迭代改进了平均下游性能,但在较弱的模型如GPT-3.5和Mixtral上性能下降。仅有递归结构是不够的。基础模型必须足够有能力才能改进机制。这意味着harness改进有助于更好地部署模型,但智能仍是核心。
A more recent work, Self-Harness (Zhang et al. 2026), relies on LLM agents to improve their own harness via a propose-evaluate-accept loop.

Self-Harness uses a loop of weakness mining, bounded harness proposal, and validation to update a harness. (Image source: Zhang et al. 2026)
The loop in Self-Harness has three stages:
Weakness mining: cluster failures into verifier-grounded failure patterns.
The current harness $h_t$ is used to evaluate on tasks and execution traces are collected for analysis.
Note that two runs can share the same verifier outcome in the error logs on the surface, such as timeout or missing artifact, while having different causal mechanisms. Therefore we need a failure record of rich information, containing the terminal verifier-level cause, the causal status of the relevant agent behavior, and the abstract agent mechanism exposed by the trace, to uncover the root causes.
Harness proposal: propose bounded harness edits based on mined failure patterns.
The same model is invoked under $h_t$ as a proposer.
The model is provided with a bounded proposal context: (1) the editable surfaces of the current harness, (2) the verifier-grounded failure patterns from the evaluation system, (3) records of passing behaviors that should be preserved, and (4) summaries of previously attempted edits.
Harness edits should prefer recurrent error patterns that are addressable (e.g. not task-specific difficulty) and can be resolved by narrow changes.
Harness edit candidates should be distinct and diverse.
Proposal validation: validate and merge qualified edits to create a new harness $h_{t+1}$.
Candidate edits are evaluated by regression tests on held-in $D_\text{in}$ (for testing whether the weakness is resolved) and held-out $D_\text{out}$ (for checking whether other unknown issues were introduced) splits.
Candidates are accepted only if they have no regression on both held-in and held-out data.
Accepted candidates are merged to update the harness to $h_{t+1}$, while rejected candidates are logged without changing the active harness.
When running MiniMax M2.5, Qwen3.5-35B-A3B, and GLM-5 on Terminal-Bench-2, Self-Harness was shown to learn model-specific harness instructions that target at different weaknesses of different base models and improve held-out pass rates.
较新的工作Self-Harness(Zhang et al. 2026)依赖LLM智能体通过提议-评估-接受循环来改进自身的harness。

Self-Harness使用弱点挖掘、有界harness提议和验证的循环来更新harness。(图片来源:Zhang et al. 2026)
Self-Harness的循环包含三个阶段:
弱点挖掘:将失败聚类为基于验证器的失败模式。
当前harness $h_t$ 用于评估任务,收集执行轨迹进行分析。
注意,两次运行可能在错误日志表面共享相同的验证器结果(如超时或缺失工件),但具有不同的因果机制。因此,我们需要包含丰富信息的失败记录,包括终端验证器级原因、相关智能体行为的因果状态以及轨迹暴露的抽象智能体机制,以揭示根本原因。
Harness提议:基于挖掘到的失败模式提出有界的harness编辑。
使用同一模型在 $h_t$ 下作为提议者。
向模型提供有界的提议上下文:(1)当前harness的可编辑表面,(2)评估系统中的基于验证器的失败模式,(3)应保留的通过行为记录,以及(4)先前尝试编辑的摘要。
Harness编辑应优先选择可解决的重复错误模式(例如,非任务特定难度),并能通过狭窄的更改解决。
Harness编辑候选应独特且多样。
提议验证:验证并合并合格的编辑以创建新harness $h_{t+1}$。
候选编辑通过在保留集 $D_\text{in}$(测试弱点是否解决)和保留外集 $D_\text{out}$(检查是否引入其他未知问题)上的回归测试进行评估。
仅当候选在保留集和保留外数据上都无回归时,才被接受。
接受的候选被合并以更新harness到 $h_{t+1}$,而被拒绝的候选被记录,不改变当前活动的harness。
当在Terminal-Bench-2上运行MiniMax M2.5、Qwen3.5-35B-A3B和GLM-5时,Self-Harness被证明能学习特定于模型的harness指令,针对不同基础模型的不同弱点,并提高保留外通过率。
Self-harness type of work does raise my concerns that if a program is allowed to edit the OS system, abstraction boundaries are broken. The editable surface needs to be properly designed and the permission control and security layers need to live outside this loop. All the challenges around reward hacking still remain.
Self-Harness这类工作确实引发了担忧:如果允许程序编辑操作系统,抽象边界就会被打破。可编辑表面需要恰当地设计,权限控制和安全层需要位于这个循环之外。所有关于奖励黑客的挑战仍然存在。
Evolutionary search is an optimization method inspired by natural selection (see my old post on evolutionary algorithm). It evolves a population of solutions by mutating them and only keeping those with high “fitness” in the crowd. Evolutionary search comes in handy when (1) the search space is extensive or weirdly shaped; and (2) it is hard to optimize directly with gradients but easy to evaluate solutions. Harness search seems to be a good fit here.
进化搜索是一种受自然选择启发的优化方法(见我之前关于进化算法的文章)。它通过变异解决方案并只保留种群中“适应度”高的个体来进化。进化搜索在以下情况中很有用:(1)搜索空间广阔或形状怪异;(2)难以直接用梯度优化但容易评估解决方案。Harness搜索似乎很适合这里。
Evolutionary search has been used in prompt engineering in the past studies. Promptbreeder (Fernando et al. 2023) optimizes task-specific prompts through a rich set of mutation operations, and interestingly the mutation prompts (i.e. instructions to an LLM to mutate a task prompt) are themselves also improved through evolution. GEPA (Agrawal et al. 2025) combines reflection-based prompting with evolutionary search and uses natural language reflection over trajectories of trial and error to propose prompt updates.
进化搜索已在过去的研究中用于提示工程。Promptbreeder(Fernando et al. 2023)通过丰富的变异操作集优化任务特定提示,有趣的是,变异提示(即指导LLM变异任务提示的指令)本身也通过进化得到了改进。GEPA(Agrawal et al. 2025)将基于反思的提示与进化搜索相结合,利用对试错轨迹的自然语言反思来提出提示更新。
Novikov et al. (2025) introduced AlphaEvolve as a coding-agent evolutionary search system, which stores a pool of candidate programs and prompts frozen LLMs to generate diffs for improvement. As the system repeatedly evaluates child programs and keeps successful ones, it discovers better solutions in time.
A few details matter in the design of AlphaEvolve:
The prompt includes parent programs, results, instructions, and sometimes meta information.
The coding agent has access to the full repo, but code regions for improvement are explicitly marked with # EVOLVE-BLOCK-START and # EVOLVE-BLOCK-END.
Meta-prompt co-evolves with instructions and context as suggested by LLM, in a similar way as how we evolve solution programs.
Ablations show the evolution procedure, context in prompts, meta-prompts, full-file evolution and the use of stronger LLMs.
Recent variants such as ThetaEvolve (Wang et al. 2025) combines evolutionary search with RL and in-context learning. ShinkaEvolve (Lange et al. 2025), on the other hand, introduced three new components to improve LLM sampling efficiency:
More sample-efficient exploration by designing parent sampling to balance performance rank and offspring count.
Code-novelty rejection sampling by discarding candidates that are too similar to the existing population based on embedding-based cosine similarity.
Identifying good patterns in successful solutions in a meta-scratchpad to guide future mutation.
Novikov等人(2025)引入了AlphaEvolve,一个编码智能体进化搜索系统,它存储一个候选程序池,并提示冻结的LLM生成用于改进的差异。随着系统反复评估子程序并保留成功的,它会及时找到更好的解决方案。
AlphaEvolve设计中的几个关键细节:
提示包含父程序、结果、指令,有时还有元信息。
编码智能体可以访问整个仓库,但改进的代码区域明确用 # EVOLVE-BLOCK-START 和 # EVOLVE-BLOCK-END 标记。
元提示与指令和上下文共同进化,由LLM建议,类似于我们进化解决方案程序的方式。
消融实验显示了进化过程、提示中的上下文、元提示、全文件进化以及使用更强LLM的价值。
最近的变体如ThetaEvolve(Wang et al. 2025)将进化搜索与RL和上下文内学习相结合。ShinkaEvolve(Lange et al. 2025)则引入了三个新组件来提高LLM采样效率:
通过设计父采样以平衡性能排名和后代数量,实现更高效的探索。
代码新颖性拒绝采样,基于嵌入的余弦相似度丢弃与现有种群过于相似的候选。
在元暂存区中识别成功解决方案中的良好模式,以指导未来变异。
Unlike the methods above, which focus on solution improvement, Darwin Gödel Machine (DGM; Zhang et al. 2025) explicitly targets the evolution of an editable harness-code repository with an LLM-based coding agent. Precisely, this agent is allowed to modify its own harness. A follow-up work on Hyperagents (Zhang et al. 2026) introduced a meta-agent to control how to modify existing task agents to create new ones.
Start with one coding agent in the pool.
In each iteration, pick one parent with a probability proportional to its performance and inversely to the number of children it has, to modify and branch off to produce new agents.
The selected parent agent examines its own benchmark evaluation log and then proposes improvements to its own harness codebase to generate a new version of the coding agent. Code editing is implemented with two basic tools: (1) bash (args: <bash_command>) and (2) editor (args: view/create/edit <file_path>).
New coding agents are evaluated, and only those with sufficiently high performance are added back into the pool.
Repeat steps 2-4 until some stop criteria hit.
DGM is harness evolution under a fixed model. In experiments with Claude 3.5 Sonnet as the base LLM and simple initial harness configs, the DGM-discovered agents are comparable to or outperform handcrafted agents on SWE-bench Verified (20% to 50%) and Polyglot (14.2% to 30.7%).
This family of methods works well when candidate solutions are automatically evaluable and candidate fitness is easy to quantify, such as matrix multiplication, GPU kernel optimization, algorithm contests, datacenter scheduling. It struggles with domains where evaluation is slow, ambiguous, or mostly heuristic-based. The compute efficiency and effectiveness of evolution are also concerns.
与上述侧重于解决方案改进的方法不同,达尔文-哥德尔机器(DGM;Zhang et al. 2025)明确针对可编辑的harness代码仓库的进化,使用基于LLM的编码智能体。确切地说,该智能体被允许修改自身的harness。后续工作Hyperagents(Zhang et al. 2026)引入了一个元智能体来控制如何修改现有任务智能体以创建新的智能体。
从池中的一个编码智能体开始。
每次迭代,选择一个父智能体,选择概率与其性能成正比、与其子代数量成反比,对其进行修改并分支以产生新的智能体。
被选中的父智能体检查自身的基准评估日志,然后对其自身的harness代码库提出改进,以生成新版本的编码智能体。代码编辑通过两个基本工具实现:(1)bash(参数:<bash_command>)和(2)editor(参数:view/create/edit <file_path>)。
评估新编码智能体,仅将性能足够高的加入池中。
重复步骤2-4,直到达到某个停止条件。
DGM是在固定模型下的harness进化。在使用Claude 3.5 Sonnet作为基础LLM和简单初始harness配置的实验中,DGM发现的智能体在SWE-bench Verified(20%到50%)和Polyglot(14.2%到30.7%)上与手工制作的智能体相当或更优。
这类方法在候选解决方案可自动评估且候选适应度易于量化时效果良好,例如矩阵乘法、GPU内核优化、算法竞赛、数据中心调度。它在评估缓慢、模糊或主要基于启发式的领域则表现不佳。进化计算效率和有效性也是问题。
Harness evolution changes the non-parametric system around the model. To enable full self-improvement, the model can totally be allowed to update its own weights at the same time. The weight update can be implemented via improvements in the model training pipeline or continual learning at test time. The topic of continual learning is worthy of its own post in the future.
SIA (Hebbar et al. 2026) is an early attempt to combine harness improvement and model-parameter updates in the same optimization loop, with three components in the design:
Meta-Agent: proposes the initial harness.
Task-Specific Agent: executes the task.
Feedback-Agent: chooses whether to update the harness or the model weights based on recent trajectories.
There are a few confounding choices in SIA’s experiments that make the results hard to interpret. For example, the task-specific agent is much weaker than the models used for the Meta-Agent and Feedback-Agent (gpt-oss-120b vs Claude Sonnet 4.6), and the baselines are too weak to cross-reference cleanly against related methods. I would consider the direction interesting, but the evidence provisional. Yet many challenges, such as training stability and Goodhart effect, still remain open.
Harness进化改变的是模型周围的非参数化系统。为了实现完全自我改进,模型完全可以同时更新自身的权重。权重更新可以通过改进模型训练流程或在测试时进行持续学习来实现。持续学习的主题值得未来专门撰写一篇文章。
SIA(Hebbar et al. 2026)是早期尝试将harness改进和模型参数更新结合在同一个优化循环中的工作,设计包含三个组件:
元智能体:提出初始harness。
任务特定智能体:执行任务。
反馈智能体:根据最近的轨迹选择是更新harness还是模型权重。
SIA的实验中有一些混淆因素使得结果难以解释。例如,任务特定智能体远弱于用于元智能体和反馈智能体的模型(gpt-oss-120b 对比 Claude Sonnet 4.6),且基线太弱,无法与相关方法进行干净交叉参考。我认为这个方向很有趣,但证据是初步的。尽管如此,许多挑战(如训练稳定性和古德哈特效应)仍然悬而未决。
Toward full RSI, researchers have made real progress, but several bottlenecks remain.
- Weak and fuzzy evaluators. Many research claims do not have a fast and precise verifier, and the same is true for many real-world tasks. Current self-improvement loops work best for tasks when evaluation metrics are measurable and objective, similar as how RL works.
Research taste, novelty, and long-term scientific value are much harder to measure. For example, research taste often mixes problem framing, experimental design, and judgment about which surprising results are worth pursuing and which failure cases are worth retries.
迈向完全RSI,研究人员取得了实际进展,但仍存在几个瓶颈。
- 薄弱且模糊的评估器。许多研究主张没有快速且精确的验证器,许多现实任务也是如此。当前的自我改进循环在评估指标可测量且客观的任务中效果最佳,类似于RL的工作方式。
研究品味、新颖性和长期科学价值更难衡量。例如,研究品味通常混合了问题框架、实验设计以及对哪些令人惊讶的结果值得追求、哪些失败案例值得重试的判断。
- Context and memory lifecycle. Memory grows as AI agents become more autonomous and independent. A useful harness needs to manage context and memory to complement existing limitation in long-context generation while still maximizing the success of long-horizon tasks. Since humans are able to maintain memory through our life time, I see an anoloy here that context engineering will and should become a core part of intelligence, rather than staying in the software system layer.
- 上下文与记忆生命周期。随着AI智能体变得更加自主和独立,记忆也在增长。一个有用的harness需要管理上下文和记忆,以补充现有长上下文生成的局限性,同时最大化长周期任务的成功率。既然人类能够终身维持记忆,我认为这里存在类比:上下文工程将且应该成为智能的核心部分,而非停留在软件系统层。
-
Negative results. Researchers are incentivized to publish successful results and thus literature is biased toward successes. LLMs trained on a vast amount of data (mostly human created, at least for now, lol) may be bad at deciding when to abandon a hypothesis, report a negative result, or even acknowledge a failure due to the imablance of success vs failure cases in data. A research harness should make failed attempts easy to preserve, as learning from failure is the best way to trim down the task search space.
-
Diversity collapse. Evolutionary and RL loops tend to exploit known high-reward patterns. We need mechanisms to prevent the population from collapsing into variants of the same solution. This is especially critical for open-ended research, where the best path may initially look worse under the current evaluator.
-
负面结果。研究人员有动机发布成功结果,因此文献偏向于成功。在大量数据(至少目前主要是人类创建的数据,哈哈)上训练的LLM可能不擅长决定何时放弃假设、报告负面结果,甚至承认失败,因为数据中成功与失败案例不平衡。一个研究harness应使失败尝试易于保存,因为从失败中学习是缩小任务搜索空间的最佳方式。
-
多样性崩溃。进化和RL循环倾向于利用已知的高奖励模式。我们需要机制防止种群崩溃为同一解决方案的变体。这对开放式研究尤为关键,因为最佳路径在当前评估器下最初可能看起来更差。
- Reward hacking. A self-improvement loop optimizes whatever signal it is given. If the reward comes from unit tests, the agent may overfit to tests; if it comes from a judge model, it may learn reward hacking tricks specific to this judge; if it comes from benchmark scores, it may exploit benchmark artifacts.
The evaluator and permission control should likely sit outside the loop that evolves harness, with held-out tests, trace audits, and human review at decision points that matter—how much oversight can be scaled up and automated remains an open research area.
- Long-term success. An extrinsic loop of optimization works on rewards outside of individual rollouts that we can simulate in training sandbox.
Take coding agent as an example. Coding agents have already increased daily productivity in software engineering, but many optimization goals are still too short-term. It can often complete the task at hand, but less obvious how it should protect the long-term health of a repo collectively maintained by hundreds or thousands of engineers. Standard sandbox-based RLVR-style training rarely captures maintainability, ownership boundaries, migration cost, backwards compatibility, or future debugging burden.
- 奖励黑客。自我改进循环会优化它接收到的任何信号。如果奖励来自单元测试,智能体可能会过拟合测试;如果来自评判模型,它可能会学习针对该评判者的奖励黑客技巧;如果来自基准分数,它可能会利用基准的缺陷。
评估器和权限控制应位于进化harness的循环之外,使用保留测试、轨迹审计和在重要决策点上的人工审查——可在多大程度上扩大和自动化监督仍是一个开放的研究领域。
- 长期成功。外在优化循环作用于单个执行之外我们可以在训练沙盒中模拟的奖励。
以编码智能体为例。编码智能体已经提高了软件工程的日常生产力,但许多优化目标仍然过于短期。它通常能完成手头任务,但不太清楚应如何保护由数百或数千名工程师共同维护的仓库的长期健康。基于沙盒的标准RLVR式训练很少捕捉可维护性、所有权边界、迁移成本、向后兼容性或未来的调试负担。
- The role of humans. Humans should move up the stack, not be removed from the loop, meaning that human should provide oversight at the right time, at the right abstraction level and our system design should consider when and how to set up such touch points.
Many challenges listed above need human’s feedback and steering. After all, we are building the technology for better future of humanity, not other way around.
Citation
Please cite this work as:
Weng, Lilian. “Harness Engineering for Self-Improvement”. Lil’Log (Jul 2026). https://lilianweng.github.io/posts/2026-07-04-harness/
Or use the BibTeX citation:
@article{weng2026harness, title = {Harness Engineering for Self-Improvement}, author = {Weng, Lilian}, journal = {lilianweng.github.io}, year = {2026}, month = {July}, url = "https://lilianweng.github.io/posts/2026-07-04-harness/" }
Appendix: Some useful benchmarks
- 人类角色。人类应向上移动层级,而非被移除出循环,这意味着人类应在正确的时间、正确的抽象级别提供监督,我们的系统设计应考虑何时以及如何设置这样的接触点。
上面列出的许多挑战需要人类的反馈和引导。毕竟,我们是为了人类更美好的未来而构建技术,而不是相反。
引用
请按以下方式引用本文:
Weng, Lilian. “Harness Engineering for Self-Improvement”. Lil’Log (Jul 2026). https://lilianweng.github.io/posts/2026-07-04-harness/
或使用BibTeX引用:
@article{weng2026harness, title = {Harness Engineering for Self-Improvement}, author = {Weng, Lilian}, journal = {lilianweng.github.io}, year = {2026}, month = {July}, url = "https://lilianweng.github.io/posts/2026-07-04-harness/" }
附录:一些有用的基准