Five parts make the loop. The model chooses, tools act, state remembers, the goal defines done, and the stopping rule ends the run.
Component | Owns | Example in a lint-triage loop |
|---|---|---|
Model | Choosing the next action from the state. | Picks reading the lint log before running a check. |
Tools | Real effects with typed inputs and outputs. | A file reader and a check runner. |
Memory and state | Goal, history, and tool results. | The transcript the loop re-reads each turn. |
Goal | What counts as done. | Every finding is explained or the budget is spent. |
Stopping rule | When the loop must end. | Answer reached, budget spent, or repeat detected. |
State holds the goal, the actions so far, and every tool result. Each choice reads the whole state, so state size grows with steps.
Token counts below are stated example parameters. Real counts are approximate and tokenizer-dependent.
stated example: goal 200 tokens plus 150 tokens per past step
after 4 steps: 200 + 4 x 150 = 200 + 600 = 800 tokens
after 10 steps: 200 + 10 x 150 = 200 + 1500 = 1700 tokens
growth per step is constant here because each result has the same sizeA loop needs at least one rule that can fire on every run. Goal reached alone is not enough, since some runs never reach it.
Goal reached: the answer satisfies the goal test.
Budget spent: the step count hits its maximum.
Repeat detected: the same action recurs with no new result.
Tool failure: a call reports an error the loop cannot handle.
The stopping rule. A repeat detector or a tighter step budget would end the loop.
In state. The loop re-reads it each turn alongside the history and tool results.