agent-chaos-engineering 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of agent-chaos-engineering might be problematic. Click here for more details.

Files changed (46) hide show
  1. agent_chaos_engineering-0.1.0/.gitignore +25 -0
  2. agent_chaos_engineering-0.1.0/CHANGELOG.md +35 -0
  3. agent_chaos_engineering-0.1.0/CITATION.cff +16 -0
  4. agent_chaos_engineering-0.1.0/LICENSE +201 -0
  5. agent_chaos_engineering-0.1.0/NOTICE +6 -0
  6. agent_chaos_engineering-0.1.0/PKG-INFO +305 -0
  7. agent_chaos_engineering-0.1.0/README.md +270 -0
  8. agent_chaos_engineering-0.1.0/docs/recovery-patterns.md +51 -0
  9. agent_chaos_engineering-0.1.0/docs/scorecard.md +65 -0
  10. agent_chaos_engineering-0.1.0/examples/demo_pipeline.py +46 -0
  11. agent_chaos_engineering-0.1.0/examples/plans/standard.json +14 -0
  12. agent_chaos_engineering-0.1.0/examples/self_healing_loop.py +42 -0
  13. agent_chaos_engineering-0.1.0/pyproject.toml +97 -0
  14. agent_chaos_engineering-0.1.0/src/agent_chaos/__init__.py +157 -0
  15. agent_chaos_engineering-0.1.0/src/agent_chaos/_version.py +2 -0
  16. agent_chaos_engineering-0.1.0/src/agent_chaos/adapters/__init__.py +8 -0
  17. agent_chaos_engineering-0.1.0/src/agent_chaos/adapters/langchain.py +34 -0
  18. agent_chaos_engineering-0.1.0/src/agent_chaos/adapters/langgraph.py +223 -0
  19. agent_chaos_engineering-0.1.0/src/agent_chaos/adapters/ma_trace.py +51 -0
  20. agent_chaos_engineering-0.1.0/src/agent_chaos/checkpoint.py +137 -0
  21. agent_chaos_engineering-0.1.0/src/agent_chaos/cli.py +173 -0
  22. agent_chaos_engineering-0.1.0/src/agent_chaos/consensus.py +228 -0
  23. agent_chaos_engineering-0.1.0/src/agent_chaos/detection.py +321 -0
  24. agent_chaos_engineering-0.1.0/src/agent_chaos/faults.py +504 -0
  25. agent_chaos_engineering-0.1.0/src/agent_chaos/healer.py +338 -0
  26. agent_chaos_engineering-0.1.0/src/agent_chaos/injector.py +398 -0
  27. agent_chaos_engineering-0.1.0/src/agent_chaos/patterns.py +263 -0
  28. agent_chaos_engineering-0.1.0/src/agent_chaos/plan.py +166 -0
  29. agent_chaos_engineering-0.1.0/src/agent_chaos/py.typed +0 -0
  30. agent_chaos_engineering-0.1.0/src/agent_chaos/runner.py +240 -0
  31. agent_chaos_engineering-0.1.0/src/agent_chaos/scorecard.py +238 -0
  32. agent_chaos_engineering-0.1.0/src/agent_chaos/sim.py +175 -0
  33. agent_chaos_engineering-0.1.0/src/agent_chaos/zones.py +208 -0
  34. agent_chaos_engineering-0.1.0/tests/conftest.py +28 -0
  35. agent_chaos_engineering-0.1.0/tests/test_adapters_langchain.py +37 -0
  36. agent_chaos_engineering-0.1.0/tests/test_adapters_langgraph.py +85 -0
  37. agent_chaos_engineering-0.1.0/tests/test_checkpoint_consensus.py +80 -0
  38. agent_chaos_engineering-0.1.0/tests/test_cli.py +65 -0
  39. agent_chaos_engineering-0.1.0/tests/test_detection.py +90 -0
  40. agent_chaos_engineering-0.1.0/tests/test_faults.py +176 -0
  41. agent_chaos_engineering-0.1.0/tests/test_injector.py +211 -0
  42. agent_chaos_engineering-0.1.0/tests/test_ma_trace_bridge.py +32 -0
  43. agent_chaos_engineering-0.1.0/tests/test_patterns_healer.py +182 -0
  44. agent_chaos_engineering-0.1.0/tests/test_plan.py +55 -0
  45. agent_chaos_engineering-0.1.0/tests/test_runner_sim.py +149 -0
  46. agent_chaos_engineering-0.1.0/tests/test_zones.py +46 -0
@@ -0,0 +1,25 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ build/
6
+ dist/
7
+ wheels/
8
+ .venv/
9
+ venv/
10
+ # Tooling caches
11
+ .pytest_cache/
12
+ .mypy_cache/
13
+ .ruff_cache/
14
+ .coverage
15
+ coverage.xml
16
+ htmlcov/
17
+ uv.lock
18
+ # Editors / OS
19
+ .vscode/
20
+ .idea/
21
+ *.swp
22
+ .DS_Store
23
+ # Runtime artefacts
24
+ .agent-chaos/
25
+ chaos-report.json
@@ -0,0 +1,35 @@
1
+ # Changelog
2
+
3
+ All notable changes to `agent-chaos-engineering` are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
5
+ [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.0] - 2026-10-03
10
+
11
+ First release on PyPI: the initial version of 27 September 2026 (*Added*) together with
12
+ the changes made to it before publishing.
13
+
14
+ ### Added
15
+ - Fault taxonomy: network delay, tool error, hallucination loop, cyclic dependency, stale memory, miscoordination, input perturbation, data poisoning, perception spoofing.
16
+ - `ChaosPlan` with round-robin / all schedules, forced primary injections, JSON/YAML persistence and three presets (operational faults, adversarial faults, everything).
17
+ - `ChaosInjector` with tool, reasoning, message, memory and input surfaces (sync + async), deterministic seeding, virtual clocks and full injection logs.
18
+ - Detection: reasoning-variance and semantic-coherence monitors with temporal filtering; redundant-path discrepancy detector.
19
+ - `CheckpointStore` (semantic checkpoints, restoration objective) and the four recovery patterns with their matching criteria and cost-based selection.
20
+ - `SelfHealer` orchestrator: dependency graph, failure context, incidents, quarantine with probation, consensus weights, reporting.
21
+ - Resilience zones, `ZoneSupervisor` control layer with audit log and lockdown, `TrustWeightedDecision` fusion with cross-path consistency.
22
+ - `ScenarioRunner` (baseline / chaos / healed arms with identical seeds) and the resilience `Scorecard` (accuracy retention, recovery latency, CAFR, per-fault success, decision integrity, availability, overhead, RLI/CAFRI/ARI/composite).
23
+ - Built-in simulated pipeline scenario, the `agent-chaos` CLI, LangGraph (`chaos_node`, `heal_node`, `SelfHealingCheckpointSaver`) and LangChain (`chaos_tool`) adapters, and a bridge to `multi-agent-observability` (MA-Trace).
24
+
25
+ ### Changed
26
+ - The operational-fault preset and its constructor are now `standard` / `ChaosPlan.standard()`;
27
+ the bundled plan file is `examples/plans/standard.json`.
28
+ - README, `NOTICE`, `CITATION.cff` and the package metadata now describe the software only;
29
+ the README no longer lists CrewAI among the supported frameworks (there is no CrewAI adapter).
30
+
31
+ ### Fixed
32
+ - CI caches uv by `pyproject.toml` (the lock file is not committed), which newer `setup-uv` releases require.
33
+ - README install line named the companion package `ma-trace`; the distribution is `multi-agent-observability`.
34
+ - `docs/recovery-patterns.md` now describes `affected_agents` as the number of degraded agents (the
35
+ code never restricted it to downstream agents).
@@ -0,0 +1,16 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use agent-chaos-engineering, please cite it as below."
3
+ type: software
4
+ title: "agent-chaos-engineering: chaos engineering and self-healing recovery patterns for multi-agent LLM systems"
5
+ version: 0.1.0
6
+ date-released: "2026-10-03"
7
+ license: Apache-2.0
8
+ repository-code: "https://github.com/nunar-nexus-forge/agent-chaos-engineering"
9
+ authors:
10
+ - name: nunar-nexus-forge
11
+ keywords:
12
+ - chaos engineering
13
+ - self-healing systems
14
+ - multi-agent systems
15
+ - resilience
16
+ - adversarial robustness
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,6 @@
1
+ agent-chaos-engineering
2
+ Copyright 2026 nunar-nexus-forge
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
5
+ this software except in compliance with the License. You may obtain a copy of
6
+ the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -0,0 +1,305 @@
1
+ Metadata-Version: 2.5
2
+ Name: agent-chaos-engineering
3
+ Version: 0.1.0
4
+ Summary: Chaos engineering and self-healing recovery patterns for multi-agent LLM systems: inject hallucination loops, tool failures, cyclic dependencies and stale memory, then measure how the system degrades and recovers.
5
+ Project-URL: Homepage, https://github.com/nunar-nexus-forge/agent-chaos-engineering
6
+ Project-URL: Documentation, https://github.com/nunar-nexus-forge/agent-chaos-engineering/tree/main/docs
7
+ Project-URL: Changelog, https://github.com/nunar-nexus-forge/agent-chaos-engineering/blob/main/CHANGELOG.md
8
+ Project-URL: Issues, https://github.com/nunar-nexus-forge/agent-chaos-engineering/issues
9
+ Author: nunar-nexus-forge
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: adversarial,agent-chaos-engineering,agents,chaos-engineering,fault-injection,langgraph,llm,multi-agent,reliability,resilience,self-healing
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development :: Testing
22
+ Classifier: Topic :: System :: Monitoring
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.10
25
+ Provides-Extra: all
26
+ Requires-Dist: langchain-core>=0.3; extra == 'all'
27
+ Requires-Dist: langgraph>=0.2; extra == 'all'
28
+ Requires-Dist: pyyaml>=6.0; extra == 'all'
29
+ Provides-Extra: langgraph
30
+ Requires-Dist: langchain-core>=0.3; extra == 'langgraph'
31
+ Requires-Dist: langgraph>=0.2; extra == 'langgraph'
32
+ Provides-Extra: yaml
33
+ Requires-Dist: pyyaml>=6.0; extra == 'yaml'
34
+ Description-Content-Type: text/markdown
35
+
36
+ # agent-chaos-engineering
37
+
38
+ **Chaos engineering and self-healing recovery patterns for multi-agent LLM systems.**
39
+
40
+ [![CI](https://github.com/nunar-nexus-forge/agent-chaos-engineering/actions/workflows/ci.yml/badge.svg)](https://github.com/nunar-nexus-forge/agent-chaos-engineering/actions/workflows/ci.yml)
41
+ [![PyPI](https://img.shields.io/pypi/v/agent-chaos-engineering.svg)](https://pypi.org/project/agent-chaos-engineering/)
42
+ [![Python](https://img.shields.io/badge/python-3.10%2B-blue.svg)](pyproject.toml)
43
+ [![License](https://img.shields.io/badge/license-Apache--2.0-green.svg)](LICENSE)
44
+
45
+ *Chaos Monkey for AI agents.* Inject **hallucination loops, tool failures, network delays,
46
+ cyclic dependencies, stale memory, miscoordination** and **adversarial input perturbations**
47
+ into a LangGraph / LangChain / plain-Python agent system, watch it degrade, then ship the fix:
48
+ four **cognitive-layer recovery patterns** that detect and heal reasoning failures without
49
+ a human in the loop.
50
+
51
+ `agent-chaos-engineering` has two halves:
52
+
53
+ * **Self-healing** - the fault taxonomy, the anomaly detectors, the four recovery patterns
54
+ (semantic checkpointing, cognitive rollback, quarantine isolation, adaptive consensus
55
+ reset), the pattern-selection rules and the resilience scorecard;
56
+ * **Adversarial resilience** - resilience zones, redundant inference paths with
57
+ trust-weighted decision fusion, cross-path consistency checks, a supervisory control layer
58
+ with audit logging, and the adversarial fault kinds (input perturbation, data poisoning,
59
+ perception spoofing).
60
+
61
+ Nothing here needs an API key: the built-in simulation and every test run offline.
62
+
63
+ > **Naming:** the distribution is `agent-chaos-engineering`; the import is `import agent_chaos`
64
+ > and the CLI is `agent-chaos <command>`.
65
+
66
+ ---
67
+
68
+ ## Install
69
+
70
+ ```bash
71
+ pip install agent-chaos-engineering # pure Python, no dependencies
72
+ pip install 'agent-chaos-engineering[langgraph]' # + LangGraph / LangChain adapters
73
+ pip install agent-chaos-engineering multi-agent-observability # + log injections/recoveries into MA-Trace episodes (import ma_trace)
74
+ ```
75
+
76
+ ## 60-second tour
77
+
78
+ ### Break things
79
+
80
+ ```python
81
+ from agent_chaos import ChaosInjector, ChaosPlan
82
+
83
+ chaos = ChaosInjector(ChaosPlan.standard(seed=1), agents=["planner", "executor"])
84
+
85
+
86
+ @chaos.tool("search", agent="executor") # errors in 5 % of calls, 50-500 ms delays
87
+ def search(query: str) -> list[str]: ...
88
+
89
+
90
+ @chaos.reasoning_step("planner") # 3 % of outputs become hallucinations
91
+ def plan(goal: str) -> str: ...
92
+
93
+
94
+ delivery = chaos.message("planner", "executor", plan("ship it")) # may be dropped / rerouted / delayed
95
+ if delivery.delivered:
96
+ executor.handle(delivery.content)
97
+
98
+ memory = chaos.memory({}, agent="planner") # reads may return stale versions
99
+ observation = chaos.input("sensor", reading) # adversarial noise / spoofing
100
+
101
+ print(chaos.summary()) # every injection is logged for post-hoc analysis
102
+ ```
103
+
104
+ `ChaosPlan.standard()` is the standard operational-fault plan (network delays 50-500 ms,
105
+ tool errors in 5 % of calls, hallucination loops in 3 % of reasoning steps, cyclic
106
+ dependencies), distributed round-robin so every fault kind gets equal exposure. `ChaosPlan.adversarial()` adds input perturbation, data poisoning and
107
+ perception spoofing; `ChaosPlan.full()` has everything. Plans are plain JSON you can edit:
108
+ `agent-chaos plan --preset full -o plan.json`.
109
+
110
+ ### Heal them
111
+
112
+ ```python
113
+ from agent_chaos import SelfHealer, HealingConfig
114
+
115
+ healer = SelfHealer(
116
+ agents=["planner", "executor", "critic"],
117
+ dependencies={"executor": ["planner"], "critic": ["executor"]}, # who consumes whose output
118
+ config=HealingConfig(coherence_threshold=0.85, variance_sigma=1.5, min_consecutive=2),
119
+ )
120
+
121
+ # at decision points, when the state is known-good:
122
+ healer.checkpoint("planner", state, coherence=1.0)
123
+
124
+ # after every output:
125
+ signal, action = healer.heal(
126
+ "planner",
127
+ task="ticket-42",
128
+ output=answer,
129
+ constraints=[cites_sources, within_budget, no_contradiction], # -> semantic coherence
130
+ accuracy=0.9, # optional, drives consensus weights
131
+ )
132
+ if action and action.kind == "restore":
133
+ state = action.state # semantic checkpointing / cognitive rollback
134
+ if action and action.kind == "quarantine":
135
+ route_around(action.agents) # quarantine isolation
136
+ if action and action.kind == "reweight":
137
+ weights = action.weights # adaptive consensus reset
138
+ ```
139
+
140
+ Detection: an anomaly is raised when the agent's **reasoning
141
+ variance** from its peers exceeds `mean + 1.5σ` of its own history **or** its **semantic
142
+ coherence** (constraints satisfied / total) drops below `0.85`, and *confirmed* only after
143
+ `min_consecutive` consecutive observations. Recovery selection first applies each pattern's
144
+ matching criteria, then minimises
145
+ `recovery_time + w_impact · affected_agents + w_accuracy · (1 − accuracy_retention)`:
146
+
147
+ | pattern | when it matches | what it does |
148
+ |---|---|---|
149
+ | semantic checkpointing | failure < 5 s, one agent affected, coherence drop < 15 % | restore the last checkpoint whose coherence ≥ threshold |
150
+ | cognitive rollback | failure > 5 s, propagation depth > 2, checkpoint validity ≥ 0.90 | restore `argmax(coherence − λ·age)` for every degraded agent |
151
+ | quarantine isolation | > 1 agent affected, cascading risk > 0.70, system can run degraded | detach degraded agents, route around them, re-admit after probation |
152
+ | adaptive consensus reset | several agents degraded, variance > 2σ, alternatives available | `w_i ← w_i · (1 + α (accuracy_i − 0.85))`, so reliable agents gain influence |
153
+
154
+ Every incident records its context, the chosen pattern, the alternatives with their costs,
155
+ and the measured recovery latency (`healer.report()`).
156
+
157
+ ### Measure
158
+
159
+ ```python
160
+ from agent_chaos import ScenarioRunner, ChaosPlan
161
+ from agent_chaos.sim import pipeline_scenario # or your own scenario function
162
+
163
+ result = ScenarioRunner(pipeline_scenario, plan=ChaosPlan.standard(), episodes=30, seed=1).run()
164
+ print(result.scorecard.to_markdown())
165
+ ```
166
+
167
+ ```
168
+ | metric | baseline | chaos | healed |
169
+ |---|---|---|---|
170
+ | task success (accuracy) | 100.0% | 63.3% | 86.7% |
171
+ | recovery latency (s) | n/a | 2.10 | 1.25 |
172
+ | cross-agent failure rate | 0.0% | 9.2% | 3.8% |
173
+ | decision integrity | 100.0% | 82.5% | 94.6% |
174
+ ...
175
+ | recovery latency improvement (RLI) | 40.5% |
176
+ | cross-agent failure rate improvement (CAFRI) | 58.7% |
177
+ | accuracy retention improvement (ARI) | 36.8% |
178
+ | composite reliability | 45.3% |
179
+ ```
180
+
181
+ (Illustrative numbers from the bundled simulation; run it yourself with
182
+ `agent-chaos run --episodes 30`.) The runner executes three *arms* with identical seeds -
183
+ **baseline** (no chaos), **chaos** and **healed** (chaos + `SelfHealer`) - and reports task
184
+ success, accuracy retention, recovery latency, cross-agent failure rate (CAFR), recovery
185
+ success per fault kind, decision integrity, availability and compute overhead, plus the
186
+ improvement metrics **RLI**, **CAFRI**, **ARI** and the weighted composite.
187
+
188
+ Your own scenario is a function `f(ctx: ScenarioContext) -> ScenarioOutcome` that runs one
189
+ episode using `ctx.chaos` (the injector), `ctx.healer` (`None` on non-healed arms),
190
+ `ctx.rng` and `ctx.clock` (virtual time, so injected delays cost nothing real). See
191
+ `src/agent_chaos/sim.py` for a complete example.
192
+
193
+ ## Adversarial resilience
194
+
195
+ ```python
196
+ from agent_chaos import ResilienceZone, ZoneSupervisor, TrustWeightedDecision
197
+
198
+ # resilience zones: isolate the zone where an anomaly is confirmed, restore its local checkpoint,
199
+ # block dangerous actions while it is isolated, keep an audit log
200
+ zones = [ResilienceZone("perception", ["camera"]), ResilienceZone("inference", ["model_a", "model_b"])]
201
+ supervisor = ZoneSupervisor(zones, dangerous_actions={"brake_release"})
202
+ action = supervisor.observe(
203
+ "model_a", task="frame-17", output=score, coherence=0.4
204
+ ) # -> isolate / restore / release
205
+ allowed = supervisor.allow("model_a", "brake_release")
206
+
207
+ # redundant inference paths + trust-weighted decision fusion + cross-path consistency
208
+ fusion = TrustWeightedDecision(["path_a", "path_b", "path_c"], discrepancy_threshold=0.5)
209
+ decision = fusion.decide(
210
+ {"path_a": 0.81, "path_b": 0.79, "path_c": 0.05}
211
+ ) # path_c suppressed, flagged adversarial
212
+ fusion.feedback(truth=0.8, outputs=...) # trust weights learn
213
+ ```
214
+
215
+ The adversarial fault kinds (`InputPerturbation`, `DataPoisoning`, `PerceptionSpoofing`)
216
+ let you run a DevSecOps-style loop: inject, detect, patch, re-run.
217
+
218
+ ## LangGraph
219
+
220
+ ```python
221
+ from langgraph.checkpoint.memory import InMemorySaver
222
+
223
+ from agent_chaos.adapters.langgraph import chaos_node, heal_node, SelfHealingCheckpointSaver
224
+
225
+ builder.add_node("planner", chaos_node(planner, chaos)) # inject into a node
226
+ builder.add_node(
227
+ "writer", heal_node(writer, healer, coherence=score_update)
228
+ ) # checkpoint / detect / restore a node
229
+
230
+ saver = SelfHealingCheckpointSaver(InMemorySaver(), coherence=score_state) # any checkpointer
231
+ graph = builder.compile(checkpointer=saver)
232
+ ...
233
+ if saver.needs_rollback(thread_id):
234
+ graph.invoke(None, config=saver.best_valid_config(thread_id)) # resume from the best valid checkpoint
235
+ ```
236
+
237
+ `SelfHealingCheckpointSaver` wraps any LangGraph checkpointer (memory, SQLite, Postgres),
238
+ tags each checkpoint with a coherence score computed from the state, and finds the
239
+ checkpoint maximising `coherence − λ · age` - LangGraph time travel with a semantic
240
+ validity criterion. For LangChain tools use `agent_chaos.adapters.langchain.chaos_tool`.
241
+
242
+ ## CLI
243
+
244
+ ```
245
+ agent-chaos faults # the taxonomy with surfaces and default rates
246
+ agent-chaos presets # standard / adversarial / full plans
247
+ agent-chaos plan --preset full -o plan.json
248
+ agent-chaos run [--scenario pkg.mod:fn] [--preset standard|--plan plan.json] [--episodes 30] [--seed 1] [--json results.json]
249
+ agent-chaos report results.json
250
+ ```
251
+
252
+ ## Architecture
253
+
254
+ ```mermaid
255
+ flowchart LR
256
+ subgraph inject["chaos (fault injection)"]
257
+ P[ChaosPlan<br/>faults · schedule · seed] --> I[ChaosInjector]
258
+ I -->|tool| T[tool calls]
259
+ I -->|reasoning| R[reasoning steps]
260
+ I -->|message| M[messages]
261
+ I -->|memory| ME[memory reads]
262
+ I -->|input| IN[observations]
263
+ end
264
+ subgraph heal["self-healing (resilience layer)"]
265
+ D[AnomalyDetector<br/>variance · coherence · temporal filter] --> S[PatternSelector<br/>criteria + cost]
266
+ S --> SC[semantic checkpointing]
267
+ S --> CR[cognitive rollback]
268
+ S --> QI[quarantine isolation]
269
+ S --> ACR[adaptive consensus reset]
270
+ CP[(CheckpointStore)] --- SC
271
+ CP --- CR
272
+ end
273
+ T & R & M & ME & IN --> APP[your agents] --> D
274
+ APP --> SR[ScenarioRunner<br/>baseline · chaos · healed] --> SCD[Scorecard<br/>RLI · CAFRI · ARI]
275
+ ```
276
+
277
+ ## Scope
278
+
279
+ The bundled simulation (`agent_chaos.sim`) is a harness for exercising the mechanics, not a
280
+ benchmark: the scorecard numbers it produces are its own, and the library makes no claims
281
+ about your system until you run your own scenario through it. Longer documents live in
282
+ `docs/`: [recovery-patterns.md](docs/recovery-patterns.md) (selection inputs and what each
283
+ pattern returns) and [scorecard.md](docs/scorecard.md) (every metric, and how to write a
284
+ scenario). To cite the software, use [CITATION.cff](CITATION.cff).
285
+
286
+ ## Companion projects
287
+
288
+ - [`multi-agent-observability`](https://github.com/nunar-nexus-forge/multi-agent-observability) - causal tracing, coordination SLOs and deterministic replay (install both and call `agent_chaos.adapters.ma_trace.bind_ma_trace` to log every injection and recovery into the current episode).
289
+ - [`agent-tool-guardrails`](https://github.com/nunar-nexus-forge/agent-tool-guardrails) - policy contracts for agent-tool calls with a tamper-evident evidence store and an MCP proxy.
290
+
291
+ ## Contributing
292
+
293
+ See [CONTRIBUTING.md](CONTRIBUTING.md). Most wanted: new fault kinds (prompt injection,
294
+ token-budget exhaustion, schema drift), adapters (CrewAI, AutoGen, OpenAI Agents SDK), and
295
+ real-world scenarios for the runner.
296
+
297
+ ```bash
298
+ git clone https://github.com/nunar-nexus-forge/agent-chaos-engineering && cd agent-chaos-engineering
299
+ make sync && make check # everything lives in ./.venv
300
+ python examples/demo_pipeline.py
301
+ ```
302
+
303
+ ## License
304
+
305
+ Apache License 2.0 - see [LICENSE](LICENSE) and [NOTICE](NOTICE).