Reference/Python
Errors, retries, and fail-closed
Return error dicts from tools, retry only timeout/parse/rate_limit, never retry unknown_city.
Tools return data, not raised exceptions that kill the loop.
Error object
{"error": "<code>", "message": "optional"}
| Code | Retry? | Next action |
|---|---|---|
timeout | yes (capped) | same tool |
rate_limit | yes (capped) | same or backoff skip |
parse | yes (parse budget) | remind JSON only |
unknown_city | no | finish cannot |
not_found | maybe once | different URL |
unknown_tool | no after 1 | stop |
bad_args | no | model must fix args |
forbidden_path | no | different path |
Retry skeleton
python
RETRY = {class="tok-s">"timeout", class="tok-s">"rate_limit"}
def call_with_retry(fn, n=3):
last = None
for _ in range(n):
last = fn()
if last.get(class="tok-s">"error") not in RETRY:
return last
return lastFail-closed rules
- Missing geocode → no weather
- Missing retrieve → no answer
- Missing approval → no mutate
- Missing citation open → no positive finish
- Max steps → budget / cannot-answer, not a guess
Exceptions you still raise
Schema bugs in your code (not the model): raise ValueError("shape") in parse_action. Convert to a parse observation at the loop boundary.
Note:except Exception: pass is how production agents eat disk-full errors and keep billing tokens.