An agent is an LLM with tools and a goal, run in a loop: it picks an action, sees the result, and decides the next step instead of answering in one shot.

Agents & the Agentic LoopDiagram with these labels, in reading order: Set Goal; Model Reasons; About State; Emit Tool Call; Execute Tool; and Return; Observation; Update Context; with Observation; Check Completion; or Stop Condition.Set GoalModel ReasonsAbout StateEmit Tool CallExecute Tooland ReturnObservationUpdate Contextwith ObservationCheck Completionor Stop Condition
Agentic Loop Process Overview

One pass through the loop

  1. Define the goal and give the model the current task state.
  2. The model reasons about that state and emits a tool call.
  3. Your runtime executes the tool and captures the observation.
  4. The observation is added to the context.
  5. The model decides whether the task is complete. If not, the loop repeats.

The loop ends when the model reports it is done or when a stop condition fires, such as a maximum iteration count or an exhausted budget.

Take debugging code: the model reads the error message, queries the relevant documentation, then uses what it found to refine the next action. Each iteration builds on the last.

The adaptivity is the point. Without observations fed back into the context, the model has nothing to base its next action on, and the answer is generic and less suited to the task. The loop lets it try one path, see the result, and switch to another.

Model judgment as the transition function

A REPL or an event loop driving a state machine is the closest software analogue. The difference is that the transition function here is the model's judgment, so identical input can lead to different paths. The loop is therefore harder to predict and test.

Agent loop versus a single prompt or a scripted workflow

Task shapeApproachWhy
Later steps depend on earlier resultsAgent loopA single prompt cannot know follow-up questions before it sees the first results.
Open-ended: research, debugging, multi-system commandsAgent loopThe model can explore paths and adjust.
Known, fixed sequence of stepsScripted workflowCheaper and more reliable, with no nondeterminism.

Compounding errors and unbounded spend

Each step's output feeds the next input, so an early mistake shifts every later step. Without limits the model can also consume an unbounded number of tokens. Cap iterations and set guardrails.

Compounding errors Small errors accumulate across steps and can drift far from the intended outcome.

Runaway calls on a simple request

Example scenario: one request triggers about 12 LLM calls and 8 tool calls, takes about 25 seconds and costs about $30. All figures are illustrative. The usual cause is a missing execution budget: nothing tells the agent when to stop.

Agents & the Agentic LoopDiagram with these labels, in reading order: Action Selection Accuracy; Feedback Interpretation; Goal Clarity; Tool Utilization; Adjust Action Strategy.Action Selection AccuracyFeedback InterpretationGoal ClarityTool UtilizationAdjust Action Strategy
Debugging the Agentic Loop
  • Measure LLM and tool calls per request.
  • Log execution time and cost for each request.
  • Look for repeated tool calls whose results could be cached.

Set execution budgets on calls and tokens, and route simple requests to smaller models. Monitor call counts, tokens, latency, cost and success rate.

Back to the knowledge baseRequest an assessment