feat: Vision fallback chain for auxiliary models (Gemini → configured fallback → local)#25878
Closed
saved-j wants to merge 1 commit into
Closed
feat: Vision fallback chain for auxiliary models (Gemini → configured fallback → local)#25878saved-j wants to merge 1 commit into
saved-j wants to merge 1 commit into
Conversation
When the primary vision provider (e.g. Gemini) fails with payment errors,
server errors (5xx), or quota exhaustion, automatically fall back through
the configured fallback_provider → local_fallback_provider chain.
Changes:
- _resolve_vision_fallback_client(): resolves configured fallback chain
from auxiliary.vision.{fallback,local_fallback}_{provider,model}
- _is_server_error(): detects 5xx HTTP errors that should trigger fallback
- _is_payment_error(): extended to catch 'quota exceeded' messages
- call_llm() and async_call_llm(): invoke fallback chain before raising
Config example:
auxiliary:
vision:
provider: gemini
model: gemini-2.5-flash
fallback_provider: Xiaomi-TP
fallback_model: mimo-v2-omni
local_fallback_provider: ollama-launch
local_fallback_model: llama3.2-vision:11b
Verified: Gemini 429 → Xiaomi-TP (mimo-v2-omni) fallback chain working.
Tested with image analysis: bird in hand (vivo X200 Ultra, 35mm f/1.69).
This was referenced May 16, 2026
This was referenced May 26, 2026
Contributor
|
This has been implemented on current Automated hermes-sweeper review evidence:
One caveat: the merged schema is |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When the primary vision provider fails (payment errors, quota exhaustion, server errors), automatically fall back through a configurable chain instead of raising immediately.
Problem
Gemini free tier (250 req/day) exhausts quickly with Hermes agent usage. Without a fallback chain, all vision requests fail with HTTP 429 until quota resets. The existing `fallback_provider` and `local_fallback_provider` config keys in `auxiliary.vision` were dead keys — the code never read them.
Changes
1. `_resolve_vision_fallback_client()` (new function)
Resolves the configured fallback chain from `auxiliary.vision.{fallback,local_fallback}_{provider,model}`. Tries `fallback_provider` first, then `local_fallback_provider`.
2. `_is_server_error()` (new function)
Detects HTTP 5xx errors (500, 502, 503, 504) that indicate provider-side failures — should trigger fallback rather than retry.
3. `_is_payment_error()` (extended)
Now catches `"quota exceeded"` and `"exceeded your current quota"` messages from Gemini API.
4. `call_llm()` and `async_call_llm()` (modified)
Before raising, check if `task == "vision"` and either:
If so, resolve and invoke the fallback chain immediately.
Configuration
```yaml
auxiliary:
vision:
provider: gemini
model: gemini-2.5-flash
fallback_provider: Xiaomi-TP
fallback_model: mimo-v2-omni
local_fallback_provider: ollama-launch
local_fallback_model: llama3.2-vision:11b
```
Testing
Verified on production:
Logs
```
INFO agent.auxiliary_client: Vision fallback: using Xiaomi-TP (mimo-v2-omni)
INFO agent.auxiliary_client: Vision fallback chain: using Xiaomi-TP (mimo-v2-omni)
INFO tools.vision_tools: Image analysis completed (2158 characters)
```
Related