QuestionQ58

Agentic Architecture & Orchestration

A customer reaches out about a warranty claim on a power drill. Resolving the request requires multiple sequential tool calls: get_customer to look up their account, lookup_order to find the purchase details, and then either process_refund or escalate_to_human depending on warranty eligibility.

You are implementing the agentic loop that orchestrates these steps using the Claude API. What is the primary mechanism your application uses to determine whether to continue the loop or stop?

Explanation

In the Claude API's tool-use (agentic loop) pattern, each API response includes a stop_reason field indicating why the model stopped generating. When Claude wants to invoke a tool, the response has stop_reason: "tool_use". The orchestrating application should check this field after every API call: as long as stop_reason is "tool_use", it executes the requested tool(s), sends the tool results back as a new user message, and calls the API again. Once stop_reason changes to "end_turn" (or another terminal value such as "max_tokens" or "stop_sequence"), Claude has finished its turn and the loop exits. Checking for the presence of a text block is unreliable because Claude can emit text alongside a tool_use block in the same response (e.g., explaining its next action) without that meaning it's done. Setting tool_choice to "none" is a way to prevent tool calls on a specific request, not a dynamic stopping signal, and tracking a maximum call count is merely a safety cap, not the primary control mechanism.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!