Advanced questions: reliability and failure handling
What it is
Questions about what happens when things go wrong, which is most of production.
Why it matters
Say each answer aloud before reading it.
- The first sentence should be a complete answer on its own.
- The rest adds one example or one trade-off.
- If an answer here surprises you, the module named in the question's topic is where to go back.
In the real world: The fastest route to a senior signal: asked about a timeout on a payment, say 'idempotency key' and explain how it is derived, before being prompted.
Q: How would you prevent infinite agent loops?
Three layers. Limits in code: steps, tokens or cost, and time. Detection: identical or alternating calls, or several steps with nothing new. Response: one corrective nudge, then stop with a summary and hand over. And the root cause: tool results and errors that say what to try next, because most loops are an agent re-asking a question it never got a useful answer to.
Q: Why do agents fail on long tasks?
Errors compound. Task success is roughly per-step success raised to the number of steps: at 95 percent per step, twenty steps succeed about a third of the time. The remedies are more reliable steps, fewer steps, and checks that catch an error before the next step builds on it.
Q: A refund call times out. What does your system do?
It retries with the same idempotency key, derived from the run and the action. If the first call succeeded, the payment service returns the original result; if not, it performs it once. The step is recorded in the action ledger and the state is checkpointed. The customer is told only what the ledger shows.
Q: The process crashes half-way through a multi-step action. Then what?
The run resumes from its last checkpoint. Completed steps are in the ledger and skipped; the in-progress step is repeated safely because it is idempotent. If a later step fails permanently, earlier steps that must not stand alone are compensated, and the customer gets an accurate account.
Q: How do you reduce hallucination in an agent?
Supply facts through tools and make empty results explicit; require looking up before stating; verify the final answer in code against tool results and the action log, including amounts, ids and claimed actions; and confirm actions in the system of record.
Q: How do you handle stale data?
Timestamp and expire memories and caches, and re-read any fact an action depends on inside the tool at the moment of acting, with a version check so the write fails if the record changed.
Q: What is a cascading failure in an agent system?
One error spreading: a wrong fact built on for ten steps, one agent's mistake repeated by others, or a slow dependency exhausting workers through timeouts and retries. Contain it with validation at boundaries, timeouts, circuit breakers, bulkheads and bounded retries.
Q: How do you make a non-deterministic system dependable?
Put determinism around it: fixed workflow stages, typed outputs, validation, limits and policy in code, idempotent tools and saved state. Then measure reliability as a rate over repeated runs and require safety behaviours to pass every run.
Proposing to fix a reliability problem by improving the prompt.
Practise it: Design a Tool-Calling Agent Over 500 APIs