New Tool Radar

AI Agents & Automation

How to Stop an Agent Tool Loop When the Goal Is Reached

Give an agent a clear stop condition so its tool loop ends as soon as the goal is met, not after extra calls.

Schematic with three steps: Write the stop condition into the instructions; Run the task and count the calls; Tighten the condition if it overshoots.

A ReAct loop ends when the model produces an answer with no tool calls, but the model only stops if it knows what counts as done. Without a written stop condition it keeps searching for a better answer long after it has a good one. Write the goal and the stop condition into the instructions in plain words: what the deliverable is, and the sentence that means stop, such as when you have three prices, answer with the table. Then check the run log to confirm the loop stopped at the goal instead of drifting on.

What you need

  • A task with a deliverable you can recognise when you see it
  • A stop condition written in one sentence
  • Access to the run log to count tool calls

Step 1: Write the stop condition into the instructions

Add one sentence to the agent instructions stating exactly when to stop, naming the deliverable and its contents. A vague goal such as research the topic has no stop; three supplier prices in a table does.

Step 2: Run the task and count the calls after the goal

Run the task and count how many tool calls happened after the goal was already met. The right number is zero; every call after the goal is wasted cost.

Step 3: Tighten the condition if it overshoots

If the agent kept calling tools after the goal, make the stop condition more specific, naming the number of items or the exact fields. Re-run and confirm the extra calls are gone.

Worked example: synthetic stop check

The table below is a synthetic example. It shows the expected result of the stop condition; no agent was run.

Check Expected Result
Goal met at call 3 Yes Pass
Tool calls after the goal 0 Pass
Deliverable has 3 prices Yes Pass
Run ends with an answer Yes Pass

Expected result (UNTESTED). the loop stops at the third call with three prices in a table and makes no further tool calls. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • The model decides when to stop, so a written condition guides it but does not force it.
  • A stop condition that is too strict ends the run before the goal is really met.
  • Check the log, not just the answer: an answer can look complete while the loop wasted calls.
  • Different tasks need different stop conditions; one generic sentence does not fit all.

Sources

See all