agentleFS
youcislayoucisla/Agent-Foundry/skills/core/fallback-model-routing/SKILL.md

fallback-model-routing

Skill1 starsChanged 23 days agoMITView on GitHub

'Route around provider overload, rate limits, and timeouts without hiding

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use the same messages for every model in the chain.

    line 63
  2. Distinctive:

    When a model rejects the system role, fold the skill text into the user turn.

    line 100

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Fallback Model Routing

A failed model call is a routing event, not a reason to abandon the task. Route it deliberately and leave a trail.

When to Use

  • A provider returns overload, rate-limit, timeout, or 5xx errors.
  • A model is unavailable in the current region or account.
  • The task has a declared fallback model or a smaller backup tier.
  • A long batch cannot afford to stop on one failed call.
  • Production paths with a latency or availability budget.
  • Batch jobs where one provider outage should not kill the run.
  • Tiered routing: frontier model first, balanced model as backup.
  • Any call where the prompt is unchanged and only the engine differs.

Procedure

1 — Declare the chain up front

Order matters. Put the preferred model first and the cheapest acceptable backup last. Resolve aliases to full model IDs before the first call so logs are stable.

primary: claude-sonnet-5-5
fallbacks: [claude-haiku-5-5]

2 — Classify the failure before retrying

FailureAction
Timeout, overload, 429, 5xxTry the next model
Auth rejected (401/403)Stop. A fallback cannot fix credentials
Invalid request (schema, context too long)Fix the request, do not reroute
Budget exhaustedStop and report spend

Blind retries on auth or budget errors burn time and hide the real cause.

3 — Bound the attempts

Retry the primary within its configured retry count, then walk the fallback list once. Cap the chain length. No fallback loops, no re-walking a model that already failed.

4 — Preserve the request

Use the same messages for every model in the chain. Do not silently shorten the prompt or drop the schema to make a smaller model fit; that changes the task.

5 — Report provenance

Return the model that actually answered. A caller comparing quality, cost, or latency needs to know when a fallback served the request.

Anti-patterns

  • Falling back on a 401 and reporting "provider outage".
  • Retrying the same overloaded model five times with no delay budget.
  • Hiding the switch so cost reports look flat.
  • Changing the prompt between primary and fallback.
  • Falling back to a model that cannot satisfy the required schema.

References

  • capabilities

Verification Checklist

  • Chain is ordered and bounded
  • Auth and budget failures stop immediately
  • The request is byte-identical across models
  • The answering model is recorded
  • A test injects a primary failure and asserts the fallback result

Composes With

  • structured-output-contract — keeps the schema fixed across models
  • budget-guard — stops the chain when spend hits the ceiling
  • execution-observability — records which model served each run

Capability-Aware Routing

  • Inspect per-model capabilities before building messages: system-prompt support, context window, default temperature, stop tokens per mode.
  • When a model rejects the system role, fold the skill text into the user turn. Never send an unsupported role and hope.
  • Reject an over-context request before the call; do not silently truncate.
  • Forward seed and temperature only when the caller set them, and record them in the request digest.
  • Retry transport failures with backoff; never retry an auth error or a refusal into another model.
  • Gate adaptive attempt allocation on queue depth. The optimization is negative at low load.
  • Cache and score identity include runtime version, git SHA, model revision, and effective params.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.