Skip to content
mentoor

The agent loop

For engineers

The reason-act-observe cycle, stopping conditions, step and token budgets, and context management across turns

See where you stand

110 questions across four stages: Understand, Apply, Solve and Judge.

Try 5 questions

Practice items, not counted towards your mastery. No account needed.

Check yourself · 1 of 5

In an agent loop built on a tool-calling API, who actually runs the tool the model asks for?

Choose one answer

Check yourself · 2 of 5

Why should an agent loop have a hard turn limit even when the model is told to stop when done?

Choose one answer

Check yourself · 3 of 5

Why can an agent's cost grow faster than its number of turns?

Choose one answer

Check yourself · 4 of 5

In an agent run, edit_file and run_tests alternate for six turns, undoing and redoing the same change. What is this pattern called?

Choose one answer

Check yourself · 5 of 5

In a long agent run, which part of the history is usually the safest to clear after several turns?

Choose one answer

Topics

  1. Reason, act, observe: the ReAct cycle4 min read · The interleaved reasoning and tool-call cycle, and how current models run it natively with tool use and extended thinking
  2. Stopping conditions that end runs cleanly4 min read · Done criteria, final-answer tools, turn limits, and stops on repeated errors or a user interrupt
  3. Step, token, time and cost budgets4 min read · Setting turn caps, token and spend limits, wall-clock timeouts, and what the agent does when a budget runs out
  4. Runaway and stuck loop mechanics4 min read · Repeating the same call, ping-ponging between two states and retrying an error forever, and the loop code that prevents each
  5. Managing context across loop turns4 min read · Tool-result clearing, compaction and summarised history so long loops stay inside the context window without losing facts

Start here

110 questions · last verified 2026-12