A migration assistant is built as an agent with a set of tools. Some runs finish after two tool calls and others after fifteen, and the team wants the loop condition expressed in application code rather than guessed from the assistant's output text. What correctly decides whether the agentic loop should run another turn?
- AThe application counts the tool calls made so far and ends the run once that count reaches a configured ceiling for the migration task
- BThe application inspects the stop reason on each response and continues only while the model has asked to use a tool, executing it and returning the result Correct
- CThe application matches the assistant text against a completion phrase agreed in the system prompt, and ends the run when that phrase appears
- DThe application ends the run when a response arrives whose output token usage is well below the configured limit, indicating nothing further was produced
Why A is wrong: Tempting because a ceiling is a sensible safety limit, but a cap protects against a runaway run rather than signalling that the model has finished its work.
Why B is correct: Correct because the stop reason is the structured signal describing why generation halted, so it distinguishes a pending tool call from a finished answer without parsing prose.
Why C is wrong: Tempting because instructing a closing phrase seems deterministic, but it depends on the model reproducing wording exactly, which makes termination a prompt behaviour rather than a protocol fact.
Why D is wrong: Tempting because a short reply often does mean completion, but a brief response can still carry a tool request, so usage size cannot decide termination.