Question presented to candidate: "An agent in production got stuck in a loop overnight: it retried the same failing tool call hundreds of times, sent a burst of emails and ran up a large model bill. Design the guardrails that would have stopped it: rate limits, budget caps and human escalation. Where does each check live, and what should happen when one trips?"
What a strong answer should cover:
- Hard limits on every run: steps or turns, tokens and dollars, wall-clock time, and per-tool call counts, all enforced in the loop runtime rather than requested in the prompt
- Budget enforcement that cannot overshoot: reserve the worst-case cost of the next call (known input plus
max_tokensoutput) before making it, instead of checking after the money is spent - Rate limits per tool and per side effect (emails, refunds, writes) using token buckets, plus per-user and per-tenant quotas, separate from the provider rate limits you retry against
- Circuit breakers for unproductive behaviour: identical repeated calls, error streaks and no-progress detection
- What happens on a trip: stop cleanly, keep the trace and partial work, and escalate to a human with a summary and options, rather than crash or silently continue; plus tiered approval for risky actions
- Observability: per-run spend and step metrics, alerts on limit trips, and limits calibrated from real run distributions
Clarifying questions expected:
- What does a normal run look like (steps, tokens, duration), so limits can be set from data?
- Which tools have real-world side effects, and what volume of them is ever legitimate per run?
- Is there a human available to take escalations, and how fast?
Code / implementation expected: Yes โ a loop wrapper that enforces step and budget caps, or a per-tool rate limiter with a breaker.