An agent loop turns a single model response into a multi-step process. A typical cycle sends the current goal and context to a model, executes an approved tool call if requested, adds the result to the state, and calls the model again. The loop ends when a completion condition or safety limit is reached.
A simple support agent shows the cycle: read the customer message, call an order lookup tool, read the status, then either answer or look up shipping details. Every pass adds text to the context window, so long loops get slower and more expensive. Patterns such as ReAct prompting structure each pass of the loop. Log the step count and the reason each run stopped (finished, hit the limit or errored), because those two fields reveal most loop bugs.
Loops need safeguards against repeated failed actions, oversized context, excessive cost and tools that never return. Use maximum iterations, timeouts and explicit exit conditions. Related: AI Agent, Agent State, AI Agent Evaluation.