Loop Engineering 101

The complete guide to ship code while you sleep

๐Ÿ“Œ1. What is a Loop?

A loop is an agent that works, checks, and retries by itselfโ€”without you prompting each step.

๐Ÿ“ŒKey Steps in a Loop:

Discovery: Find what it needs to know.
Planning: Break the goal into clear steps.
Execution: Do the work.
Verification: Check the result against the goal.
Iteration: Fix the gaps and run again.

๐Ÿ“ŒExample:

Reproduce the bug, write a failing test, fix the code, rerun the suite, repeat until itโ€™s green. You write the cycle once and walk away.

๐Ÿ“ŒKey Takeaway:

A task is loop-ready when:

It repeats often enough to be worth wiring.
It has a definition of done you can check automatically.
A wrong attempt is cheap to throw away.

๐Ÿ“Œ2. Open vs Closed Loops

๐Ÿ“ŒOpen Loops = Exploratory

Agents freely explore and discover.
High token usage (50Kโ€“2M+).
Can drift off-target and produce AI slop.
Risky as a starting point.

๐Ÿ“ŒClosed Loops = Bounded

Clear goal, defined steps, validation checks.
Agents operate within constraints.
Predictable, efficient, and easier to control.
Better for most teams.

Key Takeaway: The closed loop focuses on what matters most. It improves with each pass, sharpening the result over time.

๐Ÿ“Œ3. The Anatomy of a Loop

A loopโ€™s anatomy is six parts you wire once:

Triggers: What starts the loop.
Isolates: What narrows the scope.
Informs: What provides context.
Connects: What links agents.
Builds: What creates the result.
Remembers: What stores the lessons learned.

๐Ÿ“ŒThe 6 Building Blocks of Every Good Loop:

Automations

The hardware, runtimes, and agents.

Worktrees

Parallel agents, safe collisions.

Skills

Project knowledge, active recall, every loop.

Plugs & Connectors

APIs, PRs, tickets, Slack.

Subagents

Split the builder and reviewer into two agents.

Memory

Links the conversation; the loop never forgets.

๐Ÿ“ŒKey Takeaway:

Donโ€™t keep rules and memory only in the chat.
Donโ€™t trigger every run by hand.
Donโ€™t wire all six parts before you need them.

๐Ÿ“Œ4. Single Agent vs Fleet

๐Ÿ“ŒSingle-Agent Loop:

One agent improves its own work by repeating the cycle until the result is good.
Simple, cheap, and enough for most tasks.

๐Ÿ“ŒFleet Loop:

Multiple specialized agents work together under an orchestrator.
Use it when one agent isnโ€™t enough for the job.

๐Ÿ“Œ5. Loop in Practice

๐Ÿ“ŒImplementation:

A loop is implemented as:

The goal and rules loaded from disk.
The maker, checker, gate, and one line where the loop turns a failure into a new rule.
# Example of loop implementation  
rule = load("RULES.md")  
for review in reviews:  
    if not maker.run(goal, rule):  
        checker.run(goal, review, tests)  
        gate.append(review.reason)  

๐Ÿ“ŒKey Takeaway:

Automate the reproduce-fix-verify grind, but keep the merge yours. A good loop proposes the fix and pings you. It never ships on its own.

๐Ÿ“Œ6. The Quality Gate

A loop without a gate produces slop faster. The gate is the check your work must pass before it ships and is the only thing keeping the loop well-functioning.

๐Ÿ“ŒBuild the Gate:

Compiler
Type system
Integration tests
Mutation tests
Property-based tests
Linters, analyzers, and CI

๐Ÿ“Œ7. Self-Learning Loop

๐Ÿ“ŒKey Principle:

A loop only improves if it can carry its lessons forward and be held to them.

๐Ÿ“ŒRules for RULES.md:

Add no rule whenever the agent repeats a mistake.
Donโ€™t let it auto-repair the same issue twice.
Donโ€™t let the loop auto-fill with noise.

๐Ÿ“ŒKey Takeaway:

Your job is not only designing loops that prompt your agents. Itโ€™s designing loops that learn from experience.

๐Ÿ“Œ๐Ÿ“– Real-Time Story

Imagine Alice, a software engineer, debugging a recurring issue in her teamโ€™s CI pipeline. She sets up a closed loop:

Trigger: The loop starts whenever a test fails.
Isolate: It narrows down the failure to the specific module.
Inform: It pulls logs and error messages for context.
Connect: It links the failure to the relevant GitHub issue.
Build: It proposes a fix and reruns the tests.
Remember: It stores the fix in RULES.md for future reference.

Over time, Aliceโ€™s loop evolves into a self-learning loop, reducing repetitive failures and freeing her team to focus on new features.

FAILURE
โ†ท
ISOLATE
โ†ท
INFORM
โ†ท
CONNECT
โ†ท
BUILD
โ†ท
REMEMBER

Aliceโ€™s loop becomes the backbone of her teamโ€™s productivity, shipping reliable code while they sleep.