During an outage, a retailer's inventory API answers every request with HTTP 503. The shopping assistant reaches it through the three layers below; assume the model follows its instruction exactly. About 200 customer questions a minute need a stock check. How many requests per question reach the inventory API, and what is the fix?
# Layer 1: HTTP client shared by all tools (urllib3 retry policy;
# raises an error once its retries are used up)
session.mount("https://", HTTPAdapter(
max_retries=Retry(total=2, status_forcelist=[503])))
# Layer 2: tool wrapper (tenacity; retries on any exception)
@retry(stop=stop_after_attempt(3))
def check_stock(sku):
return session.get(f"{INVENTORY}/stock/{sku}", timeout=3).json()
# Layer 3: agent system prompt
# "If a tool returns an error, call it again, up to 2 more times."Show the answer and explanation
Correct answer: C, 27 requests per question (3 × 3 × 3), or 5,400 a minute; retry in one layer only, let the other layers fail fast, and cap retries with a budget such as 10% of requests.
Explanation Agent Reliability
Retries at nested layers multiply, because every attempt of an outer layer runs the full retry loop of the layers inside it.
- HTTP client:
Retry(total=2)means 1 attempt + 2 retries = 3 requests before it raises (urllib3's defaultraise_on_status=True; requests reports aRetryError). - Tool wrapper:
stop_after_attempt(3)calls the client 3 times (tenacity retries on any exception by default) → 3 × 3 = 9. - Agent: one call plus up to 2 re-calls = 3 tool calls → 3 × 9 = 27 requests per question.
At 200 questions a minute the failing API receives 200 × 27 = 5,400 requests a minute instead of 200: a 27× load increase on a service that is already down, which can stop it from recovering.
Fixes:
- Retry at one layer, usually the one closest to the call that knows whether the error is retryable, and make the other layers fail fast.
- Retry budget: allow retries only while they stay below a share of traffic (e.g. 10% of requests), so an outage cannot multiply load.
- Tell the model the error is temporary and was already retried, so it does not loop; add backoff with jitter and a circuit breaker.
Why the other counts are wrong: adding attempts (9) or retries (7) ignores the nesting, and per-layer backoff only spreads the requests out in time without reducing them. 81 counts the agent twice: its first call is already one of its three calls.
Interview tip: draw the call stack and multiply attempts per layer. The Google SRE book makes the same point: one top-level request can cause the product of the attempts at every layer, so retry at one level and use a per-client retry budget.