循环(loop)到底是什么?
循环是面向 AI 编码智能体的一种可复用工作流,由四部分构成:目标、用于客观验证进度的检查命令、退出条件,以及最大迭代次数上限。把启动提示词粘贴给你的智能体,它就会自主推进任务,每一轮都重新运行检查命令,直到满足退出条件为止。
可复用的提示词和分步工作流,让编码智能体自主推进任务直到完成。
Run the production build, fix compile and bundling errors, and loop until the build succeeds.
Run automated accessibility checks on changed routes, fix violations, and repeat until the audit is clean.
Add focused tests until coverage meets your threshold (e.g. 80%), without changing production behavior unnecessarily.
Poll CI on an interval, investigate failures when checks go red, and push fixes until green.
Fetch the latest failed CI run, reproduce the failure locally, fix it, and repeat until checks pass.
Every 15 minutes, inspect open PRs with a watch label: nudge reviewers, fix CI, rebase if behind main.
Run the formatter, fix any remaining style issues, and loop until the codebase formats cleanly with no diffs.
Fresh-context loop: pick one incomplete story from prd.json, implement it, run backpressure checks, commit, and update progress before the next iteration.
Run failing tests repeatedly, classify each failure as flaky or real, and fix only confirmed regressions.
Hook that runs tests before git commit commands to block commits when the suite is red.
After implementation, run a cleanup pass: remove debug code, tighten naming, delete dead branches, and align with project conventions.
When a check fails twice the same way, append a guardrail sign to .ralph/guardrails.md so the next iteration avoids repeating it.
After code changes, find affected docs and update README, API references, and inline comments to match.
On an interval, hit health and smoke endpoints after a deploy until all checks return healthy responses.
Fix high/critical npm audit findings one at a time with test verification — not a blind npm audit fix --force.
Poll open PRs labeled codex-watch every 15 minutes, review activity, and flag regressions or stale threads.
Test-first loop: write a failing test, implement the minimum code to pass, refactor, and repeat.
Keep openapi.yaml valid and in sync with route handlers — lint the spec and fix drift each pass.
When implementation claims done, a separate verifier pass runs build, lint, and tests with no access to the implementer's rationale.
Find and remove dead exports, unused files, and orphan dependencies — loop until knip reports clean.
After shipping a feature, loop until CHANGELOG.md has a user-facing entry and conventional commits are reflected.
Loop until API responses match the OpenAPI or JSON Schema contract — catch drift between docs and implementation.
Implement on a branch, run tests, push, open a PR, wait for CI, and loop until checks pass and the PR is ready to merge.
On each failed repro attempt, write a short reflection to disk, then retry with that memory — avoids repeating the same wrong fix.
Run database migrations, fix schema issues, and loop until migrations apply cleanly in dev.
Hook that runs smoke tests after git merge or rebase to catch integration regressions immediately.
Run a fixed smoke checklist against staging after deploy: auth, core flows, and error budgets.
Review your own diff like a senior reviewer, fix issues, and repeat for three passes before opening the PR.
Run lint and typecheck, fix reported issues, and loop until the codebase is clean.
Hook-based loop that runs related tests after file edits to catch regressions early.
关于 AI 编码 Agent 可复用 Loops 的常见问题
循环是面向 AI 编码智能体的一种可复用工作流,由四部分构成:目标、用于客观验证进度的检查命令、退出条件,以及最大迭代次数上限。把启动提示词粘贴给你的智能体,它就会自主推进任务,每一轮都重新运行检查命令,直到满足退出条件为止。
普通提示词是一轮对话里的一条指令;循环则是围绕多轮重复的一整套系统——它告诉智能体如何验证自己的产出、什么时候该停止,这样它就能持续推进,而不需要你在每次尝试后重新手动下达指令。这种做法就是 Loop Engineering(循环工程)。
本页大多数循环都不绑定特定智能体——启动提示词是纯文本,可以直接粘贴给 Claude Code、Cursor、Codex 或其他任意编码智能体使用。每条循环的详情页都列出了它专门构建并测试过的智能体。
当任务需要多轮修改并且有客观验收方式时,适合使用 Loop,例如修复测试、处理 CI 失败、代码审查、部署验证和批量重构。一次性问答或没有明确完成标准的任务通常不需要循环。
优先选择稳定、可重复且返回明确退出码的检查命令,例如测试、类型检查、Lint 或部署健康检查。退出条件应描述可验证的完成状态,并设置最大迭代次数,避免 AI Agent 无限重试。
循环会重复执行提示词和命令,因此应限制文件、网络、密钥与部署权限,在隔离分支或沙盒中运行高风险任务,并保留最大迭代次数和人工复核步骤。不要让循环在未审查的情况下执行破坏性命令。