Skip to solution
hardAI Engineering

How should an agent handle tool errors, timeouts and retries?

1.2k views
01

Understand the problem

Resilience inside the loop: which failures the model should see and which the runtime should absorb.

error-handlingretriesagentsresilience
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Split responsibilities: the runtime absorbs transient infrastructure failures (retry with exponential backoff on timeouts/429s, idempotency keys for writes), while semantic errors are returned to the model as tool results with actionable messages so it can correct its arguments or change approach. Guard the loop itself

Solution ready — 2 min read

Classified // press E to declassify

04

Read the code

Execute-with-policy wrapper
async function runTool(call: ToolCall): Promise<ToolResult> {
  try {
    const out = await retryTransient(                 // backoff for 429/5xx/timeout
      () => tools[call.name](call.input),
      { attempts: 3, idempotencyKey: call.id },
    );
    return ok(call.id, summarize(out));               // compact, context-friendly
  } catch (e) {
    if (isTransient(e)) return err(call.id, "Service unavailable, try later or use another approach.");
    return err(call.id, toActionable(e));             // "date must be YYYY-MM-DD" — no stack traces
  }
}
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 59 of 80 decoded in the AI Engineering track. One more won't hurt.

Back to track