Agent Architecture
Advanced 13 min read Agent Architecture

Failure Handling

Fail by design

Agents fail in recognizable ways: tool errors, exhausted caps, divergence, hallucinated success. Failure handling makes each failure explicit — detect, classify, retry-or-degrade, and report honestly with usable partial state.

failureclassificationdegradecircuit breakerfallbackpartial state
Prerequisites: Agent Reliability
Before we start

What you will learn

  • Classify agent failures
  • Apply retry, degrade, and fallback responses
  • Report honest partial state on abort
Introduction

What is this?

Failure handling predefines the response to every likely failure class: transient tool errors (retry with backoff), cap exhaustion (degrade scope or report partial), divergence (detect and re-plan or stop), and hallucinated success (verify evidence, fail honestly). Each failure is logged, classified, and converted to a user-facing, actionable outcome.

Motivation

Why do you need it?

  • Unhandled failure classes are the top source of agent incidents.
  • Classification selects the response: retry vs degrade vs abort.
  • Honest partial states beat invented completions.
  • Live failure telemetry feeds evals and design fixes.
Think about it

Mental model

Imagine

Airline delay procedures

Think of

Failure handling

A delay has a playbook: rebook (retry), downgrade class (degrade), or inform with options (honest abort). No one pretends the flight is on time — that'd compound the failure. You get status, alternatives, and a path, because the procedures were written for the failure that is happening.

Mechanics

How it works

  • Detect failure classes: transient, cap, divergence, fake-success.
  • Classify on exit: code + context into telemetry.
  • Respond: retry (transients), degrade (scope cut), fallback model/route, abort.
  • Verify before reporting done; evidence gate at terminal.
  • Compose the user-facing message: what failed, what's done, what to do.

Failure taxonomy → response.

Fail
Transient
Cap
Diverged
Fake-done
Report
Real world

In production

  • Ops runbooks degrade gracefully when a probe times out.
  • Consumer assistants report partial search results with retry hints.
  • Eval harnesses verify aborts match expected failure classes.
Guidelines

Best practices

  • Write a response for every failure class before shipping.
  • Never report done without evidence (treat terminal as a gate).
  • Degrade scope rather than silently bluff weaker output.
  • Feed all failure telemetry into the eval suite.
Watch out

Common mistakes

  • Status quo: crash → empty response.
  • Bluffing: returning optimistic 'done' to avoid the awkward report.
  • Retrying divergence four times before realizing it's not transient.
Root cause analysis

Common issues

Error
Failures multiply (fan-out of half-work)
Root cause

Degrade triggered writes anyway

Fix

Guarantee only side-effect-free degrades; gate writes separately.

Error
User can't recover
Root cause

Message lacks next steps

Fix

Always end failures with what the user can do next.

When things break

Debugging tips

  • Same failure recurs → classify beyond transient; add a specific rule.
  • Degrades look like sloppy answers → label the degrade in the message.
  • Aborts underreport → capture partial state and reasons in telemetry.
Interviews

Interview checkpoint

Practice

Hands-on lab

Checkpoint and Resume
25 min · intermediate
In progress
Objectives
  • Record completed task ids as a checkpoint
  • Simulate a crash mid-run
  • Resume by skipping already-completed tasks

Checkpoint and Resume

25 min · intermediate

0/3 steps
0%
sandbox · Linux sandbox
$
Try these commands
Test yourself

Quick quiz

0/2
1

Cap exhaustion should produce…

2

Divergence usually fixes itself via endless retries.

Go deeper

Official documentation