AI glossary
Agent loop
The agent loop is the cycle at the heart of an agent: send the conversation to the model, run any tool it asks for, add the result, and repeat.
In code it is a while loop. Each turn the model either asks for tools, which you run and append, or gives a final answer, which ends the loop.
Every loop needs a way out besides success: a maximum number of steps, a budget, a timeout and a check for the same call repeated. Without them a confused model can loop for ever.
Most of an agent's behaviour lives in this small loop: what it keeps in context, what it does when a tool fails, and when it asks a person.
Learn it hands-on
These free lessons teach it with commands to run in a lab and checked tasks. Read them whole with no account.