Complete guide to using agentic-chaos for resilience testing.
pip install agentic-chaos
git clone https://github.com/DeepAgentLabs/agentic-chaos.git cd agentic-chaos uv sync --frozen
pip install agentic-chaos[agenticlens]
This enables optional two-way integration: merge chaos events into AgenticLens observability reports.
from agentic_chaos.chaos import chaos_call, chaos_session, TokenTimeoutError
with chaos_session(["token_timeout"]):
try:
result = chaos_call(llm.complete, "What is AI?", faults=["token_timeout"])
except TokenTimeoutError:
print("LLM timed outβhandle gracefully")
agentic-chaos chaos run my_app.py --inject token_timeout,rate_limit_storm --save report.json
Inject chaos into a single function call.
result = chaos_call(
fn, # The function to call
*args, # Positional arguments
faults=["fault_type"], # Which faults apply here
step_name="step", # For tracking/topology
**kwargs # Keyword arguments
)
Create a chaos testing session. All chaos_call() inside use faults from this session.
with chaos_session([TokenTimeoutFault(hang_seconds=3.0), RateLimitStormFault()]):
# chaos_call() here will use these faults
result = chaos_call(llm_fn, query, faults=["token_timeout"])
TokenTimeoutFault(hang_seconds=2.0, mode="raise")RateLimitStormFault(burst_count=3, retry_after=1.0)SilentDegradationFault(degrade_fn=None, seed=None)ToolCallFailureFault(mode="error", timeout_seconds=5.0, tool_name=None)MemoryCorruptionFault(mode="garble", seed=None)InfiniteLoopFault(force_turns=5, continue_value="...")Run a Python script under LLM-level chaos injection.
agentic-chaos chaos run my_app.py --inject FAULT1,FAULT2 --save report.json
Run an agent under agent-level chaos injection.
agentic-chaos agent run my_agent.py --inject tool_failure,memory_corruption --save report.json
List all available fault types.
agentic-chaos chaos list-faults
rate controls how quickly shared state degradesfidelity_session() with HeuristicJudge, DeepEvalJudge, or PydanticEvalsJudge
fidelity_score (0.0β1.0) to a ChaosEventwith chaos_session([RateLimitStormFault(burst_count=2)]):
for i in range(5):
try:
result = chaos_call(llm_fn, query, faults=["rate_limit_storm"])
print(f"Call {i}: Success")
except RateLimitStormError:
print(f"Call {i}: Rate limited")
from agentic_chaos.agents import wrap_tool, TopologyTracker
tracker = TopologyTracker()
search = wrap_tool(search_fn, "search", tracker=tracker, caller_node="Agent")
with chaos_session([ToolCallFailureFault(tool_name="search")]):
agent_workflow()
# See cascade in tracker.topology.as_json()
from agenticlens import profile, step
from agentic_chaos.integrations.agenticlens import attach_events, step_kwargs
with chaos_session(["token_timeout"]) as session:
with profile("Agent") as workflow:
with step("Search"):
chunks = chaos_call(search, q, **step_kwargs(step), faults=["token_timeout"])
attach_events(session, workflow)
# agenticlens analyze workflow.json β shows cost + chaos impact