Skip to content

v0.9: resilience probes and the resilience score

Available in 0.9.0. Everything here is in the core install and needs no other package. YAML experiment files still need pip install 'agentic-chaos[yaml]'.

The offline examples need no provider and no network:

v0.6 contracts judge what happened during a run, from its report. Probes call the live system and judge whether it was healthy before the chaos and recovered after it. The resilience score folds both, plus latency, retry and cost evidence, into one number you can gate on and track.

Probes

A probe is a reusable steady-state check, separate from faults. Define them once and reuse them across runs, workflows and experiments:

from agentic_chaos.probes import HttpProbe, LatencyProbe, ResponseQualityProbe

probes = [
    HttpProbe("http://localhost:8080/health", expect_status=200),
    ResponseQualityProbe(my_agent, "What is 2+2?", expect_contains="4"),
    LatencyProbe(my_agent, "Hello", max_ms=3000),
]
Probe Passes when
HttpProbe(url, expect_status=200, method="GET", expect_contains=None, headers=None, body=None, timeout_seconds=5) the endpoint answers with expect_status (a 4xx/5xx status is still compared, so expect_status=503 works) and, if given, the body contains expect_contains. Standard library only; http:// and https:// URLs only.
ResponseQualityProbe(fn, query, expect_contains=..., expect_not_contains=..., expect_regex=..., expect=..., reference=..., min_similarity=..., judge=...) fn(query) returns and every configured check passes. With reference and min_similarity, a judge scores the answer against the reference: the zero-dependency HeuristicJudge by default, or any v0.3 judge. At least one check is required.
LatencyProbe(fn, query, max_ms=..., samples=1, statistic="max") the max (or median) of samples calls is at most max_ms. A call that raises fails the probe.
FunctionProbe(fn, query=..., expect=None) fn(query) (or fn()) returns without raising and expect, if given, accepts the output.

Every probe also takes:

  • name: defaults to the URL or the function name
  • phases: any of "pre", "during", "post"; the default is ("pre", "post")
  • retries and retry_delay_seconds: re-check a failing probe while the system settles after chaos stops
  • weight: the probe's share of the score's probe component

Custom probes subclass Probe and implement evaluate(). It returns a (message, observed) pair when the system is healthy and raises (ProbeError or any other exception) when it is not. Probe.run() never raises for an unhealthy system: it returns a ProbeResult.

The probe lifecycle

chaos_run() runs one chaos run through the full lifecycle:

from agentic_chaos import RateLimitStormFault, Scope, chaos_run

report = chaos_run(
    my_app,
    [RateLimitStormFault(burst_count=3, scope=Scope(steps=["llm"]))],
    probes=probes,
    baseline=baseline_report,                     # optional: enables latency and cost
    history=".agentic-chaos/resilience-history.json",  # optional: records the trend
)
print(report.resilience_score)        # 0-100, or None when inconclusive
assert report.resilience_score >= 70  # CI gate
  1. pre: probes run with no chaos active. If any fails, the system was not in steady state, so nothing that happens afterwards can be blamed on the chaos. By default no fault is injected and the score is inconclusive. With require_steady_state=False the chaos runs anyway, but the score stays inconclusive.
  2. The target runs repeat times inside a fresh chaos_session. Exceptions are recorded as unhandled_error, not raised.
  3. during: probes run inside that session after the target, with every fault still active. A probe that calls through chaos_call can be hit too. Probe time is not counted in the run's duration.
  4. post: the session closes and probes check that the system came back.
  5. The score is computed, compared with the run history, and stored on the report as report.resilience. Probe results are stored as report.probes.

ChaosWorkflow(..., probes=[...], weights={...}) uses the same lifecycle around a whole workflow:

  • pre probes run before the first node. A failure halts the workflow before any chaos.
  • during probes run inside every step's session, tagged with the step name.
  • post probes run after the last node. They are skipped when the run stops at a Suspend gate.

workflow.run(baseline=..., history=...) scores the merged run. Suspended runs are not recorded in the history.

The resilience score

The score is a weighted mean of five components. A component that the report cannot show is left out, and the remaining weights are renormalized. The score never invents a number: with nothing to compute, it is None (inconclusive).

Component Default weight Computed from
recovery 0.35 whether each injected fault was survived (see below)
probes 0.25 the weighted pass rate of during and post probe results; during results count half as much as post
latency 0.15 wall-clock slowdown against a baseline report: no slowdown scores 1, three times slower (latency_tolerance=2.0) or worse scores 0
retry_efficiency 0.15 injected failures per retry: one retry per failure scores 1, a retry storm scores lower; left out when nothing was retried
cost 0.10 cost overhead against a baseline with a recorded cost: none scores 1, double the cost (cost_tolerance=1.0) scores 0

Each fault event gets a verdict:

Verdict Meaning Counts as
retried a later call to the same step succeeded 1
fallback an errored step was not called again and nothing escaped 1
tolerated a delay or loop that did not escape 1
judged degraded output a v0.3 judge scored its fidelity score
unrecovered every later call to that step failed 0
escaped the run's unhandled error came from this fault 0
unverified degraded output with no judge left out

How the verdicts are assigned:

  • Escaped faults. The unhandled error carries the event when the fault's own exception escaped. When the app wrapped or replaced it, the error is attributed to the last fault injected before the run ended.
  • Workflow stages. Calls are matched within one workflow stage, so one stage never "recovers" another's failure.
  • Silent degradation is deliberately left out without a judge. A degraded answer that nobody checked cannot be called recovered.

The score is inconclusive (None) when:

  • a pre probe failed
  • the run was a dry run
  • no fault fired, which includes a run that crashed before any fault fired
  • no component could be computed

Circuit-breaker aborts are scored on what ran, with a reason attached.

Grades: A ≥ 90, B ≥ 75, C ≥ 60, D ≥ 40, F below.

from agentic_chaos.resilience import compute_resilience

score = compute_resilience("chaos_run.json", baseline="baseline.json",
                           weights={"cost": 0, "recovery": 0.5})
score.score, score.grade, score.meets(70)
score.component("recovery").detail     # "3/3 injections recovered"
[f.as_json() for f in score.faults]    # per-fault-type breakdown

compute_resilience() reads only the report, so any saved report, including CI artifacts and reports from earlier releases, can be scored later.

ResilienceHistory keeps one compact entry per scored run in a JSON file: the name, report ID, time, score, grade, component scores and per-fault scores. It never stores the full report.

from agentic_chaos import ResilienceHistory

history = ResilienceHistory(".agentic-chaos/resilience-history.json",
                            max_runs=30, max_age_days=90)
trend = history.record(score)  # {"previous": 64, "delta": 8, "direction": "up", ...}
  • A trend compares the new score with the latest scored entry with the same name. Inconclusive runs are recorded but never used as the comparison.
  • max_runs keeps the newest N entries per name. max_age_days drops older entries for every name. Retention is applied on every record() and by prune().
  • Writes replace the file atomically. The store is not locked, so give concurrent jobs separate files.

CLI

chaos run, agent run, experiment run and chaos workflow run gained:

Option Effect
--probe SPEC chaos run / agent run only, repeatable. An http(s):// URL must answer 200. A file.py:function or package.module:function spec must return without raising. Probes run pre and post.
--min-score N Exit 1 unless the score is at least N. An inconclusive score fails. For experiments, this overrides resilience.min_score.
--history PATH Record the score and show the trend.
--history-max-runs N, --history-max-age-days D Retention for that file.
--baseline PATH Already on chaos run / agent run for contracts, and now also feeds the latency and cost components. New on experiment run.

Every run now prints a probe table and a resilience report with per-component and per-fault bars:

Resilience Report: resilience-probes
════════════════════════════════════
  Overall Score: 100/100 (A)
  Component         Score                 Weight  Detail
  recovery          ████████████ 100/100    0.35  3/3 injections recovered
  probes            ████████████ 100/100    0.25  4/4 during/post probe checks passed
  latency           ············   n/a      0.15  no baseline report
  retry efficiency  ████████████ 100/100    0.15  3 retries for 3 injected failure(s)
  cost              ············   n/a       0.1  no baseline with a recorded cost
  Fault             Score                 Events  Outcome
  rate_limit_storm  ████████████ 100/100       3  3 retried
  Trend: ↑ +8 from last run (was 92)

A failed pre probe exits 1 before any chaos. When asked, it still saves the report (and an AIOS run with status failed) explaining why.

The new score group works on saved files:

agentic-chaos score show chaos_run.json --baseline baseline.json --min-score 70
agentic-chaos score show chaos-workflow.json --weight cost=0 --json   # workflow reports too
agentic-chaos score history --history .agentic-chaos/resilience-history.json
agentic-chaos score prune --history .agentic-chaos/resilience-history.json --max-runs 30

Experiments

Experiment files gained probes and resilience sections:

probes:
  - type: http
    url: http://localhost:8080/health
  - type: response_quality
    name: answers
    query: How do I reset my password?
    expect_contains: "Answer:"
    phases: [pre, during, post]
  - type: latency
    query: hello
    max_ms: 1000
    samples: 3
resilience:
  min_score: 80
  weights: { cost: 0 }
  history:
    path: .agentic-chaos/resilience-history.json # relative to the working directory
    max_runs: 30
    max_age_days: 90
  • Probe types are http, response_quality, latency and function.
  • Probe targets. Probes other than http use the experiment target unless they name their own. A query, or a response_quality probe, needs a function target.
  • History may be given as a plain path string.
  • Validation is located and gives did-you-mean suggestions, as in v0.8. It covers unknown probe types and fields, invalid URLs and regexes, out-of-range min_score values, unknown weight names, retention values and duplicate probe names. Targets are still parsed, never executed.

pytest

@pytest.mark.chaos accepts probes=[...] and min_score=N:

@pytest.mark.chaos(faults=["rate_limit_storm"], probes=[quality], min_score=90)
def test_recovers():
    assert weather_agent("?") == "sunny"
  • A failed pre probe fails the test before any fault is injected.
  • A score below min_score fails the test after its contracts are checked.
  • Every chaos test's report (and its --chaos-report-dir artifact) carries probes and resilience.
  • The terminal summary shows the lowest score.

Report and AIOS changes

  • ChaosReport gains probes (a list of probe results) and resilience (the score JSON, version: "1.0"), plus the resilience_score property.
  • WorkflowReport gains the same fields, and to_chaos_report() carries them.
  • Both fields are optional, so reports from earlier releases still load.
  • AIOS exports add a derived resilience_score measurement (0-100, unit score) when the score was computed. Probe results and the full breakdown ride in the io.deepagentlabs.agentic-chaos producer extension. Native event shapes and IDs are unchanged.

Ecosystem

  • No sibling runtime needs a change: the new report fields are additive.
  • Agentic Sidecar's optional agentic-chaos extra and the MCP server's hosted images are updated to admit or pin 0.9.0.
  • Control Tower and AgenticLens keep reading native reports as before. The score is producer evidence, not a Tower health signal or an Evals release gate.