Agent loop
Last verified
The agent loop is the control flow: send context, receive an action, execute it, append the result, repeat.
It needs external bounds, enforced in your code rather than the prompt:
- a hard step cap
- a cumulative token budget checked between steps
- a wall-clock timeout
- a repeated-state check, so an agent retrying the same failing action terminates
A budget stated in a system prompt is a suggestion the model will deprioritise when it is trying to finish. How to give an AI agent a spending limit.