Zenaique
Part ofGenAI Engineer·Week 4: Agents & ProductionView roadmap →

Describe the typical agent execution loop.

Short answer·Medium·4.4 · 102·~3 min·Asked atForethoughtRunway·Relevant atAdobeAi21AmazonAnduril
Attempt it

Describe the typical agent execution loop step by step.

Free · 2 AI evals / day
TL;DR

An agent loop is observe, reason, act via a tool, observe the result, then repeat until the model signals done or a step or cost budget runs out.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Picture a person solving a puzzle they have never seen before. They look at what is in front of them, think about the next move, pick up a tool (a calculator, a notebook, a search bar), try something, and then look at what happened. If they are not done, they think again and pick another move. They keep going like that, step by step, until the puzzle is solved or they decide to stop because they have run out of time, energy, or attempts. An agent works the same way. The model is the thinker, the tools are the calculator and search bar, and the loop is the patience to keep going round by round instead of solving it all in one shot.

Key concepts

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

An agent loop is the control structure that converts a single LLM call into a multi-step decision process. The model is no longer asked to produce the answer in one shot. Instead it sits inside a runtime that calls it repeatedly, feeds it the running state of the task, lets it act on the world through tools, and stops only when the goal is reached or a budget is hit.

The loop is what makes a system an agent. A chain that happens to call a tool is not an agent. A function that does retrieval and then generates is not an agent. The defining property is iteration with intermediate observations shaping the next step.

The five steps, in detail

Step one is observe. The agent reads the current state, which is the concatenation of the original user goal and every action and observation since the run began. On the first turn the state is just the goal. On the twentieth turn it is the goal plus nineteen action-observation pairs.

Step two is reason. The LLM consumes the state and emits one of two things, either a structured tool call or a final answer. ReAct-style agents also emit a free-text reasoning trace before the action, which improves accuracy on hard tasks at the cost of extra tokens.

Step three is act. The runtime parses the tool call, validates the arguments against the tool's schema, and executes it. This step is where the agent actually changes the world, by running a database query, calling an API, or writing a file.

Step four is capture the observation. Whatever the tool returned, including errors, is appended to the state. Errors must not crash the loop. They become observations the model can reason about on the next turn.

Step five is decide whether to stop. If the model emitted a final answer, exit. If the step or cost budget is exhausted, exit with a timeout result. Otherwise, loop.

State management as the dominant cost driver
Termination is harder than it looks
Observability and the production checklist
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

Real products, models, and research that use this idea.

  • Claude's computer use mode runs an agent loop where the tool is the desktop itself. Each turn observes a screenshot, reasons, and emits a click or keystroke.
  • LangGraph's ReAct prebuilt agent wraps OpenAI or Anthropic function calling in a state graph where each node is one loop iteration with full trace logging.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QHow would you detect and break a loop where the agent keeps making the same failing tool call?
A

Hash the action signature on each turn and compare against the last few. After N identical actions in a row, inject a system message that lists the recent failures and forces a different strategy or terminates.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Describing the loop as a one shot plan then execute. Real agents reason between every action so the next step can depend on what the last observation actually returned.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Name the five steps in order and explain what each one does.

  • Explain how state is accumulated across iterations.

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
What is the Model Context Protocol (MCP) and what problem does it solve?
MCQ·Easy