Chaos Engineering

ChaosRunner runs your agent under a clean baseline and then under each requested fault, so you can measure how behavior drifts when things go wrong.

Faults

Eight fault types are available (all wrapped as agent decorators):

FaultEffect
api_failRaises a simulated API failure.
timeoutRaises a timeout error.
rate_limitRaises a 429 rate-limit error.
network_delayRaises a connection-reset error.
tool_crashMarks tool calls as crashed.
memory_corruptPollutes memory writes.
token_limitTruncates the output.
malformed_outputReturns [[MALFORMED]].

Running chaos

from entropy import ChaosRunner

cr = ChaosRunner(seed=0)
result = cr.run(agent, dataset, ["api_fail", "timeout"], trials=50)
print(cr.summary(result))

result contains "baseline" and a "faults" dict keyed by fault name. Each entry is a full results dictionary, so you can diff success_rate, drift_score, recovery_score, etc.

Fine-grained injection

Inject a single fault manually with a probability and seed:

from entropy import chaos_inject, chaos_available

print(chaos_available())   # list of fault names
faulty = chaos_inject(agent, "tool_crash", p=0.3, seed=1)

Interpretation

A large jump in drift_score or failure_rate under a fault signals brittle behavior. Pair chaos with assert_stable thresholds for a resilience gate in CI.