core practice · coding problem

Cap agent tool loop

Agent calls tools in a loop. Max 5 steps, same tool 2× in a row triggers stop. Steps: search, search, calc, search, search, calc. When stop?

The mechanism

An agent is a loop: the model proposes an action, a tool executes it, the observation re-enters context, repeat until done. The engineering is in the guardrails — step limits, memory, and human approval — not the prompt.

Study Agent Loops

Expected evidence

Stop at step 3 (duplicate search) or step 5 by max steps — implement both guards.

Try this drill in the practice workspace →

Hints when you need them
  • Infinite loops burn tokens.
  • Log each tool call.

Watch for these mistakes

  • No step limit, so the loop runs away
  • Letting context grow unbounded across iterations
  • No human approval gate for irreversible actions

Check the sources

Browse all practice briefs