AI agent glossary
Agent loop
The repeating cycle at the heart of every AI agent: the model picks an action, a tool runs it, and the result is fed back until the task is done.
The agent loop is the simple mechanism that turns a language model into an agent. You send the model a goal plus a list of tools it may use. The model replies either with a final answer or with a request to call a tool. Your code runs that tool, appends the result to the conversation, and asks the model again.
This cycle of think, act, observe repeats until the model says it is finished, a step limit is reached, or something goes wrong. Each pass gives the model fresh evidence, which is why agents can recover from mistakes that would sink a single prompt.
Most of the engineering in a real agent lives around this loop rather than inside it: choosing which tools to offer, keeping the context from overflowing, deciding when to stop, and knowing when to ask a human for approval.
Asked to fix a failing test, a coding agent runs the test suite, reads the error, opens the relevant file, edits it, and runs the tests again. Each of those steps is one turn of the loop.
Learn more in the course
Related terms
Go from definitions to doing
Learn to use and build AI agents in 65 practical lessons.