A Beginner-Friendly Loop Engineering Tutorial: Start Your First AI Agent Loop with One Command

This guide explains how Loop Engineering turns one-off AI prompts into repeatable agent workflows. The basic idea is to define the schedule, state, tools, verification, and human review process before trusting an agent to act repeatedly. For a first run, `daily-triage` is the safest starting point. Scaffold the loop, estimate token cost, audit readiness, and keep the first week in report-only mode. The larger lesson is not that humans disappear from development. Agents can move faster inside loops, but product judgment, safety boundaries, and the definition of “done” still depend on people. **The best first loop is not the most autonomous one. It is the one you can inspect, trust, and improve.**

发布于 2026年7月5日generalGEO 评分: 06 次阅读
Loop EngineeringAI agent looploop-initloop-auditloop-costAI coding agentsClaude Code loopCodex loopGrok loopOpenCode loopagent workflowAI automationGitHub loop-engineeringAndrew Ng product loopsagentic coding loop
图片为“Loop Engineering Tutorial”教程封面,左侧以紫色和蓝色渐变的无限符号标识“Loop”,下方是“Engineering”和“Tutorial”文字。右侧是流程图,展示了AI Agent Loop的流程,包括闪电标志的触发、大脑图标的人工智能处理、人形图标的人类参与、钥匙图标的安全验证、数据库图标的数据存储、信封图标的信息发送等环节。该图片与文档中介绍Loop Engineering教程的内容相契合,直观呈现了教程主题和流程。

A Beginner-Friendly Loop Engineering Tutorial: Start Your First AI Agent Loop with One Command

Introduction

If you have been hearing people talk about “Loop Engineering” but still feel unsure where to start, this guide gives you a practical entry point.

Instead of repeatedly writing prompts and checking every step by hand, a loop lets an AI agent work toward a small goal on a schedule. The system can assign the task, read the current state, run the agent, verify the result, and bring a human back in when judgment is needed.

The original report introduced an open-source Loop Engineering framework by Cobus Greyling. At the time of the report, the project had gained around 4.5k GitHub stars. The repository may show a different star count now because it has continued to grow.

图片展示的是Cobus Greyling的Loop Engineering GitHub仓库页面。页面左侧为仓库目录,包含Code、Issues、Pull requests等选项卡,以及main分支下的多个文件夹和文件,如docs、examples、patterns等。右侧是仓库简介,介绍其为AI代码设计系统提供实用模式、入门级CLI工具等,还列出了相关标签,如automation、mp等。该图片与文档中介绍Loop Engineering框架的上下文相关,直观呈现了该框架的GitHub仓库结构。

In short: the point is no longer only to write better prompts. The point is to design a reliable loop that can prompt, check, and iterate with clear boundaries.

图片展示了一段代码风格的文字,背景为深色。文字内容为“Stop prompting. Design the loop. Get a score.”,其中“Get a score.”以绿色突出显示。下方有“loop - init → loop - audit”及“10 → 70 → 100”的代码样式表达。该图片与上文介绍Loop Engineering的内容相关,强调从停止提示、设计循环到获取分数的流程,直观呈现了循环设计的步骤及评分变化,帮助理解循环工程的核心理念。

What Is Loop Engineering?

Loop Engineering is a way to design repeatable AI agent workflows. A loop is not just one prompt. It is a small operating system around an agent: it defines when the agent runs, what context it reads, what it is allowed to change, how the result is checked, and when a human needs to review the outcome.

A typical loop can be used for tasks such as:

  • daily project triage;
  • watching pull requests;
  • cleaning up CI failures;
  • scanning dependencies;
  • sorting issues;
  • cleaning up after merges;
  • drafting changelogs.

These are not always difficult tasks, but they are repetitive. They require attention, context, and a consistent standard. That is exactly the kind of work where a well-designed loop can help.

Why This Framework Is Getting Attention

The open-source framework described in the original article brings together practical loop patterns, starter templates, and command-line tools. It is designed for AI coding agents and supports workflows around tools such as Claude Code, Codex, Grok, and OpenCode.

The framework includes:

  • seven ready-to-use loop patterns;
  • starter templates for common scenarios;
  • loop-init for scaffolding a loop;
  • loop-cost for estimating token cost;
  • loop-audit for checking loop readiness;
  • state and budget files for longer-running workflows;
  • support for safer human review and phased rollout.

The core message is simple:

Stop prompting. Design the loop.

That does not mean prompts disappear. It means prompts become part of a larger system that can repeat work, track state, and verify results.

Start Fast: One Command

The fastest way to begin is to run loop-init inside a Git project.

Note: some reposted versions of the original article display command-line flags with a long dash. In a real terminal, use the standard double hyphen -- shown below.

npx @cobusgreyling/loop-init . --pattern daily-triage --tool claude

This command scaffolds the loop structure in your current project. You can replace claude with another supported tool such as grok, codex, or opencode, depending on the workflow you want to test.

The daily-triage pattern is a good starting point for beginners because it is lower risk than high-frequency automation. It focuses on scanning the current project state and producing a report before allowing any automatic changes.

Beginner-Friendly Loop Tutorial

Loop Engineering may sound abstract at first, but the framework breaks it down into a few concrete building blocks.

The Five Building Blocks Plus Memory

At a basic level, a loop is built from five main parts, plus memory and state.

图片展示了Loop Engineering的五个核心构建块,分别为自动化/调度、工作树、技能、插件和连接器(MCP)、子代理(Maker/Checker),以及记忆/状态。每个构建块以图标和文字形式呈现,如自动化/调度图标为日历,工作树图标为树,技能图标为书本,子代理图标为人形,记忆/状态图标为磁盘。这些构建块通过箭头连接,共同构成一个循环系统,体现了Loop Engineering框架中各部分的相互作用与联系。

Building Block What It Does in the Loop
Automation / Scheduling Runs the loop on a cadence, such as daily, hourly, or every few minutes.
Worktrees Creates isolated working environments so multiple agents do not overwrite each other.
Skills Stores reusable project knowledge, rules, and task instructions.
Plugins & Connectors Connects the loop to real tools through systems such as MCP, GitHub, Linear, or Slack.
Sub-agents Separates the maker role from the checker role so the same agent does not approve its own work.
Memory / State Keeps durable context outside the chat, usually through files such as STATE.md.

This structure makes the loop easier to reason about. You are not asking the model to “just handle everything.” You are giving it a defined environment, a schedule, a state file, a verification path, and a human handoff rule.

Seven Ready-to-Use Production Patterns

The framework also includes seven production-oriented patterns. Each pattern has a different cadence, risk level, and best use case.

图片展示了Loop框架的7个生产模式。每个模式以卡片形式呈现,包含模式名称、典型应用场景、建议起始模式及风险等级。如Daily Triage适用于扫描项目状态、问题等,起始模式为L1 report - only,风险等级为LOW。PR Babysitter适用于看护PR,起始模式为L1 watch,风险等级为HIGH。右侧还有一个绿色边框的卡片,提示“Not sure? Try the interactive picker”,供不确定模式时使用交互式选择器。

Pattern Typical Use Case Suggested Starting Mode
Daily Triage Scan project status, issues, CI, and commits. L1 report-only
PR Babysitter Watch pull requests through review, CI, rebase, and merge. L1 watch
CI Sweeper Watch failing checks and propose or apply small fixes. L2 cautious
Dependency Sweeper Check stale dependencies and security updates. L2 patch-only
Issue Triage Deduplicate, score, and label incoming issues. L1 propose-only
Post-Merge Cleanup Clean TODOs, minor debt, and follow-up work after merges. L1 off-peak
Changelog Drafter Draft release notes from commits and merged changes. L1 draft

The practical advice is to start with a low-risk loop. Daily triage is usually easier to trust because it does not need to change code immediately.

Interactive Pattern Picker

The project also provides an interactive picker. Instead of choosing a pattern manually, you can start from a pain point such as “PRs keep getting stuck,” “CI keeps failing,” or “issues are too noisy.”

The picker then recommends a loop pattern and gives you a starting command. This is useful when you know the problem but are not sure which loop should handle it.

Run Your First Loop

Here is a beginner-friendly way to run the first loop while keeping risk under control.

Step 1: Choose a Pattern

Start with daily-triage if this is your first time. It is a low-risk pattern and a good way to understand how the loop reads project state, writes notes, and prepares work for a human.

Step 2: Scaffold the Loop

Run the initialization command in the root directory of your Git project.

npx @cobusgreyling/loop-init . --pattern daily-triage --tool claude

You can swap the tool name if you are using a different AI coding agent.

npx @cobusgreyling/loop-init . --pattern daily-triage --tool grok
npx @cobusgreyling/loop-init . --pattern daily-triage --tool codex
npx @cobusgreyling/loop-init . --pattern daily-triage --tool opencode

You can also replace daily-triage with another supported pattern once you understand the basic flow.

Step 3: Estimate Token Cost

High-frequency loops can consume a lot of tokens, especially if they use sub-agents, long context, or repeated verification. Estimate the cost before you run a loop too often.

npx @cobusgreyling/loop-cost --pattern daily-triage --level L1

For early testing, keep the loop at L1 and avoid aggressive schedules.

Step 4: Audit Loop Readiness

Before trusting the loop, run an audit. The audit gives the project a readiness score from 0 to 100 and suggests improvements.

npx @cobusgreyling/loop-audit . --suggest

If your project is not ready, fix the missing pieces first. Common gaps include no state file, no verification step, unclear scope, missing budget limits, or weak human handoff rules.

If the project reaches a good readiness level, you can also generate a Loop Ready badge for your README.

npx @cobusgreyling/loop-audit . --badge

Step 5: Start in Report-Only Mode

Do not let the loop modify production code on day one. Start with report-only mode, then review the output manually.

For a Grok-style loop command, the first run can look like this:

/loop 1d Run loop-triage. Update STATE.md. No auto-fix in week one.

This tells the loop to triage, write state, and avoid automatic fixes during the first week.

Step 6: Read the Output

Open STATE.md and check what the loop found. This file acts as memory outside the conversation. It should show what the loop saw, what it did, what it skipped, and what needs human attention.

If the output is noisy or wrong, adjust the loop before increasing autonomy. A useful loop should become boring, predictable, and inspectable.

Loop Maturity: L1 to L3

Loop Engineering should be rolled out gradually. The maturity levels help you avoid giving too much freedom too early.

Level Meaning Recommended Use
L1 The loop reports findings and updates state, but does not change code. Best for first runs and low-risk adoption.
L2 The loop can make small changes with a verifier and human review. Useful after the team trusts the loop’s output.
L3 The loop can run for longer periods with limited unattended execution. Only suitable when scope, safety, cost, and verification are mature.

A good first goal is not full autonomy. A good first goal is a reliable L1 loop that gives you useful information without creating extra cleanup work.

The Standard Loop Process

A complete loop has a clear sequence. The original article described it as an eight-step process:

  1. scheduled trigger;
  2. task triage;
  3. read current state;
  4. create an isolated workspace;
  5. let the agent execute;
  6. run verifier checks;
  7. connect to Git or ticket systems;
  8. ask for human confirmation when needed.

图片展示了Loop的解剖结构,强调系统一次设计后可提示、验证和迭代。图中以流程图形式呈现,包含Schedule、Triage、STATE、Worktree、Implement、Verify、MCP/PR、Human gate等环节,各环节用不同颜色框标注,如Schedule用绿色框,Triage用蓝色框等。其中,Verify环节有勾选标识,MCP/PR环节有钥匙图标,Human gate环节有黄色框和“approve/escalate”字样。该图与上下文紧密相关,直观呈现了上文提到的八步完整循环过程。

This is the main difference between a casual prompt and a real loop. The agent is not simply “doing things.” It is working inside a controlled process with state, isolation, checks, and handoff.

Andrew Ng: Product Development Needs Three Loops

The original article also connected Loop Engineering to Andrew Ng’s discussion of product development. The key point is that building software with AI is not just one loop. For a real product, there are several loops moving at different speeds.

图片为Andrew Ng的推文截图,内容提到“循环工程”在Boris Cherry和Peter Steinberger提及后迅速在社交媒体上走红,成为让AI代理迭代构建软件的关键部分。Andrew Ng在信中分享构建0到1产品时的三个关键循环,即内层的编码循环、中间的开发者反馈循环、外层的用户反馈循环,这些循环不仅指导软件构建,还决定构建何种软件。图片与上下文紧密相关,是对上下文提到的“循环工程”概念的阐述。

1. Agentic Coding Loop

The innermost loop is the coding loop. A human gives the agent a product specification and evaluation criteria. The agent writes code, tests it, fixes problems, and keeps iterating.

This loop can be fast. In some cases, it may produce a new version every few minutes.

2. Developer Feedback Loop

The next layer is the developer feedback loop. The agent can test and revise, but the developer still checks whether the result feels right, fits the product direction, and solves the real user problem.

This loop is slower. It may run every few dozen minutes or every few hours, depending on the product and the complexity of the changes.

3. External Feedback Loop

The outer layer is the user feedback loop. Once the product reaches friends, alpha testers, or real users, the team starts learning from feedback, usage data, and experiments.

This loop is slower again. It may take hours, days, or weeks.

图片展示了产品开发中的三个关键循环:Agentic Coding Loop、Developer Feedback Loop、External Feedback Loop。每个循环由箭头连接,形成闭环。Agentic Coding Loop由Coding agent和Product spec/evals组成,时间周期为几分钟;Developer Feedback Loop包含Developer vision和External feedback,周期为几小时;External Feedback Loop则涉及External feedback,周期为几天。该图与上下文紧密相关,直观呈现了文中提到的三个产品开发循环及其时间特点。

Together, the three loops create a practical product-building chain: the agent helps produce versions quickly, the developer decides what the product should become, and users prove whether the direction is worth continuing.

Why Human Taste Still Matters

Loop Engineering does not remove humans from software development. It changes the human role.

The agent can handle repeated execution, but it still needs clear boundaries, strong verification, and product judgment. The human still understands context: what users need, what trade-offs matter, what should not be automated, and what “good enough” really means.

That is why a loop can be installed with one command, but the definition of “done” still belongs to the people building the product.

Source Note

Original source: BAAI Hub article, syndicated from QbitAI / WeChat. The article also referenced the Loop Engineering GitHub repository and Andrew Ng’s public post on X.

Image note: the opening meme image and the final QR/contact promotional banner from the source page were excluded because they are not necessary for understanding the tutorial. The remaining images are included only where they support the technical explanation.

FAQ

What is Loop Engineering?

Loop Engineering is a way to design repeatable workflows for AI agents. Instead of prompting the agent manually for every small task, you define a loop with scheduling, state, tools, verification, and human handoff.

How do I start a Loop Engineering project?

The fastest starting point is to run npx @cobusgreyling/loop-init . --pattern daily-triage --tool claude inside a Git project. For beginners, daily-triage is usually safer than high-frequency loops because it can start in report-only mode.

Why does Loop Engineering use STATE.md?

STATE.md gives the loop durable memory outside the chat session. It helps the loop remember prior findings, last actions, unresolved items, and human overrides.

What is the Loop Ready score?

The Loop Ready score is an audit result produced by loop-audit. It checks whether the project has enough structure, state, verification, cost limits, and safety controls to run a loop responsibly.

Can an AI agent loop run unattended?

It can, but it should not start that way. A safer path is L1 report-only first, then L2 assisted fixes with verification, and only later L3 unattended runs when scope, safety, and cost controls are mature.

Why should I estimate token cost before running a loop?

Loops can become expensive if they run often, use long context, or spawn multiple sub-agents. loop-cost helps you estimate usage before a high-frequency workflow burns through budget.

How does Andrew Ng’s three-loop idea relate to this?

The engineering loop helps agents build and revise software quickly. Developer feedback and user feedback are slower loops that decide whether the product is useful, usable, and worth continuing.

Related Tools

  • Loop Engineering: Open-source patterns, starters, and CLI tools for designing AI agent loops.
  • Loop Engineering Showcase: Interactive overview with patterns, primitives, and a readiness simulator.
  • Node.js: Runtime needed for using npx-based CLI tools.
  • npm: Package ecosystem used to run the Loop Engineering CLI commands through npx.
  • Git: Version control system used for repositories and worktree-based isolated execution.
  • GitHub Actions: Automation platform that can support scheduled checks and loop validation workflows.
  • Model Context Protocol: Protocol for connecting AI systems to external tools and data sources.

Related Links

Summary

This guide explains how Loop Engineering turns one-off AI prompts into repeatable agent workflows. The basic idea is to define the schedule, state, tools, verification, and human review process before trusting an agent to act repeatedly.

For a first run, daily-triage is the safest starting point. Scaffold the loop, estimate token cost, audit readiness, and keep the first week in report-only mode.

The larger lesson is not that humans disappear from development. Agents can move faster inside loops, but product judgment, safety boundaries, and the definition of “done” still depend on people.

The best first loop is not the most autonomous one. It is the one you can inspect, trust, and improve.