Glean 拾遗
Daily /2026-07-22 / How to Build the Loops That Just Replaced Entire Prompt Engineering

How to Build the Loops That Just Replaced Entire Prompt Engineering

Source x.com Glean’d 2026-07-22 06:00 Read 9 min
AI summary

The era of crafting better prompts to improve AI agents is quietly ending. Top engineers now build 'loops'—systems where agents plan, execute, verify, and iterate without human intervention. Using Karpathy's overnight 700-experiment run that found 20 optimizations as a case study, the article breaks down loop architecture: automation heartbeat, skill files (project context), sub-agents (writer vs reviewer), connectors, and a verifier gate. It warns against Ralph Wiggum loops (premature exit) and comprehension debt (accumulated unread code). Practical advice: start with one boring recurring task, verify manually before scheduling, measure cost per accepted change. Essential for engineers building production agent workflows.

Original · 9 min
x.com ↗
§ 1

How to Build the Loops That Just Replaced Entire Prompt Engineering

如何构建刚取代整个提示工程的循环

§ 2

For two years, getting more out of an AI agent meant writing a better prompt.

That era is quietly ending. The best engineers in the world stopped writing prompts a while ago and started writing loops - systems that prompt the agent, check the result, and keep running until the work is done.

Karpathy's overnight script found 20 optimizations he had missed in two decades of tuning by hand. Boris Cherny, who built Claude Code, has not written a line of code this year. Anthropic engineers now merge close to 8x more code per day than they did in 2024.

None of them typed anything smarter. They stopped typing at all.

Here is what a loop actually is, when you need one, when you do not, and how to build your first one.

两年来,从AI智能体中获取更多价值意味着编写更好的提示词。

那个时代正在悄然结束。世界上最好的工程师们早就停止编写提示词,转而开始编写循环——一种系统:提示智能体、检查结果、持续运行直到工作完成。

Karpathy的隔夜脚本发现了他在20年手动调优中遗漏的20个优化。Boris Cherny,Claude Code的构建者,今年一行代码都没写。Anthropic的工程师现在每天合并的代码量接近2024年的8倍。

他们中没有一个人输入了更聪明的东西。他们干脆停止了输入。

以下是循环究竟是什么,何时需要它,何时不需要,以及如何构建你的第一个循环。

§ 3

700 experiments while the human slept

March 2026. Andrej Karpathy pushes three files to GitHub. Around 630 lines of code.

One file held the model. One scored it. One told the agent what to explore and what to leave alone. The agent could only touch the training file. Nothing else.

The cycle was boring on purpose. Read the code, propose a change, train for five minutes, check if the score improved, keep the change if it did, roll back if it did not, then go again.

He pointed it at a model he had already tuned by hand for two decades. He let it run for two days.

It ran 700 experiments. It found 20 improvements. One of them was a missing scalar multiplier in the attention mechanism, subtle, not the kind of bug any linter would ever catch, but exactly the kind of thing a careful engineer could have found and never did.

Shopify's CEO ran the same trick overnight on an internal model. He woke up to a 19 percent quality gain on a model half the size of the previous one.

The insight is not "the AI is smarter." Humans get tired after experiment twelve. Loops do not get tired at all.

人类睡觉时的700次实验

2026年3月。Andrej Karpathy向GitHub推送了三个文件。大约630行代码。

一个文件包含模型,一个文件负责评分,一个文件告诉智能体要探索什么、放过什么。智能体只能触碰训练文件。不能动其他任何东西。

这个循环故意设计得很无聊。读取代码、提出修改、训练五分钟、检查分数是否提升——提升则保留修改,没提升则回滚,然后继续。

他把这个循环对准了一个他已经手动调优了20年的模型。让它运行了两天。

它执行了700次实验,找到了20个改进点。其中一个是注意力机制中缺失的标量乘子——很微妙,不是任何linter都能捕捉到的bug,但恰恰是细心工程师本应发现却从未发现的那种问题。

Shopify的CEO在内部模型上用同样的技巧跑了一夜。醒来发现,模型大小减半,质量却提升了19%。

启示不是“AI更聪明了”。人类到第12次实验就累了。循环根本不会累。

§ 4

§ 5

A loop is not a prompt on a schedule

Most people hear "loop" and think cron. That misses the whole thing.

A prompt is one instruction. A loop is a goal the AI keeps working toward until it gets there, with nobody in the chair. It plans, executes, verifies its own result, feeds the result back in, and repeats.

Five stages: discover, plan, execute, verify, iterate. Three of them do the actual work.

The verifier is the heart of the loop. Without a real gate on the output, you do not have a loop, you have the agent grading its own homework forever. A gate is a test that passes or fails, a build that compiles or crashes, a linter that returns zero or non-zero. Not a second agent with an opinion.

State is what makes the loop learn. A file on the side, a Linear board, a project log, somewhere outside the conversation that records what was tried and what failed. Tomorrow's run resumes instead of starting from scratch.

A stop condition is what keeps it sane. Every real loop has two exits: the goal is met, or a hard cap fires. Skip this and you have built a machine that runs all night for nothing.

Miss any of the three and you have not built a loop. You have built an expensive script.

循环不是定时执行的提示词

多数人听到“循环”就会想到cron。这完全理解错了。

提示词是一条指令。循环是一个目标,AI持续朝着它努力直到达成,无需人坐在椅子上。它规划、执行、验证自己的结果,将结果反馈回来,然后重复。

五个阶段:发现、规划、执行、验证、迭代。其中三个阶段做实际工作。

验证器是循环的核心。如果输出没有真正的关卡,你拥有的就不是循环,而是让智能体永无止境地给自己评分。关卡是一个能通过或失败的测试、能编译或崩溃的构建、能返回零或非零的linter。不是第二个有主见的智能体。

状态让循环能够学习。一个侧边文件、一个Linear看板、一个项目日志,记录尝试了什么、什么失败了。明天的运行从中断处恢复,而不是从头开始。

停止条件让循环保持理智。每个真正的循环都有两个出口:目标达成,或者硬性上限触发。跳过这个,你就造出了一台整夜空转的机器。

三者缺一,你就没有构建出循环。你构建的只是一个昂贵的脚本。

§ 6

The four conditions before you build one

Loops earn their cost only when four things are true at the same time. Miss one and the setup takes more than it returns.

  • The task repeats at least weekly. Less than that and the setup cost never amortizes.

构建循环前的四个条件

循环只有在四个条件同时满足时才值得投入成本。缺一个,搭建所花的时间就超过回报。

  • 任务至少每周重复一次。否则设置成本永远无法摊销。
§ 7
  • Something can automatically fail the work. A test, a type check, a linter, a build.
  • 存在能自动判定工作失败的机制:一个测试、类型检查、linter或构建。
§ 8
  • Your token budget can absorb the waste. Loops re-read context, retry, explore.
  • 你的token预算能承受浪费。循环会重复读取上下文、重试、探索。
§ 9
  • The agent has senior engineer tools. Logs, a reproduction environment, the ability to run the code it writes and see what breaks.
  • 智能体拥有高级工程师工具:日志、复现环境、运行自己编写的代码并观察哪里出问题的能力。
§ 10

The honest version, the part nobody selling loops will tell you: most people do not need the heavy version yet. If you are on a consumer plan trying to run overnight verification loops on serious work, the token bill arrives before the productivity gain does.

Good first loops are the boring ones. CI triage. Dependency bumps. Lint-and-fix passes. Flaky test reproduction. Issue-to-PR drafts on a codebase with strong tests already in place.

Bad first loops are the interesting ones. Architecture rewrites. Auth code. Payments. Anything where "done" is a judgment call and a human still has to weigh in.

坦诚地说,这是那些兜售循环的人不会告诉你的部分:多数人还不需要重型版本。如果你用的是消费级订阅,却想在严肃工作上运行隔夜验证循环,token账单会在生产力提升之前到来。

好的初次循环是那些无聊的任务:CI分类、依赖升级、lint并修复、复现不稳定测试、在有强测试的代码库上将issue草拟为PR。

坏的初次循环是那些有趣的任务:架构重写、认证代码、支付。任何“完成”需要判断、人类仍需介入的任务。

§ 11

The five blocks that make a loop real

Every real loop is assembled from the same five pieces. Claude Code and Codex ship all of them now.

The first is automation. The heartbeat. Something that fires the loop on a schedule or an event. /loop runs on a cadence. /goal keeps going until a condition you defined actually holds. Without a heartbeat, the loop is a script you ran once and forgot about.

构建真实循环的五个块

每个真实的循环都由相同的五个部件组装而成。Claude Code和Codex现在全都内置了它们。

第一是自动化——心跳。一个按计划或事件触发循环的机制。/loop按节奏运行。/goal持续运行直到你定义的条件真正达成。没有心跳,循环就是一个你跑过一次就忘记的脚本。

§ 12

The second is a skill. Project knowledge saved as a claude-md file the agent reads on every run. Without it, the loop re-derives your context from zero each cycle. With it, intent compounds. The loop knows your conventions, your build steps, the thing you never do because of that one incident three months ago.

第二是技能——以claude-md文件形式保存的项目知识,智能体每次运行都会读取。没有它,循环每次都要从零推导你的上下文。有了它,意图不断累积。循环了解你的约定、构建步骤、以及因为三个月前那次事故你从来不做的事情。

§ 13

The third is sub-agents. The maker and the checker cannot be the same model. The one that wrote the code is far too generous grading its own work. The one that wrote the article misses its own weak sections. Writer fast and cheap. Reviewer slow and strict. That separation is most of the quality.

第三是子智能体。创造者和检查者不能是同一个模型。写代码的那个人给自己的作品打分时会过于慷慨;写文章的那个人会忽略自己文章的薄弱部分。写作应快速且廉价,审校应缓慢且严格。这种分离是大部分质量的来源。

§ 14

The fourth is connectors. The loop opens the pull request, closes the ticket, pings the channel when CI turns green. This is the difference between an agent that says "here is a suggested fix" and a report waiting for you in the morning saying the PR is already merged.

第四是连接器。循环负责创建拉取请求、关闭工单、在CI变绿时通知频道。这区分了一个说“这是建议修复”的智能体,和一份早上等你、说明PR已经合并的报告。

§ 15

The fifth is the verifier. The test, type check, or build that fails bad work automatically. Everything else is plumbing. This is the block that decides whether the loop helps you or just spends your money.

Stack these together and you get what serious teams now run at scale. Dozens of loops, each owning one narrow job, running side by side while everyone sleeps. One engineer used a fleet loop like this to rewrite an entire codebase from one language to another in about six days, work that would have taken close to a year by hand.

第五是验证器——能自动让差劲工作失败的测试、类型检查或构建。其余都是管道。正是这个块决定了循环是在帮你还是仅仅在花你的钱。

把这些组装起来,你就得到了认真团队如今规模化运行的东西:几十个循环,每个负责一个狭窄的任务,在所有人睡觉时并行运行。一位工程师用这样的舰队循环在六天内将整个代码库从一种语言重写为另一种语言,这种工作手动完成需要将近一年。

§ 16

§ 17

Where loops fail silently

Loops do not crash. They bill you in silence. Two failure modes worth naming, both of which get worse as the loop gets better, not easier.

The first is the Ralph Wiggum loop. Engineer Geoffrey Huntley documented it. The agent decides it is done too early, emits the completion signal on a half-finished job, and the loop exits satisfied. Without a hard objective gate, the loop keeps running the next night, keeps spending, keeps producing work nobody will accept.

The fix is not a smarter agent. It is a dumber gate. A test that passes or fails. A build that compiles or does not. Something with no opinion.

循环悄然失败之处

循环不会崩溃。它们悄然向你收费。有两种值得命名的失败模式,而且随着循环变得更强大,这两种情况会更糟,而不是更轻松。

第一种是Ralph Wiggum循环。工程师Geoffrey Huntley记录过。智能体过早认定工作完成,在半成品上发出完成信号,循环满意地退出。如果没有一个硬性的客观关卡,循环会继续第二天晚上运行,继续花钱,继续产出没人接受的工作。

解决方案不是更聪明的智能体,而是更傻的关卡。一个通过或失败的测试。一个能编译或不能的构建。一个没有主见的东西。

§ 18

The second is subtler. Comprehension debt. The faster the loop ships code you did not write, the larger the gap between what your repo contains and what you actually understand. A smooth-running loop charges compound interest on that gap. The day you have to debug a system nobody on the team has read costs more than the tokens ever did.

Cognitive surrender comes with it. When the loop runs itself, it is tempting to stop forming an opinion and accept whatever comes back. Designing the loop is the cure when you do it with judgment. It is the accelerant when you do it to avoid thinking. Same action, opposite outcome.

Two people can build the exact same loop and end up in opposite places. One uses it to move faster on work they understand deeply. The other uses it to avoid understanding the work at all. The loop does not know the difference. You do.

第二种更微妙:理解负债。循环交付你未曾编写的代码越快,你的仓库包含的内容与你实际理解之间的鸿沟就越大。一个运行顺畅的循环,会在这个鸿沟上收取复利。当你不得不在团队中没人读过的系统上调试时,付出的代价远超所有的token费用。

随之而来的是认知投降。当循环自行运转时,很容易停止形成自己的主张,接受任何返回的结果。当你带着判断力设计循环时,它是解药;当你为了避免思考而设计循环时,它是助燃剂。同样的动作,截然相反的结局。

两个人可以构建完全相同的循环,最终却走向相反的方向。一个用它来更快速地推进他深有了解的工作;另一个用它来完全避免理解工作本身。循环不知道其中的区别。你知道。

§ 19

§ 20

Start with one loop, not ten

The mistake everyone makes is trying to build the whole system on day one. Ten loops, a dashboard, a fleet. It collapses by the weekend because you cannot tell which loop did what.

Start with one. Pick the most annoying recurring task you have, the thing you check every morning out of habit, and turn that single job into a loop. Let it run for a few days. Watch where it overreaches. Watch where it misses. Tighten. Then add the second one.

The order matters more than the tools. Get one manual run reliable first, not fast, reliable. Turn that run into a claude-md skill. Wrap the skill in a loop with an objective gate and a hard stop condition. And then, only then, put it on a schedule. Skipping ahead, scheduling something you have not made reliable by hand, is exactly how loops blow up while you sleep.

The metric that decides if the loop is working is not tokens spent or tasks attempted or PRs opened. It is cost per accepted change. If your accepted-change rate is below 50 percent, you are doing the review work the loop was meant to remove, and the loop is losing.

Karpathy stopped writing training code. Cherny stopped prompting. Neither of them stopped thinking. If you take one thing from this, take that. The loop is a system that does the boring 95 percent while you keep your full attention on the 5 percent that actually carries risk.

You are paying for a fleet of agents and using one chat window.

Follow me and subscribe to my Telegram channel: https://t.me/+75nMf005jRpjMDU1

从一个循环开始,不要十个

每个人都犯的错误是第一天就想构建整个系统:十个循环、一个仪表盘、一个舰队。到周末就崩溃了,因为你分不清哪个循环做了什么。

从一个开始。挑出你工作中最令人烦恼的重复性任务,那个你每天早上习惯性检查的事情,把这个单一任务变成一个循环。让它运行几天。观察它哪里越界了,哪里遗漏了。收紧。然后再添加第二个。

顺序比工具更重要。先让一个手动运行变得可靠——不是快速,而是可靠。把这个运行变成一个claude-md技能。将技能包裹在循环中,设置一个客观关卡和一个硬性停止条件。然后,只有在那之后,才把它放到计划上。跳过步骤、把还没手动验证可靠的事情安排进计划,正是循环在你睡觉时爆炸的原因。

判断循环是否有效的指标不是花了多少token、尝试了多少任务、打开了多少PR,而是每次被接受的变更的成本。如果接受率低于50%,你实际上还在做着循环本应替你消除的审查工作,那么这个循环是在亏钱。

Karpathy不再编写训练代码。Cherny不再写提示词。但他们都没有停止思考。如果有什么值得你从本文带走的,那就是这一点:循环是一个系统,它搞定无聊的95%,而你保持全神贯注于真正有风险的5%。

你正在为一个智能体舰队付费,却只用着一个聊天窗口。

欢迎关注我的Telegram频道:https://t.me/+75nMf005jRpjMDU1

Open source ↗