Loop engineering
Loop engineering sets an agent's done conditions, turn limits, error policy and the state it keeps between turns.
Loop engineering is the design of the loop an agent runs in. An agent repeats a cycle: it looks at the state, chooses an action, calls a tool, reads the result and decides what to do next. Loop engineering decides how that cycle starts, when it must stop, what happens when a step fails and what state is carried from one turn to the next.
A loop without these decisions tends to do one of two things. It stops too early, leaving the task half done, or it keeps going, spending money and making changes nobody asked for.
In practice
I write four rules before the first run. The done condition says what a finished task looks like, in terms that a checker can test. The turn limit sets the maximum number of cycles and the cost ceiling for one task. The error policy says which failures are retried, which are escalated and which stop the loop at once. The state policy says what is kept between turns and what is discarded.
The rules are tested with the evaluation set. A loop that passes the happy path but never reaches its done condition on the hard cases has not been engineered yet.
Example
[Composite] A research agent for a procurement team kept searching after it had found the answer, because its done condition was "enough sources" rather than "the three required fields are filled". Changing the condition to a field check, with a turn limit of eight, cut the number of calls and removed the repeated searches.
Common mistakes
- Writing the done condition as a feeling. Use a check the system can run.
- Leaving the turn limit out. Every loop needs a ceiling on turns and cost.
- Keeping all state between turns. Carry only what the next step needs.
Related terms
Cite this definition
Loop engineering. Mayur Patil, mayurpatil.ai, updated 2026-11-01. https://mayurpatil.ai/glossary/loop-engineering/