Loop Engineering
Running agents without being the keyboard — loop types, guards, building blocks, and failure modes on one page.
The ladder
- L1 Prompt engineering
- Shape one request — a single model call
- L2 Context engineering
- Shape everything one run sees — instructions, files, tools, memory
- L3 Loop engineering
- Shape the system around runs — when it fires, what it gets, how it’s checked, when it stops
Four loop types
- Heartbeat
- Fires continuously on an interval · monitoring, triage · stops only by kill/budget
- Cron
- Fires on a schedule · nightly reviews, audits · each run ends with its batch
- Hook
- Fires on an event (PR push, CI fail) · reactive work · once per event
- Goal
- Iterates until a verifiable condition · migrations, refactors · always cap it
Three stop guards
- Hard caps
max_iterations, wall-clock, token budget — catches runaways- Verifiable conditions
- Tests green, build passes, zero diff — machinery, not model judgement
- Independent verification
- Verifier ≠ implementer: test suite or reviewer subagent
Six building blocks
- Automations
- Scheduled/triggered runs that find work
- Worktrees
- Isolated git dirs — parallel agents never collide
- Skills
- Codified conventions in version-controlled files
- Connectors (MCP)
- Reach: PRs, tickets, Slack, DBs
- Subagents
- Fresh-context verification split
- External memory
- Board/checkpoint outside the window — read first, write last
Failure modes → guards
- Token runaway
- Hard caps + budget, alert on trip
- State amnesia
- Checkpoint file, resume-point line, facts not vibes
- Overconfident termination
- Verifiable stop conditions + verification split
- Context degradation
- Fresh subagent per work item
- Silent quality drift
- Periodic human audit of merged output
- Comprehension debt
- Read what merges; throughput ≤ review bandwidth
Cost levers
- Model routing
- Cheap watches, expensive acts, priciest only reviews · saves 60–80%
- Prompt caching
- Stable system prompt + skills re-sent each turn · saves 40–90% input
- Doing less
- Hooks over heartbeats; cheap pre-checks skip the agent entirely
Vocabulary
- Verification split
- Generation and review are separate agents
- Intent debt
- Re-explaining context every run instead of writing skills
- Orchestration tax
- Ceiling = human review bandwidth, not model capability
- Cognitive surrender
- No longer having opinions about loop output