BACK TO INTERVIEW BANK
agent-architecturesenior

How do you handle failures in an agent system?

Answer

Separate the failure types, because they need different handling.

Tool failures are the easy case. The API returned 500, the file did not exist, the command exited non zero. Feed the error back to the model as a tool result. Models are reasonably good at adapting to a clear error message, and often the recovery is correct on the next attempt. Return the actual error text, not a sanitised "operation failed", because the specifics are what make recovery possible.

Reasoning failures are harder. The model misunderstood the task, or is confidently pursuing a wrong approach. No error is raised, so nothing signals the failure. Detection needs an external check: does the test suite pass, does the output validate against a schema, does the result satisfy the stated condition.

Silent failures are worst. The agent reports success and something is subtly wrong. This is why verification must be independent of the agent's own claim. Never treat "the agent said it fixed it" as evidence.

Mechanisms worth having:

  • A step limit, so a loop terminates
  • A retry cap per tool, so a failing call does not consume the whole budget
  • Checkpointing, so you can resume rather than restart
  • Structured logs of every tool call and result, since you cannot debug what you did not record
  • A clean abort path that leaves the system in a known state

Design assuming a human will need to recover. Small reversible steps and version control are more valuable than sophisticated error handling.

Common wrong answer

Retrying the same call repeatedly on failure. Without changing anything, the same call returns the same error, and you have burned budget. Retries need either changed inputs or backoff for transient issues, plus a cap.

Also wrong is catching errors and hiding them from the model. The model cannot adapt to a failure it was not told about.

Likely follow-ups

  • How do you detect a silent failure?
  • What do you log?