Autonomous Long-Running Coding Agents

自主编码正从优化提示转向构建目标、评估器、循环与验证器等控制系统,以实现代理的长时间自主工作与可验证性。

Image

Autonomous coding is moving from better prompting to better control systems. The important shift is that engineers are learning how to wrap agents in goals, evaluators, loops, and artifacts that let them keep working after the human stops typing.

自主编码正从更好的提示转向更好的控制系统。这一重要转变在于,工程师们正在学习如何将智能体包裹在目标、评估器、循环和工件中,让它们在人类停止输入后仍能持续工作。

This matters because most serious engineering work spans long horizons: ambiguous requirements, hidden constraints, partial failures, changing context, and repeated verification. The new frontier is designing the system around the agent so it can plan, execute, check its work, recover from mistakes, and keep making progress without constant human steering.

这一点很重要,因为大多数严肃的工程工作都涉及漫长的时间跨度:模糊的需求、隐藏的约束、部分的失败、变化的环境以及反复的验证。新的前沿领域是围绕智能体来设计系统,使其能够规划、执行、检查工作、从错误中恢复,并在无需人类持续引导的情况下持续取得进展。

This piece is based on a DAIR.AI Academy session on autonomous long-running coding agents, where I walked through Claude Code’s /goal mode, the newer /loop command, verifiers, artifacts, and orchestration patterns in practice. Written in collaboration with Codex and Claude Code.

本篇文章基于DAIR.AI Academy关于自主长期运行编码代理的课程,我在其中实际演示了Claude Code的/goal模式、较新的/loop命令、验证器、工件以及编排模式。与Codex和Claude Code协作编写。

From Prompting to Goal Design

从提示到目标设计

Image

The core idea behind features like Claude Code’s /goal is simple. A coding agent remains the executor, but the human no longer interacts with it turn by turn. Instead, the human specifies the desired end state, the evidence required to prove success, the constraints that must not be violated, and, where possible, the number of turns and budget.

诸如 Claude Code 的 /goal 这类功能背后的核心理念很简单。编码智能体仍然充当执行者,但人类不再与其逐轮交互。相反,人类指定期望的最终状态、证明成功所需的证据、不得违反的约束条件,以及在可能的情况下,指定轮次数量和预算。

That goal works more like a contract than a longer prompt. A weak goal gives the model room to stop early, take shortcuts, or redefine success in a way that looks plausible in the transcript but fails in the real system. A strong goal gives the agent a target it can repeatedly measure itself against.

这个目标更像是合同,而不是较长的提示。弱目标会让模型有机可乘,更早停止、取捷径或在记录中看似合理但实际在真实系统中失败的前提下重新定义成功。强目标则为智能体提供了一个它可以反复自我对照的标尺。

Engineering judgment still matters here. The best goals encode domain knowledge that the model would otherwise guess. For a research experiment, that might mean a target benchmark score, a held-out evaluation, a required loss curve, and a rule that the result must beat an initial baseline. For a UI task, it might mean a screenshot reference, concrete layout constraints, and a browser verification step. The model can execute, but the human still defines what “done” actually means.

工程判断在此处仍然至关重要。好的目标会将模型可能猜测的领域知识编码进去。对于研究实验,这可能意味着一个目标基准分数、一个留出评估、一条所需的损失曲线,以及结果必须超越初始基线的规则。对于UI任务,则可能意味着截图参考、具体的布局约束,以及浏览器验证步骤。模型可以执行任务,但”完成”的实际定义仍由人来决定。

The Evaluator Becomes a First-Class Component

评估器成为一等组件

Image

Long-running agents need a second role besides the goal. That evaluator can be another coding agent, an LLM-as-judge, a script, a test suite, a benchmark harness, or a mix of all of them. The key design choice is matching the evaluator to the task. When success is crisp, deterministic checks are better. Type checks, unit tests, lint rules, integration tests, and benchmark scripts should be used whenever they can express the condition clearly.

长时间运行的智能体除了目标之外,还需要第二个角色。这个评估者可以是另一个编码智能体、LLM-as-judge、脚本、测试套件、基准测试框架,或是它们中的任意组合。关键的设计选择在于让评估者与任务相匹配。当成功标准清晰明确时,确定性检查更优。类型检查、单元测试、lint 规则、集成测试和基准测试脚本,凡能清晰表达条件之处,都应加以使用。

When success is fuzzy, an agent evaluator becomes useful. A script can tell you whether tests pass, but it cannot easily decide whether a generated research report is coherent, whether an implementation faithfully follows a paper, or whether a UI matches a design intent. This is where the evaluator benefits from language, judgment, and sometimes vision.

当成功的定义模糊时,智能体评估器就显得很有用。脚本可以告诉你测试是否通过,但很难判断生成的研究报告是否条理清晰、实现是否忠实地遵循了论文、或者用户界面是否匹配设计意图。这正是评估器借助语言、判断力,有时还有视觉能力发挥作用的所在。

The practical pattern uses deterministic checks as the floor and agent evaluation as the higher-level review. That combination reduces hallucinated success while still allowing autonomy on tasks that do not fit cleanly into a test assertion.

该实际模式以确定性检查为基准,将智能体评估作为更高层级的审查。这种结合减少了幻觉成功的情况,同时仍允许在那些难以完全适配测试断言的任务上保持自主性。

Verifiers Define the Boundary of Trust

验证者定义信任的边界

Image

The deeper point is that autonomy only works when the system has a reliable verifier. A coding agent can generate a plan, implement a feature, and explain why it believes the work is complete, but that explanation should not be treated as evidence. Evidence comes from an external check that the agent cannot easily talk its way around.

更深层的观点是,只有当系统拥有一个可靠的验证器时,自主性才能发挥作用。一个编码代理可以生成计划、实现功能,并解释为何它认为工作已完成,但这种解释不应被视为证据。证据来自于代理无法轻易绕过的外部检查。

For code, the verifier might be a test suite, type checker, benchmark, browser run, screenshot comparison, or reproducible script. For research work, it might be a held-out evaluation, a reproduced table, a loss curve, or a benchmark score that improves over the baseline. For design work, it might be a reference screenshot plus a visual review step. The verifier is what turns a long-running agent from a confident text generator into a system that can be trusted with more time.

对于代码,验证器可能是测试套件、类型检查器、基准测试、浏览器运行、截图比较或可复现脚本。对于研究工作,它可能是保留评估、复现表格、损失曲线或优于基线的基准分数。对于设计工作,它可能是参考截图加视觉审查步骤。验证器将长时间运行的智能体从自信的文本生成器转变为一个可以被赋予更多时间而值得信赖的系统。

Most shortcuts appear at this boundary. If the verifier is vague, the model will often satisfy the easiest interpretation of the task. If the verifier is too narrow, the model may overfit to it and miss the broader intent. A good autonomous workflow, therefore, needs layered verification, with cheap deterministic checks catching basic failures and higher-level review catching judgment-heavy failures. A few of the frontier models can already achieve some level of verification, but based on my research, there is still an evident OOD problem, where if the verification task you assign to the agent falls outside the training distribution, models struggle significantly.

大多数捷径都出现在这个边界上。如果验证器定义模糊,模型通常会满足任务最简单直白的解释;如果验证器过于狭窄,模型则可能过度拟合它,从而错失更广泛的意图。因此,一个良好的自主工作流需要分层验证:用廉价且确定性的检查来捕捉基础错误,用更高级的审查来捕捉依赖判断的严重错误。部分前沿模型已经能够实现一定程度的验证,但根据我的研究,仍存在明显的OOD(分布外)问题——当你分配给智能体的验证任务超出训练数据分布时,模型的表现会大打折扣。

Verifiers are still an open area of research, but I anticipate more companies will start to make huge investments in this area. The concept of fine-tuned verifiers is also in high demand in the enterprise.

验证器仍是一个开放的研究领域,但我预计更多公司将开始在这一领域投入巨资。微调验证器的概念在企业中也需求很高。

Loops Make Autonomy Durable

循环使自主持久

Image

A goal gives the agent direction, but a loop keeps the work alive. This distinction is important because models often stop before the real task is finished. They may hit a turn limit, lose confidence, exhaust context, or decide that a partial solution is enough.

目标为智能体指明方向,而循环则让工作持续运转。这一区别至关重要,因为模型常常在真正任务完成之前就停下来——可能是触发了轮次限制、失去信心、耗尽上下文,又或是认为部分解决方案已经足够。

The loop is the outer control system. It wakes up, inspects progress, runs checks, compares the result against the goal, and sends the agent back in with the next instruction when the goal has not been met. In its simplest form, this is the Ralph loop pattern with a coding agent and a deterministic condition. In a more flexible form, the loop includes an evaluator agent that can reason about progress and decide what should happen next.

循环是外部控制系统。它会唤醒、检查进展、执行校验、将结果与目标进行比对,若目标尚未达成,则给代理下发下一步指令后将其重新投入任务。最简单的形式是包含编码代理和确定性条件的Ralph循环模式。更灵活的形式则包含能够推理进展程度并决策后续操作的评估代理。

Long-running autonomy works as repeated effort under supervision from a control layer, not as one continuous act of intelligence. The agent can still fail, but the loop gives the system a way to notice the failure and continue instead of silently declaring victory.

长期自主运行是在控制层的监督下进行重复努力,而非一次性的智能行为。智能体仍可能失败,但这一循环让系统能够察觉到失败并继续运行,而不是默默地宣告胜利。

Planning Is Where Expertise Enters

规划是专业知识的用武之地

Image

One of the strongest themes from the session was that planning remains critical. You can ask a frontier model to generate a plan, but you still need to inspect it, challenge assumptions, and make the success criteria sharper before handing the task to an autonomous loop.

本次讨论中最突出的主题之一是,规划仍然至关重要。你可以让前沿模型生成一份计划,但在将其交给自主循环执行之前,你仍然需要检查它、质疑其中的假设,并让成功标准更加明确。

This leads to a useful division of labor. A stronger planning model can help define the goal, identify missing constraints, and structure the evaluation. A different execution model can then run the implementation once the plan is clear. In practice, this means engineers should stop thinking of “the model” as a single choice. Model choice becomes an architecture decision.

这引出了一个有用的分工。一个更强的规划模型可以帮助定义目标、识别缺失的约束条件并构建评估框架。一旦计划清晰,另一个执行模型就可以负责落实实施。在实践中,这意味着工程师不应再将“模型”视为单一选择——模型选择变成了一项架构决策。

Some models are better planners. Some are better executors. Some are cheaper evaluators. Some are better at vision-based review. A good orchestrator lets you swap these roles instead of waiting for one vendor to provide the perfect coding agent interface.

有些模型更擅长规划,有些更精于执行,有些是成本更低的评估者,还有些在基于视觉的审查方面表现更佳。一个好的编排器能让你互换这些角色,而不是等待某一家供应商提供完美的编码代理接口。

Visual Artifacts Become Control Surfaces

视觉伪影成为控制表面

Image

Terminal transcripts do not scale when many agents are running. Once you have several sessions working in parallel, raw text becomes a poor interface for understanding progress.

终端日志无法随代理数量的增加而扩展。一旦有多个会话并行工作,原始文本便成为理解进展的糟糕界面。

Live artifacts matter because a dashboard with loss curves, benchmark scores, task states, screenshots, cost estimates, and recent decisions gives the human a much better way to supervise autonomy. The artifact becomes the control surface for deciding when to intervene, rather than a report generated after the fact.

实时工件之所以重要,是因为一个包含损失曲线、基准分数、任务状态、截图、成本估算和近期决策的仪表盘,能让人类以更优的方式监督自主系统。该工件成为了决定何时干预的控制界面,而非事后生成的报告。

The most useful pattern is to separate storage from presentation. Markdown or a vault can store durable evidence, logs, notes, plans, and results. HTML artifacts can render that state into something visual and interactive. The agent can search the Markdown, while the human can monitor the artifact.

最有用的模式是将存储与展示分开。Markdown 或库可以存储持久化证据、日志、笔记、计划和结果。HTML 产物则能将这种状态渲染为可视化和交互式的内容。智能体可以搜索 Markdown,而人类则可以监控产物。

For UI and product work, visual cues are especially powerful. A screenshot reference can communicate design intent more precisely than prose, and a vision-capable evaluator can compare the implementation against that reference. This reduces the common failure mode where the agent technically implements the requested component but misses spacing, hierarchy, alignment, or product feel.

对于UI和产品类工作,视觉提示尤为强大。一张截图参考比文字描述更能准确传达设计意图,而具备视觉能力的评估者可以对比实现结果与参考图。这减少了常见的失败模式——代理虽然从技术上实现了所要求的组件,却忽略了间距、层级、对齐或产品感觉。

Session Mining Turns Usage Into Memory

会话挖掘将使用转化为记忆

Image

Another important insight is that past agent sessions are a rich source of workflow data. If an agent repeatedly fails in the same way, forgets to run the same check, uses the wrong path, or retries the same broken command, that pattern should not stay buried in logs.

另一个重要的洞察是,过往的代理会话(agent sessions)是工作流数据的丰富来源。如果代理反复以相同方式失败、忘记运行同一项检查、使用错误路径或重试同样出错的命令,这种模式不应被埋在日志里。

Session mining turns those transcripts into operating rules. An agent can scan the last thirty days of work, find recurring failure modes, and propose updates to project instructions, vault learnings, or agent rules. This is how a team can gradually improve its harness without manually remembering every mistake.

会话挖掘将这些会话记录转化为操作规则。智能体可以扫描过去三十天的工作,找到重复出现的故障模式,并针对项目指令、知识库经验或智能体规则提出更新建议。这样一来,团队就能逐步优化其工作框架,而无需手动记住每一个错误。

The goal is to make the local environment smarter without training a model from scratch. A small rule in an agent instruction file can prevent repeated failures across future sessions, especially when the rule is specific to the project.

目标是在不从头训练模型的情况下,让本地环境变得更智能。智能体指令文件中的一条小规则就能避免未来会话中反复失败,尤其是在该规则针对特定项目时。

A Practical Operating Model

一种实用的运营模式

Image

For AI engineers, the emerging workflow looks like this.

对于AI工程师而言,新兴的工作流看起来是这样的。

  • Start with a small, cheap subset before launching the full autonomous run.
  • Write a goal with measurable success criteria, explicit constraints, and a turn or time budget (where possible).
  • Separate the executor from the evaluator so implementation and judgment are not collapsed into one role.
  • Define external verifiers before the long-running loop starts.
  • Use deterministic checks wherever possible, then add agent review for fuzzy criteria.
  • Require proof artifacts such as logs, screenshots, benchmark curves, or changed files.
  • Mine past sessions and promote repeated lessons into project instructions.
  • 在启动全自动运行之前,先从小而廉价的子集开始。
  • 写出带有可衡量成功标准、明确约束条件以及轮次或时间预算(尽可能)的目标。
  • 将执行器与评估器分开,避免实施和判断合并为单一角色。
  • 在长时间运行的循环开始之前定义外部验证器。
  • 尽可能使用确定性检查,然后针对模糊标准引入智能体审查。
  • 要求日志、截图、基准曲线或变更文件等证明工件。
  • 挖掘过往会话,将反复出现的经验教训提炼为项目说明。

That is the difference between using a coding agent and engineering an autonomous coding system. One gives you a conversation. The other gives you a harness.

这就是使用编码代理与设计自主编码系统之间的区别。前者给你一段对话,后者给你一套可驾驭的工具。

What Still Breaks

仍存在的问题

Image

None of this removes the hard problems. Agents still take shortcuts. They still stop early. They still overestimate completion. They still produce confident but weak plans, especially on recent papers, unfamiliar benchmarks, or systems outside their training distribution.

这些都未能消除那些棘手的问题。代理仍然会走捷径,仍然会过早停止,仍然会高估完成度,仍然会生成自信但薄弱的方案——尤其是在最新论文、陌生基准或训练分布之外的系统上。

Trusting them more will not solve this. Better control systems will. Goals, loops, evaluators, deterministic checks, visual artifacts, and session memory are all ways of making autonomy observable and correctable.

更信任它们解决不了这个问题。更好的控制系统才能做到。目标、循环、评估器、确定性校验、可视化产物和会话记忆,都是让自主性变得可观察、可纠正的方法。

The direction is clear. The future of coding agents depends on better orchestration around more capable models, where engineers design the conditions under which agents can safely run for hours or days and still produce work that can be verified.

方向已明确。编码代理的未来取决于围绕能力更强的模型进行更好的编排,工程师需设计出合适的环境,让代理能够安全运行数小时甚至数天,同时产出可验证的成果。