agentleFS
MLOps-CoursesMLOps-Courses/agentops-open-course/skills/agent-resilience/SKILL.md

agent-resilience

Skill2 starsChanged 4 months agoMITView on GitHub

Make an LLM agent's tool and model calls survive flaky and dead dependencies with deadlines, bounded retries, a circuit breaker, and a validated model fallback. Use when an agent hangs on a slow tool, storms a down gateway with retries, or has no failover when its model endpoint is unreachable.

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. 2867203296/hermes-agent★ 0same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository8 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    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:

    Write deterministic unit tests with an injected clock and fake failing calls: assert the breaker opens after the threshold, fails fast …

    line 35

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 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

Agent Resilience

Give an agent's outbound calls three layers of failure handling, applied in the right place. The rule that generalizes: retry only where the call is idempotent, and only where a replica exists to retry against.

When to use

  • A slow tool or model call can hang a whole turn instead of failing on a deadline.
  • A hard-down dependency is hammered with the full retry budget on every turn.
  • The primary model endpoint has no failover, so its outage is a total outage.
  • You are about to add a retry to a write — stop and read step 2 first.

Steps

  1. Bound every call with a deadline. Wrap each tool/model call so exceeding a timeout raises a clear error instead of hanging. Run sync tools in a worker thread so the deadline can actually fire on the event loop.
  2. Retry only idempotent reads, never writes. Retrying a non-idempotent action (restart, resolve, charge) can apply it twice. Retry reads with bounded, exponential backoff; leave writes to run exactly once behind human confirmation.
  3. Add a circuit breaker for dead dependencies. After N consecutive failures, open the breaker and fail fast (shed load) until a cooldown elapses, then let one trial call test recovery. Keep it opt-in so default behavior stays retry-only, and emit a metric each time it opens.
  4. Fail over the model only to a validated fallback. Try a primary model; on a retriable 429/5xx before any response, fall back to a secondary you have evaluated. Never fail over on a 4xx or an ambiguous 408 (the request may already be billed), never switch mid-stream (it splices two answers), and prefer a smaller same-provider model so failover keeps your cost and privacy properties. Prefer the framework primitive (ADK's FallbackModel) over a hand-rolled wrapper: it also restores the request before the next attempt.

Reference implementation

From the AgentOps Open Course (agent modules live under agents/python/src/agent/):

  • resilience.py — with_resilience (deadline + bounded retry, never on writes).
  • circuit.py — a deterministic, clock-injectable CircuitBreaker.
  • model.py — ADK's FallbackModel wrapping a primary and a validated fallback.
  • Course chapters 4.5. Guardrails and 5.4. Model Gateway.

Verify

Write deterministic unit tests with an injected clock and fake failing calls: assert the breaker opens after the threshold, fails fast while open, and recovers half-open; assert a write is never wrapped; assert the fallback engages only on a retriable status before the primary responds.

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.