Lesson 2 of 9 · 4 min read
Tool Errors as Observations
In this lesson
TL;DR: Classify every tool failure into one of three bins. Transient: retry in the dispatcher with backoff, jitter and a budget, invisible to the model. Correctable: return a structured observation that says what was wrong, what valid input looks like, and whether retrying could help. Terminal: stop or escalate with the reason. Never swallow an error into an empty or "ok" result, never paste a stack trace into the context, and never retry a non-idempotent write without a key.
After this lesson, you should be able to sort any tool failure into the right bin, write an error result a model can recover from, design the retry policy the model never sees, and recognise the three error-handling bugs that show up most in agent traces.
Before you read
Commit to an answer now. The lesson that follows explains it, and having guessed first, even wrongly, makes the explanation easier to remember.
1book_meeting returns {"error": "400 Bad Request"} when the requested time is in the past. The agent tries the same time again, then gives up. What should the result have said?
Three bins
Every failure a tool can produce belongs in exactly one of three bins, and the bin decides who handles it.
| Bin | Examples | Who handles it | What the model sees |
|---|---|---|---|
| Transient | Timeout, HTTP 429, 502, 503, connection reset, on an idempotent call | The dispatcher: retry with backoff, jitter and a budget | Nothing, unless retries run out |
| Correctable | Invalid argument, unknown id, a business rule ("order already shipped"), missing permission the user could grant | The model, given a useful observation | A structured error with what to do next |
| Terminal | Dependency down past its retry budget, a policy refusal, a bug in the tool | The harness: stop, escalate or degrade | The reason, and that retrying will not help |
The bin is a property of the failure, not of the tool. The same orders_get produces a transient 503 on Tuesday and a correctable "no such order" on Wednesday.
Transient failures stay in the dispatcher
The model is a poor retry loop. It spends a turn (and the whole rereading cost of the context) to decide to try again, it may change the arguments when it should not, and each failed attempt leaves noise in the history. Retries belong in code:
import random
class Transient(Exception):
pass
def call_with_retries(fn, attempts=3, base=0.2, cap=2.0,
sleep=lambda s: None, rng=random.Random(7)):
for attempt in range(attempts):
try:
return fn()
except Transient:
if attempt == attempts - 1:
raise
delay = min(cap, base * 2 ** attempt)
sleep(rng.uniform(0, delay)) # full jitter
raise AssertionError("unreachable")
outcomes = iter([Transient(), Transient(), {"status": "ok"}])
def flaky():
o = next(outcomes)
if isinstance(o, Exception):
raise o
return o
print(call_with_retries(flaky)) # => {'status': 'ok'}
Two rules keep this safe. Retry only what is idempotent: a read, or a write carrying an idempotency key (see Idempotent Side Effects). And bound it twice, per call and per run, so an outage cannot turn every run into a retry storm against a dependency that is already struggling.
Correctable failures become observations
When the model can fix the problem, the result is the fix's instructions. A good error observation has four parts:
{
"error": "invalid_argument",
"field": "start_time",
"message": "start_time must be in the future. Now: 2026-11-23T10:05+05:30",
"retryable": true
}
A machine-readable code (invalid_argument, not_found, precondition_failed, permission_denied) so the harness can count and route them; the field that was wrong; a message in plain language that says what valid input looks like, including any fact the model is missing (here, the current time and zone); and whether calling again with different input could succeed. The retryable flag is what stops the opposite failure: a model hammering a tool that will never accept the call.
Terminal failures end the run honestly
Some failures cannot be fixed by anyone in the run: the dependency is down past its retry budget, a policy refused the action, the tool itself has a bug. Return the reason with retryable: false, and let the harness decide the run's fate: stop with a partial result, escalate to a person, or degrade (answer from what is already known and say what could not be checked). A run that ends saying "the order system is unavailable, I could not confirm the refund" is a correct run.
The three bugs that show up most in traces
- 01toolweather_get(city="Pune")
weather_get(city="Pune")
The dependency returns HTTP 500.
Swallowing. A tool catches every exception and returns ok with an empty payload. The harness cannot retry what it never sees, and the model treats nothing as an answer. Tools should raise transient failures to the dispatcher and return only failures that are meant for the model.
Stack traces in the context. Returning str(exception) with a full traceback costs hundreds of tokens on every later turn, leaks internals, and gives the model nothing it can act on. Translate exceptions into the observation format above at the dispatcher boundary.
Retrying everything. A blanket retry on any error repeats non-idempotent writes after timeouts (the refund that happened twice) and burns budget on errors no retry can fix. Retry only transient failures on idempotent calls.
Say it in 30 seconds
"Every tool failure goes into one of three bins. Transient ones (timeouts, 429s, 5xx on idempotent calls) are retried in the dispatcher with exponential backoff, jitter and a per-call and per-run budget, so the model never sees them. Correctable ones go back as a structured observation: a code, the field, a plain message with what valid input looks like, and whether retrying can help. Terminal ones stop or escalate with the reason. The bugs to look for are swallowed errors, stack traces in the context and retries on writes without idempotency keys."
Check yourself
Answer aloud or on paper before revealing. Producing the explanation unaided is exactly what a panel listens for.
1A payments.refund call times out. Which bin is it in, and what is the safe handling?
2Why include retryable: false on a 'policy: refunds over $100 need approval' error?
3A tool returns {"error": "KeyError: 'eta'"} plus a 40-line traceback. What two things are wrong?