Claude Certified Architect – Foundations Practice Question 2: Agentic Loop Stop Reason
Claude Certified Architect, Foundations · Test 1 · question 2 of 10
You are writing the agentic loop for a Claude API application by hand, without an SDK abstraction. After each call to the Messages API, the loop inspects the response. Which implementation correctly drives the loop?
Show answer and explanation
Answer:
D is correct. When Claude wants to use a tool the response has stop_reason "tool_use" and contains one or more tool_use blocks. Your code executes them, appends the assistant message and then a user message containing tool_result blocks (each with the matching tool_use_id), and calls the API again. The loop ends when stop_reason is "end_turn", meaning Claude has produced its final answer.
A is wrong because parsing prose for keywords is fragile; the structured stop_reason and tool_use blocks are the signal. B is wrong because a fixed call count either truncates the work or wastes calls, and tools are requested through tool_use blocks, not mentioned in text. C is wrong because a tool_use block means the model is waiting for a result; stopping there leaves the task unfinished and the tool_use without a tool_result.
Reference: Handle tool calls - Claude Platform Docs