An agent rarely finishes a task with one model call. It reads a file, calls a tool, looks at the result and asks the model again. If the provider answers the fourth call with HTTP 429, the task is half done and some tools have already run. I had to handle this twice: in Praxi-Bot, which I write in Rust, and in the Python rewrite of my voice assistant JARVIS.
A limit in the middle of a task
The Praxi-Bot guide describes the situation in its section on the Gemini free tier: each model has its own limits per minute and per day, an agent makes several model calls per task, and a daily cap does not recover by waiting a few seconds.
Three things can go wrong then. The run can wait for a limit that will not reset soon, repeat a step that has already changed something, or quietly continue with another model while the user does not know where the answer came from.
Model selection
In Praxi-Bot every bot has a profile that names models by role. executor runs the agent loop and is the only required role. light is an optional model for simple first turns, classifier an optional small model for the routing step, and fallback the list of alternates. When a call needs a model, ModelSelector::pick in crates/provider-catalog/src/selector.rs returns the first of four candidates that is set:
- Sub-agentThe model a sub-agent asked for explicitly
- Bot and roleThe model pinned to this bot and role
- Global defaultThe global default model
- First providerThe default of the first registered provider
JARVIS has no bots, it has kinds of work. core/src/jarvis/providers/registry.py defines them as roles: VOICE_BRAIN, FAST_DECIDER, TEXT_WORKER, VISION_GROUND, EMBEDDING, STT and TTS. Each role has an ordered list of (provider, model) targets, and each provider has a pool of API keys. So a request in JARVIS chooses two things: a target and a key.
Reasons to fall back
Praxi-Bot first puts every provider error into a class, without parsing the text shown to the user. Two short functions in crates/provider-catalog/src/error.rs then decide what is allowed:
pub fn is_retryable(&self) -> bool {
!matches!(self, Self::CliTurn { .. })
&& matches!(self.class(),
FailureClass::RateLimit | FailureClass::Overloaded | FailureClass::Timeout
| FailureClass::Network | FailureClass::MalformedToolCall)
}
/// A different model can also resolve a capability mismatch.
pub fn can_fallback(&self) -> bool {
self.is_retryable() || matches!(self, Self::Unsupported { .. })
}What the two functions give for each kind of error:
| Error | Retried | Falls back |
|---|---|---|
| Rate limit, HTTP 429 | Yes | Yes |
| Overloaded server, timeout, network error | Yes | Yes |
| Malformed tool call | Yes | Yes |
| Missing capability (tools, vision) | No | Yes |
| Exhausted quota, HTTP 402 | No | No |
| Rejected key | No | No |
| Conversation too long, content filter, invalid request | No | No |
| Coding CLI turn | No | No |
According to the guide, a model step gets 3 attempts with backoff. A model that lacks a capability, such as tools or vision, is not retried, but the next model may have it, so that also counts as a reason to fall back. The last four rows of the table are hard stops.
The loop in crates/agent-core/src/exec.rs walks the primary model and then the fallback list from the bot's profile, and nothing else. Coding CLIs that act as a bot's model are the exception. The comment in the source says why: a whole CLI turn cannot be replayed automatically because tools may already have run.
JARVIS states its rules in the docstring of its registry module:
* RateLimited → cool down that (key, model) and try the next key
* AuthError → park the key for an hour and try the next key
* BadRequest → this model/payload won't work; move to the next target
* ProviderError→ short cool-down, next keyThe distinction here is between the key and the target. A rate limit or a rejected key says something about one key, so the same model is tried with the next key. A bad request is about the model or the payload. No other key will change that, and the loop moves to the next target.
Cooldowns
In JARVIS the cooldowns are constants at the top of the file: DEFAULT_RATE_COOLDOWN = 30, ERROR_COOLDOWN_SECONDS = 10 and AUTH_PARK_SECONDS = 3600. The rate cooldown applies to a (key, model) pair and not to the whole key. The pool is walked starting after the last key used, and before every call a QuotaTracker is asked whether this key still has room for this model. A key it reports as exhausted is skipped without a request being sent.
Praxi-Bot keeps its cooldowns per provider and takes their length from the server. If an error carries a retry delay, the loop skips that provider's models until the time has passed. If the whole chain failed for transient reasons only, the run does not end: it waits with exponential backoff, from 5 seconds up to 60, and walks the chain again. The total wait is bounded by the transient_outage_budget setting.
The model that answered
Each time the Praxi-Bot loop moves to the next model it emits Event::ModelFallback { run_id, from, to, reason }. The desktop app shows it as a warning line in the chat timeline. The user sees which model stopped, which one took over and why. While the loop waits for an outage to pass, it also sends a recoverable error message that says how many seconds it will wait.
JARVIS says less. When every target of a role has been tried, the registry raises NoRouteAvailable with the role and the list of attempts, one line per provider, model and key.
Cost control
Falling back keeps a task alive but does not make it cheaper. Praxi-Bot has two mechanisms for that, and both are off by default.
The first is the light model, which takes a small share of first turns. The choice is a fixed rule and adds no model call: a user message of at most 200 Unicode characters qualifies when the routing ladder returns a non-empty tool hint and every hinted tool only reads. The greetings merhaba, selam, hello and hi qualify as well when they match exactly. The move to the executor is one-way. It happens when the light model lacks a capability, after two malformed responses, when a light reply asks for a tool that does more than read (the reply is discarded before any tool runs), after any tool has executed, or at the fourth model step. A tier decision never grants a permission. The guide states the limit too: a discarded light reply is followed by one more call to the executor, so tiering does not guarantee fewer calls.
The second is a monthly spending limit, set per installation. CallGuard::start checks it before every model call.
- Scope
- Per installation, monthly. Bots can have limits of their own.
- Default
- Off
- Allowed range
- 1 to 1,000,000 US dollars
- Spend for the month
- The sum of the
cost_usdvalues in the usage records - Model with no price
- Records
null. The call is not counted and its price is never guessed. - Blocked call
- Fails with the stable code
spend_limit_reached
Unfinished calls reserve an estimate, otherwise parallel calls could all pass the limit at 99 percent.
In short
Both projects arrived at the same order of work. Classify the error before deciding anything. Try the cheapest change first: one more attempt or another key, then another model, then a wait. Do not repeat a step that may already have acted. Tell the user which model answered. The details differ: Praxi-Bot follows the chain its owner wrote and the delay the provider asks for, while JARVIS rotates a pool of keys with fixed cooldowns.
| Case | Praxi-Bot | JARVIS |
|---|---|---|
| What is chosen | A model, by role in the bot's profile | A target for the role and a key from the pool |
| Rate limit | Retry, then the next model | Next key. The (key, model) pair cools down for 30 seconds by default. |
| Rejected key | Hard stop | Key parked for 3600 seconds, next key |
| Invalid request | Hard stop | Next target |
| Whole chain exhausted | Waits 5 to 60 seconds on transient errors, walks the chain again | NoRouteAvailable error |
| Notice | Event::ModelFallback on every move, a warning line in the chat | The role and the list of attempts, inside the error |




