文章

对话

图像
From Prompting Agents to Loop Engineering从提示代理到循环工程
A claim has been circulating in AI coding circles: stop prompting your coding agents and start designing loops that prompt them for you. As with everything new, this stuff gets repeated often and explained rarely. This is the practical version: what an agent loop is, why it matters, and what one looks like in production.在 AI 编码圈子里流传着一种说法:停止直接提示你的编码代理,改为设计循环让它们自行提示。和所有新事物一样,这类内容经常被重复,却很少被解释。这里是实用版:什么是代理循环、它为何重要,以及在生产环境中它的样子。
Below you can read some of my thoughts (written with the help of Claude) from some of the experiments, research, and conversations I’ve been having with some of our 下面你可以阅读我(在 Claude 的帮助下)对一些实验、研究以及我与我们的, technical founders, AI engineers, and startups.、技术创始人、AI 工程师和初创公司的对话中的一些想法。
You might also find our recent live session on "你也可以把我们最近的直播 "" as a good starting point for all of this." 作为一个很好的起点。

Where the claim comes from
说法的来源

"You shouldn't be prompting coding agents anymore. You should be designing loops that prompt your agents."Peter Steinberger (), Jun 7 2026. 2.2M views.
"你不应该再提示编码代理了。你应该设计循环来提示你的代理。" Peter Steinberger(@steipete),2026年6月7日。220 万观看。原始推文
Boris Cherny, the creator of Claude Code, makes the same point from the other side.Claude Code 的创建者 Boris Cherny 也从另一个角度表达了同样的观点。
"I don't prompt Claude anymore. I have loops that are running. They're the ones that are prompting Claude and figuring out what to do. My job is to write loops."Boris Cherny ().
"我不再提示 Claude 了。我有正在运行的循环。它们才是提示 Claude 并决定该做什么的。我只负责写循环。" Boris Cherny(@bcherny)。原始推文
The point is not that prompt engineering is dead. With loop engineering, the work moves up a level, from writing the code to writing the system that writes the code. Developers furthest along this path report months where they shipped hundreds of PRs without opening an IDE, with every line written by the agent.重点并不是提示工程已经死了。通过循环工程,工作提升到了更高的层次——从写代码转向写生成代码的系统。走在这条路上最前沿的开发者报告称,他们有几个月的时间提交了数百个 PR,却没有打开 IDE,所有代码行都是由代理写的。

What a loop actually is
循环到底是什么

A loop is a small program you write that does four things:循环是一个小程序,你编写它来完成四件事:
  • prompts the coding agent for you,
    为你提示编码代理,
  • reads what it produced,
    读取它产生的输出,
  • decides whether it is done,
    判断是否已经完成,
  • and if not, prompts it again with the error or the next step.
    如果没有完成,则用错误信息或下一步提示再次提示它。
You stop sitting inside the loop typing prompts; you write the loop, and the model becomes a subroutine it calls.你不再在循环内部手动输入提示;你编写循环,模型则成为它调用的子程序。
图像
The shape is always the same: set a goal, act, check, feed the error back, and repeat until the check passes or the loop stops itself.形状始终相同:设定目标、执行、检查、反馈错误,重复直到检查通过或循环自行停止。

"Loop" means at least five things
"循环" 至少包含五个含义

Much of the disagreement is people using one word for five different ideas. Here is the progression, oldest to newest.很多争议来源于人们用一个词指代了五种不同的概念。以下是从最早到最新的演进。
图像
  • ReAct (2022). The original research pattern: reason, act, observe, repeat.
    ReAct(2022)。最初的研究模式:推理、行动、观察、重复。
  • AutoGPT (2023). A self-prompting goal loop, notorious for not knowing when to stop.
    AutoGPT(2023)。自我提示的目标循环,以不知道何时停止而闻名。
  • ralph loop. A deliberate context reset between iterations so the agent does not drown in its own history.
    ralph loop。每次迭代之间进行有意的上下文重置,防止代理被自己的历史淹没。
  • /loop and /goal. Cadence and completion conditions are built into the agent, carrying the state across turns.
    /loop 和 /goal。节奏和完成条件内置于代理中,状态跨回合保持。
  • orchestration. One author fans out many agents that read your GitHub, Slack, and chat, and decide what to build next.
    orchestration。某位作者让多个代理读取你的 GitHub、Slack 和聊天记录,并决定接下来要构建什么。

The parts you actually assemble
你实际组装的部分

The progression explains what people 演进解释了人们mean by loop; this is what a loop is 循环的含义;这就是循环的本质built from由以下. The same six parts show up every time, and most now ship inside the coding tools instead of custom scripting you maintain yourself.六个部分构成。每次都会出现相同的六个部分,而且大多数现在都内置在编码工具中,而不是你自己维护的自定义脚本。
图像
  • A trigger. Something that starts the loop without you pressing go: a schedule, a webhook, a file change, a label landing on a PR. This is what separates a real loop from a single run you repeat by hand.
    触发器。无需手动点击启动循环的东西:计划任务、Webhook、文件变更、PR 上的标签。这是把真实循环和手动重复单次运行区分开的关键。
  • Isolation. A private checkout per agent, usually a git worktree, so two agents running at once cannot overwrite each other's files. Once you run more than one, this stops being optional.
    隔离。为每个代理提供私有的检出目录,通常是 git worktree,这样同时运行的两个代理不会互相覆盖文件。一旦运行多个代理,这一步就不再是可选的。
  • Written-down context. The conventions, build steps, and project-specific rules are kept where the agent reads them on every run. Skip it, and the loop re-derives your project from scratch each pass and guesses at the gaps.
    书面化上下文。约定、构建步骤以及项目特定规则都保存在代理每次运行时会读取的位置。若省略,循环将在每一次迭代中重新推导项目并猜测缺失内容。
  • Reach into your tools. Connectors to the issue tracker, CI, database, and chat, so the loop can open the PR, link the ticket, and post the result instead of printing a fix and waiting for you to carry it the rest of the way.
    接入你的工具。连接 issue tracker、CI、数据库和聊天系统,使循环能够打开 PR、关联工单并直接发布结果,而不是仅仅打印修复并等待你手动完成。
  • A second agent checks. A separate worker who grades the output is held apart from the one who produced it, because a model reviewing its own work passes almost everything.
    第二个代理进行检查。一个独立的工作者负责对输出进行评分,且与生成者分离,因为模型自评往往几乎全通过。
  • State on disk. A markdown file, a board, or a queue: anything outside the conversation that records what is finished and what is next. The model forgets between runs; the file does not.
    磁盘状态。Markdown 文件、看板或队列:任何在对话之外记录已完成和待完成事项的东西。模型在不同运行之间会忘记,文件则不会。
Assemble those six, and you have a good starting point for loop engineering. You used to hand-build everything; now most ship as built-in features, which is why the pattern has moved from a fringe technique into common use.把这六个部分组装起来,你就拥有了一个很好的循环工程起点。过去你需要手工构建所有东西;现在大多数已经作为内置功能提供,这也是该模式从边缘技术走向主流的原因。

A concrete loop, the PR babysitter
一个具体的循环示例——PR 保姆

A concrete example you can build today:今天就可以实现的具体例子:
图像
  • Trigger. Every 15 minutes.
    触发器。每 15 分钟一次。
  • Scope. Open PRs labeled agent-watch.
    范围。打开标记为 agent-watch 的 PR。
  • Action. If CI is red for a deterministic reason, attempt one fix. If the main moved, rebase once.
    动作。如果 CI 因可确定原因而失败,尝试一次修复;如果主分支有变动,执行一次 rebase。
  • Budget. One fix attempt per PR, five minutes, ten files changed.
    预算。每个 PR 最多尝试一次修复,时长五分钟,最多修改十个文件。
  • Stop condition. CI green, or budget exhausted, then stop and ping a human.
    停止条件。CI 通过或预算耗尽,则停止并通知人工。
You return to merged PRs instead of a backlog of broken builds. The same shape covers most ops work:这样你会得到已合并的 PR,而不是一堆构建失败的积压。相同的形状可以覆盖大多数运维工作:
  • CI health. Every 30 minutes, pull failing runs and cluster them by signature, so ten red PRs with one root cause become one thing to look at.
    CI 健康。每 30 分钟拉取失败的运行并按特征聚类,这样十个因同一根本原因导致的红色 PR 就会合并为一个待查看项。
  • Deploy verification. After a push, hit your endpoints, confirm 200s and the expected content, and flag regressions before users do.
    部署验证。代码推送后访问你的接口,确认返回 200 且内容符合预期,在用户发现之前标记回归。
  • Feedback clustering. Every 30 minutes, pull comments from your channels, group them into themes, and map each cluster to the file or doc that owns it.
    反馈聚类。每 30 分钟从各渠道拉取评论,按主题分组,并将每个聚类映射到对应的文件或文档。

A concrete Claude Code loop with /goal
带 /goal 的具体 Claude Code 循环

The babysitter is a loop you wire up yourself; it also helps to see one that ships inside the agent. In Claude Code, the smallest complete loop is /goal: you hand it a verifiable end state, and it keeps taking turns until that state is true.保姆是你自行搭建的循环;同时也可以看看在代理内部已经实现的版本。在 Claude Code 中,最小完整的循环是 /goal:你给它一个可验证的终态,它会不断回合直到该状态成立。
图像
Here is an example of /goal used as an in-session command in Claude Code. You launch the session, then set the goal inside it:下面是 /goal 在 Claude Code 会话中作为指令使用的示例。先启动会话,然后在会话内部设定目标:
bashbash
$ claude  # launch Claude Code
$ /goal tests in test/auth pass   # set the goal inside the session
It is the same act, check, repeat shape from earlier, with the verifier built in.这与前面的 act、check、repeat 形状相同,只是把验证器内置进来了。
At this point, it’s clear that a strong /goal reads less like a prompt and more like a contract. The good ones specify four things: the 此时可以看出,一个强大的 /goal 看起来更像合同而不是提示。好的 /goal 会明确四件事:end state终态 you want, the 你想要的evidence证据 that proves you reached it, the 证明已达成的依据,constraints约束条件 the agent must not break getting there, and the 代理在达成过程中不得违反的限制,budget预算 of work it is allowed to spend. Leave any one of them vague, and the model fills the gap with the easiest reading: it stops early, takes a shortcut, or redefines success so the transcript looks done while the real system is broken.允许消耗的工作量。只要其中任意一项写得模糊,模型就会用最省事的方式填补空白:提前停止、走捷径,或把成功重新定义为“看起来完成”,而实际系统仍然出错。
  • Set the condition. Type /goal plus a checkable end state, for example,/goal tests in test/auth pass. The first turn starts immediately.
    设定条件。输入 /goal 加上可检查的终态,例如 /goal tests in test/auth pass。第一回合会立即启动。
  • The agent works a turn. It edits, runs the tests, and surfaces the results in the session.
    代理执行一次回合。它会编辑代码、运行测试,并在会话中展示结果。
  • An evaluator checks. A fast model reads the transcript and decides whether it is met or not met, so the agent is not grading its own work.
    评估者检查。一个快速模型读取会话记录并判断是否达标,从而避免代理自评。
  • Loop or finish. Not met means another turn with guidance; met means the goal clears itself and the run stops.
    循环或结束。未达标则继续下一回合并提供指导;达标则目标自行清除,循环停止。
State carries across turns, so it does not quit early or drop a constraint partway through. A few controls keep it reliable:状态会在回合之间保持,因此不会提前退出或在中途丢失约束。以下控制可以提升可靠性:
  • Make the check measurable. A test result, an exit code, a file count, or an empty queue. npm test exits 0 is a goal; "make it better" is not.
    让检查可度量。测试结果、退出码、文件数量或空队列都可以。npm test 退出 0 是目标;“让它更好”则不是。
  • Bound the run. Append something like "or stop after 20 turns" so a stuck loop halts instead of burning turns.
    限定运行次数。加上类似 “或在 20 回合后停止” 的限制,防止循环卡死而无限消耗。
  • Pair it with auto mode so that turns run unattended, and use /goal clear to abandon it early.
    配合 auto 模式让回合无人值守运行,并使用 /goal clear 提前终止。
The evaluator step hides a useful subtlety: the checker does not have to be the same model as the coder. Once the loop has distinct roles (planner, executor, evaluator, vision reviewer), each can run on a different model, and choosing which model fills which role becomes an architecture decision rather than a single bet on one "best" coding agent. Some models plan better, some execute more cheaply, some judge a screenshot more accurately, and a good orchestrator lets you swap them per role instead of waiting for one vendor to win every category.评估步骤揭示了一个细微但重要的点:检查者不必和编码者是同一个模型。一旦循环拥有不同角色(规划者、执行者、评估者、视觉审阅者),每个角色可以使用不同的模型,这就成为架构决策,而不是把所有希望压在单一“最佳”编码代理上。某些模型擅长规划,某些执行更廉价,某些更擅长评审截图,优秀的编排器可以根据角色自由切换模型,而不必等某一家供应商全能。
It works well for API migrations (move every call site until it compiles and tests pass), refactors (split a file until each module is under budget), issue backlogs (work a labeled queue until it is empty), and eval loops (tune a prompt until the score clears a threshold). /loop is the counterpart for work with no single finish line: instead of a completion condition it re-prompts on a schedule, which is how a loop like the PR babysitter keeps running.它在 API 迁移(逐个调用点修改直至编译并通过测试)、重构(拆分文件直至每个模块符合预算)、issue 待办(处理标记队列直至清空)以及评估循环(调优提示直至分数突破阈值)等场景表现出色。/loop 是没有单一终点的工作对应的形式:它没有完成条件,而是按计划重新提示,这正是类似 PR 保姆的循环能够持续运行的方式。

Running many loops unattended
无人值守运行多个循环

A single /goal loop is one agent working toward one finish line. Running many unattended processes raises the stakes, because a loop is only as trustworthy as its ability to check its own work. Cherny's setup for running Opus autonomously for hours comes down to five steps:单个 /goal 循环对应一个代理朝向单一终点工作。大量无人值守进程会提升风险,因为循环的可信度取决于它自检的能力。Cherny 为让 Opus 能够自主运行数小时的设置归结为五步:
  1. Auto-approve permissions so the agent does not stop to ask on every tool call.
    自动批准权限,避免代理在每次调用工具时都停下来询问。
  2. Use dynamic workflows (drop Ultracode into the prompt) to fan out across many agents instead of one serial thread.
    使用动态工作流(在提示中加入 Ultracode)让任务在多个代理之间并行,而不是单线程。
  3. Use /goal or /loop to keep it going. /goal sets a completion condition, /loop re-prompts on a schedule, and both carry state, so it does not quit early.
    使用 /goal 或 /loop 保持运行。/goal 设置完成条件,/loop 按计划重新提示,两者都携带状态,防止提前退出。
  4. Run it in the cloud (desktop or mobile app) so the session survives when you close the laptop.
    在云端运行(桌面或移动端应用),这样关闭笔记本后会话仍然存活。
  5. Give it a way to self-verify end-to-end. Claude in Chrome for web, a simulator MCP for mobile, and a live server for backend. This is the step that makes the other four safe.
    提供端到端自我验证的方式。Chrome 上的 Claude、移动端的 MCP 模拟器以及后端的实时服务器。这一步让其他四步安全可靠。
The full sequence:完整流程如下:
bash
claude --permission-mode auto                          # 1 · no approval prompts
ultracode  orchestrate sub-agents to ship the feature  # 2 · fan out
/goal all tests pass and the demo loads clean          # 3 · keep going
→ cloud / desktop app                                  # 4 · close the laptop
→ chrome ext · sim MCP · live server                   # 5 · self-verify, then halt

crabfleet: orchestration as a product
crabfleet:作为产品的编排

Orchestration is easier to picture with a concrete tool. Peter Steinberger's 编排通过具体工具更易于想象。Peter Steinberger 的, an OpenClaw project billed as "mission control for agent runs," is a loop packaged as a product, and its shape maps onto everything above.,一个被称为 “agent 运行的任务控制中心” 的 OpenClaw 项目,是一个包装成产品的循环,其形态映射到上文所有内容。
图像
  • Work as cards on a board. Tasks are entered as cards built from a prompt, a GitHub issue, or a PR, then move through todo, running, human review, and done. That board is the loop's queue and its stop-and-report step, made visible.
    将工作视为看板上的卡片。任务以卡片形式录入,来源可以是提示、GitHub issue 或 PR,然后在 todo、running、human review、done 之间流转。看板即循环的队列和停机报告步骤,可视化呈现。
  • Durable runs, not fire-and-forget. Each run is a tracked attempt with heartbeats, so it keeps going when you look away and survives a closed laptop. You take over only when the runtime advertises that it supports handoff.
    持久运行,而非一次性抛弃。每次运行都有心跳追踪,即使你离开视线或关闭笔记本,它仍能继续。只有当运行时声明支持交接时,你才会介入。
  • Agents that spawn agents. A run can start child sessions, send messages, read transcripts, and update its own summary from inside a sandbox: on-disk memory and fan-out in one place, one author and many agents.
    代理生成代理。一次运行可以启动子会话、发送消息、读取记录,并在沙箱内部更新自己的摘要:磁盘记忆与并行扩展合二为一,单一作者却拥有多个代理。
It runs on disposable cloud sandboxes with browser-based terminals, which is what makes walking away from an unattended run safe. The point is not the specific tool but that the loop has hardened into infrastructure: a queue, durable execution, fan-out, and a human-review gate are now things you configure rather than hand-script every time.它运行在可一次性销毁的云端沙箱,配有基于浏览器的终端,这正是让无人值守运行安全的关键。重点不在于具体工具,而在于循环已经硬化为基础设施:队列、持久执行、并行扩展以及人工审查门槛现在都是可配置的,而不是每次都手写脚本。

Where the cost goes now
成本现在流向何处

For two years, the cost question in AI coding was simple: which model, and how many tokens. Inside a loop, that instinct points at the wrong layer. The spend is no longer a single call but how many times the loop goes around, so a loop that retries six times before it converges costs six times as much as one that lands on the first pass, on the same model.过去两年,AI 编码的成本问题很简单:选哪个模型,消耗多少 token。进入循环后,这种直觉指向了错误的层面。支出不再是单次调用,而是循环迭代的次数;因此一个需要重试六次才收敛的循环,成本是一次成功循环的六倍,即使使用相同模型。
That changes what is worth optimizing:这改变了优化的重点:
  • Iterations are the budget line, not tokens. A cheaper model that loops twice as often is not cheaper, so track cost per finished task, not cost per call.
    迭代次数才是预算线,而不是 token。一个更便宜的模型如果循环次数翻倍,整体并不更便宜,所以要跟踪每个完成任务的成本,而不是每次调用的成本。
  • A weak verifier is the most expensive bug you can ship. If the check that decides "done" is loose, the loop either stops early on broken work or grinds on work that was already fine, and both waste whole iterations. Tighten this before anything else.
    弱验证器是最贵的 bug。如果决定 “完成” 的检查过于宽松,循环要么在错误的工作上提前停止,要么在已经完成的工作上反复消耗,都会浪费整轮迭代。先把验证器收紧。
  • Failing fast is a cost control. A loop with no cap on consecutive failures does not eventually succeed; it eventually drains the account, so the stop condition protects the bill as much as the codebase.
    快速失败是成本控制。没有对连续失败的上限,循环会一直耗尽账户,而不是最终成功;因此停止条件同样是账单的保护伞。
You used to tune the prompt; now you tune the loop, because that is where the cost accumulates.过去你调的是提示;现在你调的是循环,因为成本正是在这里累积。

When not to loop
何时不该使用循环

Loops pay off when a task repeats, and a machine can tell when it is done. Outside that, a loop only automates churn. Skip it in these cases:循环在任务可重复且机器能判断何时完成时才有价值。否则循环只会自动化重复劳动。以下情况请跳过循环:
  • One-shot edits. If you can finish it in a single pass, a loop is pure overhead.
    一次性编辑。如果能在单次通过完成,就没有循环的必要。
  • Unscoped or exploratory work. "Figure out why users are churning" has no pass condition, so the loop never converges.
    范围不明确或探索性工作。比如 “弄清用户流失的原因” 没有明确的通过条件,循环永远无法收敛。
  • Anything without a cheap automated check. If the only verifier is your own eyes, you are still inside the loop. Build the check first, or do the task by hand.
    缺乏廉价自动检查的任务。如果唯一的验证器是你自己的眼睛,那么你仍然在循环内部。先构建检查,再考虑自动化。

What can go wrong
可能出现的问题

A loop that runs while you sleep also makes mistakes while you sleep, and the failure modes are predictable.在你睡觉时运行的循环也会在你睡觉时出错,且其失效模式是可预测的。
  • The verification burden stays human. The loop writes faster than you can review, so if you stop reading the diffs, you have not removed the work, only deferred it.
    验证负担仍然落在人类身上。循环写代码的速度快于你审查的速度,如果你停止阅读 diff,工作并未被消除,只是被延后。
  • Comprehension gaps widen. Shipping code you did not write, faster than you can absorb it, erodes the model of your own system, and that debt comes due during the next incident.
    理解缺口会扩大。让模型快速交付你未亲自编写的代码,会侵蚀你对系统的认知,这种技术债务会在下次事故时显现。
  • Silent drift on a loose check. A weak verifier lets wrong-but-passing work through on every iteration, so the loop looks productive while it digs a hole.
    宽松检查导致的静默漂移。弱验证器会让错误但通过的工作不断进入,每次迭代看似高产,实则在挖坑。
None of this is an argument against loops; it is why the engineer who designs the loop matters more, not less.这些并不是反对循环的论点,而是说明设计循环的工程师比以往更为关键。

How to build your own
如何自行构建

图像
  1. Pick one repeatable task. Babysitting PRs, fixing CI, verifying deploys: start with routine work.
    挑选一个可重复的任务。比如保姆 PR、修复 CI、验证部署:从例行工作开始。
  2. Scope it tight. "Fix the billing webhook validation, only touch app/api/billing and lib/billing," beats "fix the bug." A loose loop wanders.
    范围要紧。比如 “修复计费 webhook 验证,只触及 app/api/billing 和 lib/billing”,胜过笼统的 “修复 bug”。宽松的循环会四处漂泊。
  3. Give it a budget and a stop condition. Max attempts, max runtime, max files, max spend, max consecutive failures. A loop running unattended is also a loop making mistakes unattended.
    设定预算和停止条件。最大尝试次数、最大运行时长、最大文件数、最大花费、最大连续失败次数。无人值守的循环同样会产生无人值守的错误。
  4. Add an independent verifier. A separate sub-agent grades the work, because the agent who wrote the code is the worst judge of whether it is done.
    加入独立的验证器。让一个子代理对工作进行评分,因为写代码的代理是最差的自评者。
  5. Run it on a cadence. /loop for an interval, cron for a schedule, hooks at lifecycle points, or GitHub Actions so it survives a closed laptop.
    让它按节奏运行。使用 /loop 设置间隔,cron 设定计划,hook 在生命周期节点触发,或 GitHub Actions 让它在笔记本关闭后仍然存活。
  6. Keep memory on disk. The model forgets between runs, so state lives in markdown or a board, not in the context window.
    将记忆保存在磁盘。模型在不同运行之间会忘记,状态应保存在 markdown、看板或其他持久介质,而不是上下文窗口。
The takeaway: the loop, not the model, is now the expensive and failure-prone part. Build it like someone who intends to stay the engineer responsible for the output, not just the person who starts the run.要点:循环,而非模型,才是现在最昂贵且最易出错的环节。要像对待自己负责的工程师那样去构建它,而不是仅仅把启动任务的工作交给它。
If you see any errors or things that need further clarification, don’t be afraid to reach out.如果你发现任何错误或需要进一步澄清的地方,请不要犹豫,随时联系。

Other Useful References
其他有用的参考

想发布自己的文章?想发布自己的文章?
升级为 Premium升级为 Premium
SW
发布你的回复

当前趋势

AirPods Pro 3
What’s Vini Jr. listening to?
Promoted by Apple