Agents that run on a heartbeat
Loop Engineering: Build Agents That Run Themselves
Stop prompting. Start looping.
A hands-on crash course in loop engineering — building agents that run on a heartbeat, checked by a second pair of eyes, and gated by a human who stays the engineer.
MIT · 6 parts · 20 starter kits · 11 projects
Anatomy of a loop
What one loop looks like
A loop is not a prompt you re-send. It's a cycle that schedules itself, does the work in isolation, gets graded by a second pair of eyes, and stops at a human. Then it beats again.
- 01 Schedule
The heartbeat fires — a timer, a condition, or an event.
- 02 Load state
Read STATE.md and the run log — what survived the last beat.
- 03 Triage
Pick the next unit of work, or stop if there's none.
- 04 Worktree
Isolate the run in its own checkout so nothing collides.
- 05 Implement
The maker agent does the work inside the worktree.
- 06 Verify
A separate checker grades it — never the maker itself.
- 07 Human gate
A person approves, escalates, or rejects the change.
- 08 Commit
Apply over MCP, append one line to the log — then beat again.
The six parts
Drop any one and the loop earns a familiar failure name — no heartbeat and it's a script you run by hand; no checker and it grades itself; no human gate and it ships with no owner.
- Heartbeatpulse
- When does a beat start?
- Bodyhands
- What may it do and touch?
- Spinememory
- What survives between beats?
- Stopping conditionfinish line
- How does it provably end?
- Checkersecond pair of eyes
- Who grades the work?
- Human gatesignature
- Where does a person decide?
Building blocks
The primitives you compose
Six moving parts. Learn each on its own, then wire them into a loop that runs without you.
Scheduling
Give a loop a heartbeat: timers, conditions, and unattended runs.
Worktrees
Isolate each run in its own checkout so parallel loops never collide.
Skills
Package repeatable know-how the agent can load on demand.
Connectors
Reach real systems over MCP — the hands of the loop.
Sub-agents
A separate checker grades the work — never the maker itself.
State
A spine that survives between beats: state files and run logs.
Architecture
How a loop is built up
The same five layers under every loop. A human designs the top; work descends to real tools at the bottom; results climb back up to the gate.
- L0The engineer
Human
Design the loop, hold the gate, review the diffs.
- L1Heartbeat
Control plane
Scheduling, pattern selection, and budget caps.
- L2Spine
Durable memory
STATE.md, LOOP.md, and the run log — carried between beats.
- L3Body
Execution
Worktrees and the maker / checker agents doing the work.
- L4Hands
Tooling
CLIs and MCP connectors — the hands that touch real systems.
Three rungs of autonomy
Every loop starts on the bottom rung and earns its way up. You decide how far.
- L1Report-only
The loop looks and tells you. It writes findings; a human makes every change.
Where triage-loop runs.
- L2Assisted
The loop proposes and drafts — one small change at a time — and waits at the gate.
Small auto-wins after week one.
- L3Unattended
The loop runs to completion on its own, stopping only when done or stuck.
Where build-loop runs — still human-gated on deploy.
Curriculum
Six parts, start to finish
Part 1
The Shift
Part 2
Heartbeat
Part 3
The Body
Part 4
The Spine
Part 5
Complete Loop
Part 6
Human Control
Patterns
Production patterns, ready to fork
Six loops that already earn their keep. Each ships as a write-up plus a starter kit you can fork today.
| Pattern | Cadence | Risk | What it does | Links |
|---|---|---|---|---|
| PR Babysitter | On PR events | medium | Shepherds a PR through review, CI, and rebase. The human stays in the merge seat. | |
| Daily Triage | Daily | low | A morning scan of CI, issues, and commits. Report-only in week one, small auto-wins after. | |
| CI Sweeper | On CI failure | medium | Reacts to a failing check with the smallest fix that passes it. Escalates after three tries. | |
| Dependency Sweeper | Weekly | medium | Opens one PR per upgrade, reads the changelog, and flags anything that needs a human look. | |
| Issue Triage | On new issue | low | Labels, dedupes, and routes a new issue before anyone on the team has seen it. | |
| Changelog Drafter | On release | low | Reads the merged commits since last tag and drafts release notes for a human to edit. |
Get started
Clone it and go
$ git clone https://github.com/ayeshakhalid192007-dev/LoopEngineering-CrashCourse.git- 1
Clone & skim the map
Start here — the course overview and how to navigate it.
- 2
Learn the foundations
The primitives and mental models every loop is built from.
- 3
Build your first loop
A guided watch loop — your first hands-on project.