# When the agent runs out of credit

> An agent that can't do its job mustn't pretend it's working.

Author: Aleš Nypl · https://engineloop.cz/ales-nypl

My email agent runs unattended. One day it stopped working because the credit with the AI provider had run out. Nothing dramatic, just an error message. The interesting part was what came out of it.

## Two weaknesses it exposed

- **What should happen when the AI is unavailable?** The rule now is that an account-level error stops the whole run, and the system lets me know straight away. Nothing is marked or written, and the email waits, untouched, for the next run. Unfinished work is never passed off as done.
- **How does it pick up after an outage?** Originally the agent only looked back over a fixed period. After a longer outage, older email would never have been picked up. Now it remembers its last successful run and always picks up where it left off. It widens the period itself to cover the whole gap.

## Three lessons

- **Failure has to be loud.** A silent error is worse than a crash.
- **A system has to remember where it stopped,** not just what time it is.
- **The safeguard belongs in the code, not in my head.** A rule you can get round by forgetting isn't a rule.

I didn't plan any of this. The system is more robust because of it. A mistake is cheap, as long as you turn it into a rule.
