Basis Lab

Models That Use Tools

When a Tool Fails

Last timeChecking What the Model Asked For

Tools time out, refuse and return nothing. The question is which failures are worth another attempt, and what the model should be told about the ones that are not.

Three kinds of failure

A tool call can fail in many ways and they collapse into three groups,

distinguished by one question: could the identical call, made again in a few

seconds, succeed?

A transient failure is one where the answer is yes. A timeout, a rate limit, a

momentary connection error, a service restarting. Nothing about the request was

wrong and the world was briefly unavailable.

A permanent failure is one where the answer is no. The record does not exist.

The customer is not eligible. The argument was rejected. Repeating this call

will produce exactly the same refusal for ever, and the only useful response is

to do something different.

The third group is the one that causes real damage. An ambiguous failure is a

call whose outcome is unknown: the request was sent, the connection dropped,

and nobody knows whether the payment went through.

FIG 1Failures and what each one calls for
could the same call succsafe to repeattell the modelretry in the program
timeout before anything 1101
rate limited1101
service restarting1101
record not found0110
argument rejected0110
not permitted0110
timeout after the reques1010
Coded 1 for yes and 0 for no. The first three rows the program handles silently, since the model has nothing useful to contribute to waiting. The middle three go back to the model, since only it can decide what to do instead. The last row is the hard one, and it is the only row that is unsafe to repeat: the request may have taken effect, so repeating it may act twice. It needs either a check of whether the action happened or an identifier that makes repeating it harmless.

Retrying in the program, not the model

Transient failures are handled by trying again, and where that retry lives

matters more than it sounds.

Inside the program, a retry repeats the byte for byte identical call. Three

attempts with increasing gaps, and if all three fail the failure is reported

once.

Delegated to the model, by passing the timeout back and letting it decide, the

retry is not a retry. The model produces a new request, which is usually

similar and rarely identical: a slightly different search phrase, a rounded

amount, an extra argument it decided might help. For reads this is merely

wasteful. For writes it is how a customer ends up refunded twice, once by the

call that timed out after taking effect and once by the model helpful second

attempt.

FIG 2How many attempts a transient failure costs on average
the chance one attempt fails transiently
attempts needed on average to get one success
A one in five transient failure rate means one and a quarter attempts per success, which is cheap, and the same arithmetic says a four in five failure rate means five attempts per success, at which point retrying is holding a broken system together and hiding the fact. The useful habit is to count retries as a measured quantity rather than a hidden one, because a retry rate climbing from two per cent to thirty is the clearest early signal a dependency is in trouble.

Two details make retries safe. Space the attempts out, with a growing gap and a

small random component, because a hundred clients all retrying in unison one

second after an outage are the reason the outage continues. And attach an

identifier to any call that changes something, so that the same identifier

arriving twice is recognised and performed once. That second property is what

turns the dangerous ambiguous failure into an ordinary transient one, and it is

worth having on every tool that writes.

The lesson stops here

3 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

The rest of this course

  1. 01Saying Something and Doing Something
  2. 02The Loopopening only
  3. 03Describing a Tool Wellopening only
  4. 04Checking What the Model Asked Foropening only
  5. 05When a Tool Failsyou are here
  6. 06Several Steps and a Budgetopening only
  7. 07Text From Outside Is Not an Instructionopening only
  8. 08Judging Whether the Whole Thing Workedopening only

Read alongside