Harness Engineering:从提示词到可问责的智能体循环
一个能长期工作的智能体,并不是“模型加一段 prompt”。它是一个运行系统:在有限上下文里选择信息,调用工具,保存工件,执行权限策略,管理预算和失败恢复,并把结果交给 agent 无法改写的 evaluator。Harness Engineering(智能体运行支架工程)研究的正是这一层。
模型 + harness 版本 + 环境 + 工具/权限策略 + evaluator + 预算。因此,一次 pass rate 上升并不能单独说明“模型变强了”,也不能说明更复杂的 orchestration 一定有效。
1. 这篇文章不做什么
这不是产品横评,也不是“更多子 agent 必然更好”的宣言,更不是 RSI 已经达成的主张。已有的Coding Agents 架构对比解释六个具体系统怎样运行;本文换一个问题:我们应该怎样设计、约束并评估 harness 本身?
这里的“工程”有两个边界:
- Agent harness(智能体运行支架) 是围绕模型的运行时:上下文、工具、状态、控制流、权限、日志和恢复。
- Evaluation harness(评测支架) 是配置任务、执行试验、收集证据并计算结果的基础设施。它不能被待测 agent 当作可编辑工具。
如果这两个概念混在一起,就会出现一个危险的模糊说法:“agent 得分提高了”。读者无法判断是模型、提示、工具、环境、预算还是评分器变了。
2. 先画出可问责的边界
这张图不是某个已发布系统的结构图,而是一条设计立场:模型可以提出行动,harness 可以安排行动,但权限与接受标准不能藏在 prompt 的一句“请小心”里。MCP 为 tools、resources、prompts 等交互对象提供协议边界;它并不自动使工具输出可信,也不替代宿主的权限控制。MCP Specification
3. 六个工程平面
3.1 契约:工具不是函数名的集合
工具是非确定性模型与有状态服务之间的契约。一个可评估的工具面应让输入 schema、权限、错误、幂等性与返回范围都可见;工具之间的功能重叠越大,agent 越容易用偶然路径得到不可复现的结果。Anthropic 的工具设计指南建议在真实多步任务上测试工具,并用保留任务检查是否只对开发轨迹过拟合。Writing tools for agents
可检验的问题不是“工具多不多”,而是:在相同权限和预算下,任务形状化的窄工具是否降低无效调用、token 浪费或安全违规,同时不牺牲保留任务成功率。
3.2 状态:把记忆变成工件,而不是越塞越长的上下文
Context engineering(上下文工程)是每次调用所见 token 状态的选择与维护;它不等于增加 context window,更不等于把所有历史日志塞回 prompt。长程系统需要把任务清单、进度、测试、候选工件、依赖和版本历史保存为可检索的外部工件。这样一个新 session 才能依据同一证据继续工作,而不是猜测前一轮发生过什么。
要特别区分三个词:
| 名称 | 它保存什么 | 它不能保证什么 |
|---|---|---|
| Context compaction / 上下文压缩 | 当前对话的摘要或选择后的上下文 | 原始环境可以恢复 |
| Session handoff / 会话交接 | 让新上下文接手的状态清单、工件位置、未决问题 | 之前的动作可安全重放 |
| Checkpoint / 检查点 | 可重新启动的环境状态、配置和工件版本 | 外部服务或实时网页保持不变 |
关于长程 harness 的公开工程实践强调了 feature list、进度文件、测试、初始化命令和版本历史:它们让新的执行者能从工件重建状态,而不是依赖不可见的聊天记忆。Effective harnesses for long-running agents
3.3 权限:authority 必须由运行时执行
Prompt 可以表达偏好,不能单独构成权限边界。一个严肃的 authority policy 至少应列出:可读写路径、允许域名、凭据作用域、危险动作类别、审批点、资源上限、网络出口和审计保留期。沙箱隔离与网络控制是运行时机制,不是礼貌性指令;这也是为什么官方 sandboxing 设计同时讨论文件系统与网络边界。Claude Code sandboxing
这带来一条简单但重要的规则:agent 可以提议扩大权限或修改 policy,但它不能自行批准该变更,更不能同时改写 evaluator 并宣布自己通过。这个规则同样适用于浏览器、Computer Use、terminal 和训练 harness。
3.4 控制:并行是一项待验证的调度策略
并行子 agent 能拓宽检索和独立执行的覆盖面,也会放大 token、协调与合并成本。它只适合可明确拆分、输出契约稳定的子问题;同一代码面或强耦合决策常常需要共享的主控上下文。公开的多 agent 研究系统也报告了更宽探索带来的显著 token 开销,并强调协调方式会影响结果。Multi-agent research system
因此父 agent 应拥有:全局预算、任务切分、取消权、合并权和最终发布权。子 agent 应拥有:窄目标、隔离工作区、明确交付物和可审计结果记录。所谓“多 agent 更好”只有在相同模型、总预算与任务分布下,比较 sequential baseline 后才是可成立的经验结论。
3.5 证据:trace、replay 与 rerun 不是同义词
每次运行至少应记录 harness、模型、工具、环境与 policy 版本;初始状态 digest;输入输出与工具事件;批准/拒绝;工件哈希;重试与恢复;evaluator 输出;token、墙钟和资源用量。密钥、个人数据和第三方内容需要在保留之前脱敏。
这份 trace 支持三件不同的事:
- 诊断(diagnosis):为什么失败、为什么花费异常、哪一步触及权限。
- 观察式回放(observational replay):查看已发生的事件而不重放外部副作用。
- 执行式重跑(execution rerun):从冻结状态重新执行,并公开随机性和外部依赖控制。
只拥有录像或聊天记录,通常只支持第一项或第二项。对一个仍在变化的在线服务而言,不能把它称为“可复现 rerun”。
3.6 完整性:evaluator 是系统的一部分,却不属于优化面
确定性测试、模型 grader 和人工审查回答的不是同一个问题。确定性 verifier 适合检查明确终态;模型 grader 可以处理开放文本,但要校准并报告其误差;人工审查用来发现未建模的损害。关于 agent eval 的工程指南强调了任务、grader、样本和指标必须先被定义,再将结果解释为能力。Demystifying evals for AI agents
所以 harness 的改动应携带一个 change manifest:它预期改善什么、不会伤害什么、在哪个保留集上验收、何时回退。Harness-Bench 与 VeRO 等预印本探索了 configuration-level 或版本化 agent 评测;它们提供有价值的方法线索,但不证明复杂 harness 在所有任务上都更强,也不构成无界自我改进的证据。Harness-Bench · VeRO
4. 报告一个 harness,需要哪些表
| 维度 | 至少报告 | 不应省略的限定 |
|---|---|---|
| Outcome | 成功率、任务版本、grader、置信区间 | 单次成功不等于稳定行为 |
| Efficiency | token、工具调用、墙钟、GPU / sandbox 小时、每个成功任务成本 | 必须使用相同预算比较 |
| Reliability | 超时率、故障注入后的恢复率、resume latency、方差 | 说明重试与停止策略 |
| Governance | policy violation、误拦截、审批准确率 | 写清 threat model 与拦截面 |
| Observability | trace 完整率、脱敏失败、replay / rerun agreement | 指明是观察式还是执行式回放 |
| Parallelism | speedup、worker-hours、重复工作、合并冲突 | 与同预算 sequential baseline 比较 |
| Generalization | 保留任务变化、回归数、跨模型/任务迁移 | 最终测试集不进入优化循环 |
这张表让“harness 很好”变成一组可能失败的陈述。比如,更高的 pass rate 可能来自隐藏的重试、更多并发或不等的 token 预算;若不报告这些,读者无法把结果用于工程决策。
5. 当 harness 尝试改进自己时
Harness optimization 可以是很有价值的:系统分析失败轨迹,提出一个小的 context、tool 或控制流修改,在冻结评测上验证,保留或回退版本。但它仍不是自动的 RSI。要讨论更强的主张,修改后的 harness 必须让之后的改进过程在未参与选择的任务上持续更好;权限与 evaluator 也不能由候选版本自己授予或重写。
因此可接受的最小循环是:
- 人或外部 policy 冻结可改动面、预算、evaluator 与回退规则。
- agent 从失败谱系提出窄修改,并说明预期收益和回归风险。
- 独立 runner 在 capability 与 regression split 上执行,记录同预算证据。
- 外部 acceptance gate 合并、拒绝或回退;候选 harness 没有对 gate 的写权限。
这和RSI 文章的边界一致:改进一条 workflow 很有意义,但不应凭一次局部 gain 宣称已经改进了“改进者”。
6. 一个可公开讨论的 workshop 议程
下面是研究议程,不是已经宣布的活动、CFP 或赞助消息。
- Interfaces and environments。 工具协议、browser / computer actions、沙箱、可移植性与确定性验证。
- Memory and long-horizon execution。 context 生命周期、工件存储、检查点、恢复、持久任务与 replay。
- Governed autonomy。 capability scoping、身份、批准设计、prompt injection containment 与审计日志。
- Optimization and evaluation。 workflow search、多 agent 调度、harness evolution、trace analysis、evaluator integrity、成本与负结果。
一篇系统论文若声称 harness 改进,最少应交付版本化 harness/environment manifest、任务与 evaluator 版本、预算账本、trace/redaction 方案、同预算 baseline、关键消融、威胁模型和失败分析。这样的要求不会保证正确性,但能让论文的关键依赖暴露在读者面前。
7. 五个可被推翻的研究问题
| 假设 | 最小实验 | 推翻信号 |
|---|---|---|
| 结构化的外部 handoff 比只做 context compaction 更可靠 | 固定模型、任务、预算和环境状态,比较两种恢复路径 | 保留任务无完成/恢复收益,或成本更高 |
| 窄而任务化的工具优于广泛 API mirror | 在相同 authority 下比较成功率、无效调用与 token | 广工具同样好且无可靠性/成本代价 |
| 并行只在独立分支有收益 | 固定总 token 与 worker-time,比较 orchestration | 无速度/质量收益,或合并回归抵消收益 |
| 外部 acceptance gate 降低 harness 自改的回归 | 冻结 evaluator/policy,比较 versioned edit 与无约束 edit | 接受改动的回归率不降或 manifest 没有预测力 |
| 过程信号可以改善恢复而非被刷 | 将过程指标与独立终态在保留集上对照 | 过程分数上升却不改善终态或安全 |
这些问题和AutoResearch、Agentic RL、Agent Research Environments相连:它们都要求把可改动的系统、获得的反馈和最终证据放在不同的边界中。
Primary References
- MCP Specification.
- Anthropic: Writing tools for agents, effective harnesses for long-running agents, multi-agent research system, sandboxing, and agent evaluation.
- Harness-Bench and VeRO (preprints).
- Lilian Weng, Harness Engineering for Self-Improvement.
- Related notes in this series: coding-agent architecture, research program, RSI.
Harness Engineering: From Prompts to Accountable Agent Loops
A long-running agent is not “a model plus a prompt.” It is a runtime system: it selects information within a finite context, calls tools, preserves artifacts, enforces authority, manages budget and recovery, and hands results to an evaluator the agent cannot rewrite. Harness engineering is the discipline of designing that layer.
model + harness version + environment + tool/permission policy + evaluator + budget. A pass-rate increase alone therefore cannot show that “the model got better,” nor that a more elaborate orchestration helped.
1. What This Post Does Not Do
This is not a product survey, a declaration that more subagents are always better, or a claim that RSI has arrived. The existing coding-agent architecture comparison explains how six concrete systems run. This post asks a different question: how should a harness itself be designed, constrained, and evaluated?
Two meanings must remain separate:
- An agent harness is the runtime around a model: context, tools, state, control flow, authority, logs, and recovery.
- An evaluation harness provisions a task, executes trials, collects evidence, and scores results. The evaluated agent must not treat it as an editable tool.
When those meanings collapse, “the agent’s score improved” becomes dangerously ambiguous. A reader cannot tell whether model, prompt, tools, environment, budget, or scorer changed.
2. Draw an Accountable Boundary First
This is not a diagram of one released system. It is a design position: the model may propose actions and the harness may schedule them, but authority and acceptance criteria cannot live only in a prompt that says “be careful.” MCP provides a protocol boundary for objects such as tools, resources, and prompts. It does not automatically make a tool response trustworthy or replace host-side policy enforcement. MCP Specification
3. Six Engineering Planes
3.1 Contract: Tools Are Not Just a List of Function Names
Tools are contracts between a stochastic agent and stateful services. An evaluable tool surface makes its input schema, authority, errors, idempotency, and response scope inspectable. The more overlapping tool paths an agent has, the easier it is to obtain a fragile result through an accidental route. Anthropic’s tool-design guidance recommends testing tools on realistic multi-step tasks and using held-out tasks to detect overfitting to development trajectories. Writing tools for agents
The testable question is not “how many tools exist?” It is whether task-shaped narrow tools reduce invalid calls, token waste, or policy violations at equal authority and budget without harming held-out success.
3.2 State: Turn Memory into Artifacts, Not an Ever-Longer Prompt
Context engineering is the selection and maintenance of token state visible at each invocation. It is not merely a larger context window, and it is not dumping every past log into a prompt. Long-running systems need task manifests, progress, tests, candidate artifacts, dependencies, and version history as retrievable external artifacts. A fresh session can then continue from the same evidence instead of guessing what a prior session did.
Three terms deserve a strict distinction:
| Term | What it preserves | What it does not guarantee |
|---|---|---|
| Context compaction | A summary or selected context for the current conversation | The original environment can be restored |
| Session handoff | A state manifest, artifact locations, and open questions for a fresh context | Earlier actions can be safely replayed |
| Checkpoint | Restartable environment state, configuration, and artifact version | A live external service stays unchanged |
Public long-running-harness practice emphasizes feature lists, progress files, tests, bootstrap commands, and version history so a new worker reconstructs state from artifacts rather than hidden chat memory. Effective harnesses for long-running agents
3.3 Authority: Runtime Enforcement, Not Prompt Wording
A prompt can express a preference; it cannot enforce an authority boundary by itself. A serious policy names readable and writable mounts, allowed hosts, credential scope, risky action classes, approval points, resource ceilings, network egress, and audit retention. Sandboxing and network controls are runtime mechanisms, not courtesy instructions. This is why public sandboxing designs discuss both filesystem and network boundaries. Claude Code sandboxing
One simple rule follows: an agent may propose a policy expansion, but it cannot approve that expansion itself, nor rewrite the evaluator and announce that it passed. The rule applies to browser, Computer Use, terminal, and training harnesses alike.
3.4 Control: Parallelism Is a Scheduling Hypothesis
Parallel subagents can widen research and independent execution coverage, but also multiply token, coordination, and merge cost. They fit only materially separable work with stable output contracts; shared code surfaces and tightly coupled decisions often need a common controller. A public multi-agent research system likewise reports substantial token cost for broader exploration and stresses that coordination shapes the outcome. Multi-agent research system
The parent should own global budget, decomposition, cancellation, merge, and publication. Workers should receive narrow objectives, isolated workspaces where possible, explicit deliverables, and durable result records. “Multi-agent is better” becomes an empirical claim only after comparison with a same-model, same-budget, same-task sequential baseline.
3.5 Evidence: Trace, Replay, and Rerun Are Not Synonyms
Every run should at least record harness, model, tool, environment, and policy versions; an initial-state digest; input/output and tool events; approvals and denials; artifact hashes; retries and recovery; evaluator outputs; and token, wall-clock, and resource usage. Secrets, personal data, and third-party content need redaction before retention.
That trace supports three different operations:
- Diagnosis: why a run failed, spent unusually, or touched authority.
- Observational replay: inspect an event record without repeating external side effects.
- Execution rerun: execute from frozen state while declaring nondeterminism and external-dependency controls.
A video or chat transcript generally supports only the first two. It should not be called a reproducible rerun of a changing online service.
3.6 Integrity: The Evaluator Is Part of the System but Not the Optimization Surface
Deterministic tests, model graders, and human review answer different questions. Deterministic verifiers check explicit terminal states; model graders can handle nuanced text but need calibration and error reporting; humans catch unmodeled harm. Agent-evaluation engineering guidance stresses defining tasks, graders, samples, and metrics before interpreting a result as capability. Demystifying evals for AI agents
Harness changes should therefore carry a change manifest: what should improve, what must not regress, the held-out split that accepts it, and the rollback condition. Harness-Bench and VeRO are preprints exploring configuration-level or versioned agent evaluation. They provide useful methodological clues, not proof that elaborate harnesses are stronger on every task or evidence of unbounded self-improvement. Harness-Bench · VeRO
4. What a Harness Report Must Include
| Dimension | Minimum report | Qualification that cannot be omitted |
|---|---|---|
| Outcome | Pass rate, task version, grader, confidence interval | One success is not durable behavior |
| Efficiency | Tokens, tool calls, wall clock, GPU / sandbox-hours, cost per successful task | Compare under an identical budget |
| Reliability | Timeout rate, recovery after injected failure, resume latency, variance | State retry and stopping policy |
| Governance | Policy violations, false blocks, approval accuracy | Name the threat model and interception surface |
| Observability | Trace completeness, redaction failures, replay / rerun agreement | State whether replay is observational or executable |
| Parallelism | Speedup, worker-hours, duplicate work, merge conflicts | Compare with a same-budget sequential baseline |
| Generalization | Held-out change, regressions, cross-model or cross-task transfer | Keep final test data out of the optimization loop |
This table turns “the harness is good” into claims that can fail. A higher pass rate may come from hidden retries, greater concurrency, or an unequal token budget; omitting those makes the result unhelpful for engineering decisions.
5. When a Harness Tries to Improve Itself
Harness optimization can be useful: a system analyzes failed traces, proposes a small context, tool, or control-flow edit, tests it on frozen evaluation, then retains or reverts the version. It is still not automatically RSI. A stronger claim would require the modified harness to make later improvement processes reliably better on tasks that did not select it, while authority and evaluation remain outside the candidate’s control.
The minimum acceptable loop is:
- A human or external policy freezes editable surface, budget, evaluator, and rollback rule.
- The agent proposes a narrow edit from failure lineage and declares expected gain and regression risk.
- An independent runner executes capability and regression splits under the same budget and records evidence.
- An external acceptance gate merges, rejects, or reverts; the candidate harness has no write access to that gate.
This matches the boundary in the RSI note: improving one workflow is valuable, but one local gain does not establish that the system improved “the improver.”
6. A Workshop Agenda That Can Be Discussed Publicly
The following is a research agenda, not an announced event, CFP, or sponsorship notice.
- Interfaces and environments. Tool protocols, browser and computer actions, sandboxing, portability, and deterministic verification.
- Memory and long-horizon execution. Context lifecycles, artifact stores, checkpoints, recovery, durable jobs, and replay.
- Governed autonomy. Capability scoping, identity, approval design, prompt-injection containment, and audit logs.
- Optimization and evaluation. Workflow search, multi-agent scheduling, harness evolution, trace analysis, evaluator integrity, cost, and negative results.
A systems paper that claims a harness improvement should at minimum provide a versioned harness/environment manifest, task and evaluator versions, a budget ledger, trace/redaction plan, same-budget baseline, critical ablation, threat model, and failure analysis. These requirements do not guarantee correctness, but they expose a paper’s load-bearing dependencies to readers.
7. Five Falsifiable Research Questions
| Hypothesis | Minimum experiment | Falsifier |
|---|---|---|
| Structured external handoffs are more reliable than context compaction alone | Hold model, task, budget, and environment state fixed; compare recovery paths | No held-out completion or recovery gain, or greater cost |
| Narrow task-shaped tools beat a broad API mirror | Compare success, invalid calls, and tokens under equal authority | Broad tools match results without reliability or cost penalty |
| Parallelism helps only independent branches | Fix total tokens and worker-time; compare orchestrations | No speed or quality gain, or merge regressions erase it |
| An external acceptance gate reduces regressions in self-edits | Freeze evaluator/policy; compare versioned and unconstrained edits | Accepted edits regress no less, or the manifest has no predictive value |
| Process signals improve recovery rather than get gamed | Compare process metrics against independent held-out terminal states | Process score rises without better outcome or safety |
These questions join AutoResearch, Agentic RL, and Agent Research Environments: all require separate boundaries for what can change, what feedback is observed, and what finally counts as evidence.
Primary References
- MCP Specification.
- Anthropic: Writing tools for agents, effective harnesses for long-running agents, multi-agent research system, sandboxing, and agent evaluation.
- Harness-Bench and VeRO (preprints).
- Lilian Weng, Harness Engineering for Self-Improvement.
- Related notes in this series: coding-agent architecture, research program, RSI.