Stage 4 · Assumes you can code · Harnesses & Orchestration

Control Loops & State Machines

How harnesses structure repeated model calls into coherent programs.

At the heart of most agentic harnesses is a control loop: call the model, inspect its output, decide what to do (call a tool, ask the user, stop), then loop again with updated context.

More complex harnesses model this explicitly as a state machine: defined states (e.g. "planning", "executing", "waiting for approval") with rules for transitioning between them. This makes behavior more predictable and easier to debug than an unstructured loop — at any point you can point to exactly which state the agent is in and which transitions are even possible from there.

A Loop Needs a Stop Condition
call → actstep 1continue
No cap. "Perfect" never arrives — this is the runaway-essay case.

Run steps with a fuzzy goal versus a hard cap. "Perfect" never stops the loop on its own.

All lessons in Stage 4: Builders (optional)