Step one — Write the goal and the scorekeeper
Make the goal small, specific, and finishable — not a long wishlist. Then define the scorekeeper: the exact check (pass/fail criteria) that proves the goal is met. Write the goal and scorekeeper before any code or automation. The goal guides the design; the scorekeeper validates it.- Goal: one focused outcome the loop should produce.
- Scorekeeper: an objective test that returns a clear pass or fail.
Write the scorekeeper first. Without a robust, hard-to-game scorekeeper, a loop cannot safely run autonomously.
Step two — Start the loop and get one small win saved
Follow the “green-first” rule: implement just enough for the loop to produce one real result that passes the scorekeeper and is persisted (saved). That initial green proves the loop runs end-to-end and gives a stable baseline to iterate from.- Implement the minimal path from input → process → score → persist.
- Persisting the first successful result prevents regression and makes refactoring safe.
- Treat this as a thin vertical slice, not a full product.

Step three — Add parts only as they are needed
Extend the loop incrementally and only to solve observed problems. Common, justified additions include:- A skill/guard to enforce the correct step when the loop repeatedly makes the same mistake.
- Durable memory when runs grow long or need to pause/resume across sessions.
- A focused sub-agent when a particular job requires concentrated effort (large search, deep review).

Cost, human handoffs, and when not to build a loop
Be mindful of token and compute costs. Each run consumes resources and may spawn sub-agents; frequent or fast runs increase expense. Build a loop only when:- Work repeats often enough to amortize costs, and
- A scorekeeper can reliably validate outcomes.

Common mistakes and traps — how to detect and fix them



Be cautious with autonomy. Never give the loop unchecked access to destructive actions. Gate risky operations behind explicit human approval and limit the loop’s editing scope.
A habit that ties it all together
Keep every change small and saved. Small, incremental changes are easy to test, reason about, and revert. This safety net allows you to run a bolder loop without undue risk.Quick recap — Design order and checklist
Checklist:
- Is the goal narrow and finishable?
- Is the scorekeeper objective and difficult to game?
- Does the loop produce one saved green result?
- Are new parts added only to fix observed failures?
- Have you evaluated token cost and human handoff points?
- Do you limit scope and gate risky actions?

Further reading
- Prompt engineering best practices
- Designing safe agent systems
- Practical automation: when to script vs. when to build a loop