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.

Stuck? AI Nudge Available

Get a conceptual hint to guide your logic without spoiling the final implementation.

03

Study the solution

The solution is waiting

Give it an honest attempt first — then compare your thinking with the full walkthrough.

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.