Claude Certified Architect – Foundations Practice Question 43: Agent Loop Turn Budget Caps
Claude Certified Architect, Foundations · Test 5 · question 3 of 10
A team deploys an autonomous coding agent built on the Claude Agent SDK. Occasionally an open-ended prompt such as "improve this codebase" makes the agent run for a very long time and generate a large bill. The team wants a hard stop on both the number of tool-use round trips and the dollar cost, and wants the application to be able to detect which limit was hit. What should they do?
Show answer and explanation
Answer:
The Agent SDK exposes max_turns / maxTurns (maximum tool-use round trips) and max_budget_usd / maxBudgetUsd (maximum cost). Both default to no limit. When either is reached, the SDK returns a ResultMessage whose subtype is error_max_turns or error_max_budget_usd, so the application can log it, alert, or resume the session with a higher limit. The budget cap also counts subagent spend.
B is wrong because a prompt instruction is advisory; the model cannot reliably count its own spend, and nothing enforces it. C is wrong because a wall-clock kill is a blunt tool that does not bound cost directly, gives no structured signal about why the run ended, and can interrupt work mid-edit. D is wrong because max_tokens limits the output of a single response, not the number of loop iterations, and a low value would truncate legitimate responses and tool calls.
Reference: How the agent loop works