**What it is:** Flakestorm injects faults into the **tools, APIs, and LLMs** your agent depends on — not into the user prompt. This answers: *Does the agent handle bad environments?*
**Why it matters:** In production, tools return 503, LLMs get rate-limited, and responses get truncated. Environment chaos tests that your agent degrades gracefully instead of hallucinating or crashing.
---
## When to use it
- You want a **chaos-only** test: run golden prompts against a fault-injected agent and get a single **chaos resilience score** (no mutation generation).
- You want **mutation + chaos**: run adversarial prompts while the environment is failing.
- You use **behavioral contracts**: the contract engine runs your agent under each chaos scenario in the matrix.
---
## Configuration
In `flakestorm.yaml` with `version: "2.0"` add a `chaos` block:
```yaml
chaos:
tool_faults:
- tool: "web_search"
mode: timeout
delay_ms: 30000
- tool: "*"
mode: error
error_code: 503
message: "Service Unavailable"
probability: 0.2
llm_faults:
- mode: rate_limit
after_calls: 5
- mode: truncated_response
max_tokens: 10
probability: 0.3
```
### Tool fault options
| Field | Required | Description |
|-------|----------|-------------|
| `tool` | Yes | Tool name, or `"*"` for all tools. |
Chaos can target **content that flows into the agent from tools** (indirect_injection) or **the user input before each invoke** (memory_poisoning). The **chaos interceptor** applies memory_poisoning to the input before calling the agent; LLM faults (timeout, truncated_response, rate_limit, empty, garbage, response_drift) are applied in the same layer (timeout before the call, others after the response). Configure under `chaos.context_attacks` as a **list** or **dict**; each scenario in `contract.chaos_matrix` can also define `context_attacks`. See [Context Attacks](CONTEXT_ATTACKS.md) for types and examples.
| `flakestorm run --chaos` | Mutation tests **with** chaos enabled (bad inputs + bad environment). |
| `flakestorm run --chaos --chaos-only` | **Chaos only:** no mutations; golden prompts against fault-injected agent. You get a single **chaos resilience score** (0–1). |
| `flakestorm run --chaos-profile api_outage` | Use a built-in chaos profile instead of defining faults in YAML. |
| `flakestorm ci` | Runs mutation, contract, **chaos-only**, and replay (if configured); outputs an **overall** weighted score. |
Profile YAMLs live in `src/flakestorm/chaos/profiles/`. Use with `--chaos-profile NAME`. The **`model_version_drift`** profile exercises the LLM fault type **`response_drift`**.