Agent Loop

创建时间: 2026-06-09 来源: [[sources/WTF Is a Loop Peter Steinberger vs. Boris Cherny.md]] 相关: Peter-SteinbergerBoris-ChernyGeoffrey-HuntleySteve-YeggeHarness-EngineeringClaude-Code-Extension-LayerAgent-Paradigm-ShiftVibe-Coding-to-Agentic-EngineeringAgent-Native-Infrastructure


定义

Agent Loop 是一个小程序,它代替人类去提示 coding agent,读取输出,判断是否完成,没完成就继续循环。人类从「loop 里面的人」变成「loop 的作者」,模型变成子程序。

Boris Cherny 的干净定义(2026-06-02,WorkOS Acquired Unplugged):

“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.”

Peter Steinberger 的引爆版本(2026-06-07,X):

“You shouldn’t be prompting coding agents anymore. You should be designing loops that prompt your agents.”

两者的关系:Steinberger 和 Cherny 从两个侧面描述同一个实体 —— Steinberger 强调设计循环技能复用,Cherny 强调循环作为抽象层级自主验证

演化谱系

“Loop” 这个词在 AI 编程语境中至少隐藏了五种不同的东西。以下是按时间线排列的阶梯:

Stage 1:学术 While-Loop(ReAct,2022)

ReAct 论文 将其形式化:模型 reasoning → 调用工具 → 读取结果 → 重复直到完成。

  • 单模型、单循环
  • 人类全程旁观
  • 核心贡献:将推理与行动交织,而非分离

Stage 2:目标驱动自循环(AutoGPT,2023)

给模型一个 goal,让它自己提示自己。因 infamous 的”无限循环做无用功”而声名狼藉,也催生了 “agents are a toy” 的批评。

  • 创新:移除人类逐轮干预
  • 失败:缺乏有效停止条件和上下文管理

Stage 3:上下文纪律循环(ralph loop,2025-07)

Geoffrey Huntley 发布的 ralph —— 一个 bash one-liner,将同一 prompt 文件反复 pipe 给 agent。

  • 真正创新:每轮迭代强制重置上下文到固定锚文件,而非让对话无限增长
  • Huntley 用约 $297 的成本构建了一门完整编程语言
  • 局限:假设终端保持打开

Stage 4:产品化验证循环(/goal,2026 春)

Codex 和 Claude Code 先后推出 /goal 命令:运行 ralph 式循环,但增加一个小型验证模型确认任务完成才停止。

  • 从”人类判断何时停止”到”模型判断何时停止”
  • 标志着 loop 从脚本进入产品功能

Stage 5:编排监督循环(Orchestration Loop,2026)

Cherny 和 Steinberger 所指的真正新东西。四项关键变化:

维度ralph 时代orchestration 时代
工作单元单个任务loop 本身
监督关系单 agent 自循环loops 监督其他 loops,并发运行
触发方式人工启动定时调度取代人工触发
状态管理终端内存(假设不关闭)git-backed 持久化 + 故障恢复

Steve Yegge 的 Gas Town(2026-01 开源)是这一阶段的落地实现:20-30 个 Claude Code 实例由 Mayor agent 协调,patrol agents 运行持续 loop,状态存储在 git 中。

Loop ≠ Cron

最精辟的 skeptic line:

“Cronjobs have funny re-branding rn.”

回答是半对半错:

  • 对的一半:调度层确实是 cron。Boris 的 loops 跑在 cron 上,Claude Code 的 /loop 底层也使用 cron。如果 loop 的定义只是”定时运行的东西”,那它确实发明于 1975 年。
  • 错的一半:cron 运行的是固定脚本,loop 运行的是模型驱动的决策者。每一 tick,模型观察当前状态、决定下一步、执行、检查结果、决定是否继续。决策是模型的,不是人类的,也不是硬编码分支。

** honest framing**:loops 不是新魔法,也不是旧 cron。它们是 cron + 一个决策-maker 在循环体中,而有趣的工程全部围绕”如何让这个决策-maker 不跑出悬崖”。

反馈是 Loop 的根基

Loop 的可信度完全取决于它检查自身工作的能力。

“A loop with no feedback is a machine for generating confident mistakes.”

生产级验证机制

  1. roborev(Dan Kornas):在后台 review 每个 commit,将发现反馈给 agent,趁 context 还新鲜时修正
  2. End-to-end self-verification(Boris 的五原则之一):Claude 必须能自行验证工作成果
  3. TikTok 上的干净总结:“Loop mode is one of the clearest signs that AI coding is moving from one-off prompts to background operations.”

反馈设计的核心 tension

  • 开放 loop(只写不验)= 自信的错误制造机
  • 闭环 loop(写→运行→读结果→修正)= 实际可用的系统

成本转移:Loop 成为昂贵部分

“Every ai agent i shipped this year is a for-loop, an llm call, and a try/catch around the json parsing. The only thing agentic about it is the anthropic bill at the end of the month.” — @rohit_jsfreaky

当模型写代码的成本趋近于零,成本转移到 loop 管理上

  • Uber 在 4 个月内烧完全年 AI 预算,随后将每位工程师的 Claude Code / Cursor 月限额封顶在 $1,500/工具
  • “The costliest thing in AI coding is no longer writing code, it’s managing the agent loop.”

三个 Hard Stops

每个生产级 loop 必须实现的三重保险:

  1. 最大迭代次数上限(max iteration count)
  2. 无进展检测(no-progress detection)—— 连续 N 轮没有实质变化时终止
  3. 预算天花板(token 或 dollar budget ceiling)

“Without guardrails, you get infinite loops and billing surprises orders of magnitude over budget.”

Gartner 将 agentic AI 置于”膨胀期望峰值”,仅约 17% 的组织实际部署了 agent。时间线与落地收据之间的落差是真实状态。

Skill:Loop 内部的可复用单元

Steinberger 的核心洞见:loop 是 plumbing,asset 是它调用的 skill。

  • 一个空循环 = while-true 围绕一个陌生人
  • 一个调用 sharp、tested、named skills 的循环 = 复利系统

这与 Claude-Code-Extension-Layer 中的 Skills 层直接对应:将专业化工作流和领域知识打包为按需加载的可复用单元。

Skill 与 Prompt 的区别

PromptSkill
一次性指令命名、测试、版本化的能力单元
每次重新推导一次创建,多次调用
隐含知识显式编码的规范与边界

Loops that re-derive everything just burn money. Loops that call a library of skills compound.

在 Harness Engineering 中的位置

Agent Loop 是 Harness-Engineering 的核心机制之一:

  • 将工作分解为可处理单元 → loop 的每次迭代处理一个子任务
  • 分离生成与评估 → loop 内部的 feedback/verification 层
  • 将品味编码为工具 → skill 作为可机械执行的规则
  • 结构化交接工件 → loop 间的状态传递(git-backed persistence)

Claude Code 的 /loop/goal 命令是 harness 层的产品化入口。见 Claude-Code-Extension-Layer

实践入口

最简单的 on-ramp(Boris 的 canonical starter):

/loop babysit all my PRs. Auto-fix build issues, and when comments come in, use a worktree agent to fix them.

更深的水域:参考 Gas Town 的 Mayor + patrol agents 架构,或构建自己的 multi-loop supervision 系统。

关键模式总结

  1. Loop = cron + decision-maker:模型而非硬编码分支决定每一步动作
  2. 谱系真实存在:ReAct → AutoGPT → ralph → /goal → orchestration,单 agent ralph 已过时,multi-agent supervision 是新层
  3. 可信度来自反馈:连续 review 和 validation gate 是 loop 可用的前提
  4. 成本已转移:管理 loop 的开销 > 写代码的 token 开销,必须设 hard stops
  5. 可复用单元是 skill 而非 prompt:loop 调用命名技能才能复利,重新推导只会烧钱
  6. 停止条件决定生死:max iter + no-progress detection + budget ceiling 是生产底线

引用

  • “I don’t prompt Claude anymore. I have loops that are running.” — Boris Cherny
  • “You shouldn’t be prompting coding agents anymore. You should be designing loops that prompt your agents.” — Peter Steinberger
  • “Cronjobs have funny re-branding rn.” — X reply, June 2026
  • “The costliest thing in AI coding is no longer writing code, it’s managing the agent loop.” — @runes_leo
  • “A lot of people are rolling their eyes on Twitter, but my ears are perked up.” — r/ChatGPTCoding

参考资料