stigmergic 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.
- stigmergic-0.1.0/LICENSE +201 -0
- stigmergic-0.1.0/PKG-INFO +342 -0
- stigmergic-0.1.0/README.md +301 -0
- stigmergic-0.1.0/pyproject.toml +89 -0
- stigmergic-0.1.0/setup.cfg +4 -0
- stigmergic-0.1.0/src/stigmergic/__init__.py +56 -0
- stigmergic-0.1.0/src/stigmergic/agents/__init__.py +18 -0
- stigmergic-0.1.0/src/stigmergic/agents/base_ant.py +388 -0
- stigmergic-0.1.0/src/stigmergic/agents/concrete.py +236 -0
- stigmergic-0.1.0/src/stigmergic/agents/hybrid_ant.py +242 -0
- stigmergic-0.1.0/src/stigmergic/agents/verifier_ant.py +125 -0
- stigmergic-0.1.0/src/stigmergic/core/__init__.py +34 -0
- stigmergic-0.1.0/src/stigmergic/core/backends/__init__.py +104 -0
- stigmergic-0.1.0/src/stigmergic/core/backends/postgres.py +606 -0
- stigmergic-0.1.0/src/stigmergic/core/consensus.py +569 -0
- stigmergic-0.1.0/src/stigmergic/core/environment.py +1086 -0
- stigmergic-0.1.0/src/stigmergic/core/latent_transfer.py +139 -0
- stigmergic-0.1.0/src/stigmergic/core/observability.py +246 -0
- stigmergic-0.1.0/src/stigmergic.egg-info/PKG-INFO +342 -0
- stigmergic-0.1.0/src/stigmergic.egg-info/SOURCES.txt +26 -0
- stigmergic-0.1.0/src/stigmergic.egg-info/dependency_links.txt +1 -0
- stigmergic-0.1.0/src/stigmergic.egg-info/requires.txt +20 -0
- stigmergic-0.1.0/src/stigmergic.egg-info/top_level.txt +1 -0
- stigmergic-0.1.0/tests/test_benchmark.py +488 -0
- stigmergic-0.1.0/tests/test_consensus.py +455 -0
- stigmergic-0.1.0/tests/test_ground.py +529 -0
- stigmergic-0.1.0/tests/test_observability.py +172 -0
- stigmergic-0.1.0/tests/test_servicenow_hr.py +747 -0
stigmergic-0.1.0/LICENSE
ADDED
|
@@ -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 2026 Emmanuel Esperança
|
|
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,342 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: stigmergic
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A near-zero-dependency, fault-tolerant multi-agent framework built on Stigmergy, Latent State Transfer, and a Byzantine-inspired consensus quorum.
|
|
5
|
+
Author: Stigmergic Contributors
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/emmanuelesperanca/stigmergic
|
|
8
|
+
Project-URL: Repository, https://github.com/emmanuelesperanca/stigmergic
|
|
9
|
+
Project-URL: Documentation, https://github.com/emmanuelesperanca/stigmergic/blob/main/ARCHITECTURE.md
|
|
10
|
+
Project-URL: Issues, https://github.com/emmanuelesperanca/stigmergic/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/emmanuelesperanca/stigmergic/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: multi-agent,stigmergy,swarm-intelligence,byzantine-fault-tolerance,latent-state-transfer,eventual-consistency
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: pydantic>=2.0
|
|
26
|
+
Provides-Extra: cognition
|
|
27
|
+
Requires-Dist: torch>=2.0; extra == "cognition"
|
|
28
|
+
Requires-Dist: transformers>=4.40; extra == "cognition"
|
|
29
|
+
Requires-Dist: sentencepiece>=0.1.99; extra == "cognition"
|
|
30
|
+
Requires-Dist: protobuf>=3.20; extra == "cognition"
|
|
31
|
+
Provides-Extra: postgres
|
|
32
|
+
Requires-Dist: psycopg[binary]>=3.2; extra == "postgres"
|
|
33
|
+
Provides-Extra: benchmark
|
|
34
|
+
Requires-Dist: openai>=1.0; extra == "benchmark"
|
|
35
|
+
Provides-Extra: baselines
|
|
36
|
+
Requires-Dist: guardrails-ai>=0.5; extra == "baselines"
|
|
37
|
+
Requires-Dist: nemoguardrails>=0.9; extra == "baselines"
|
|
38
|
+
Provides-Extra: dev
|
|
39
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
40
|
+
Dynamic: license-file
|
|
41
|
+
|
|
42
|
+
# 🐜 Stigmergic
|
|
43
|
+
|
|
44
|
+
[](https://www.python.org/downloads/)
|
|
45
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
46
|
+
[](https://GitHub.com/Naereen/StrapDown.js/graphs/commit-activity)
|
|
47
|
+
|
|
48
|
+
> **A near-zero-dependency, fault-tolerant multi-agent framework built on Stigmergy, Latent State Transfer, and a Byzantine-inspired consensus quorum.**
|
|
49
|
+
>
|
|
50
|
+
> *The decomposer layer for **operational entropy** — the endless rain of tickets, invoices, and alerts that traditional automation can't keep up with.*
|
|
51
|
+
|
|
52
|
+
Forget API chaining, central orchestrators, and fragile `Agent-A → Agent-B` string-passing. **Stigmergic** reimagines Multi-Agent Systems (MAS) not as corporate org charts, but as **living ecosystems**.
|
|
53
|
+
|
|
54
|
+
Nature solved distributed computing 500 million years before we invented the CPU. Ant colonies coordinate thousands of workers with no manager. Your immune system runs a planet-scale security audit with no central firewall. Your neurons exchange thought without ever flattening it into words. **Stigmergic is a shameless plagiarism of that biology** — three battle-tested survival strategies, ported into a framework for LLM agents.
|
|
55
|
+
|
|
56
|
+
If LangGraph is a rigid assembly line, Stigmergic is an ant colony: decentralized, self-healing, and consensus-guarded against hallucination and prompt injection.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## 🩻 The Disease We're Curing
|
|
61
|
+
|
|
62
|
+
Today's orchestration frameworks suffer from two chronic conditions:
|
|
63
|
+
|
|
64
|
+
- **The String Tax 💸** — agents think in rich, high-dimensional latent space, then are forced to flatten that thought into lossy text just to talk to the next agent. It is brain damage by serialization.
|
|
65
|
+
- **Centralized Fragility 🥀** — a supervisor node holds the whole graph in memory. The supervisor dies, the organism dies with it. No ant colony ever collapsed because the "manager ant" had a heart attack.
|
|
66
|
+
|
|
67
|
+
Biology never made these mistakes. Neither should your agents.
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## 🌳 Forest-Floor Problems
|
|
72
|
+
|
|
73
|
+
> *Where Stigmergic earns its keep.*
|
|
74
|
+
|
|
75
|
+
Walk into any enterprise and you'll find a **forest floor**: an endless rain of events — support tickets, invoices, fraud alerts, SAP exceptions, security alarms, insurance claims — falling faster than humans (or traditional automation) can clear them. Leaves never stop dropping. There is no "end of project," only a steady state of decay that must be continuously digested.
|
|
76
|
+
|
|
77
|
+
Nature has a name for the layer that handles exactly this: **decomposers**. Stigmergic is the decomposer layer for your **operational entropy** — a swarm that digests the chaos into resolved, *audited* order, continuously, and never loses a leaf even when the systems above it crash.
|
|
78
|
+
|
|
79
|
+
We call this category **Operational Entropy Management**, and it is not a metaphor: the framework literally measures `global_entropy()` and drives it toward zero, while the `SwarmInspector` charts the decay in real time.
|
|
80
|
+
|
|
81
|
+
**A problem belongs on the forest floor when it has these seven traits:**
|
|
82
|
+
|
|
83
|
+
1. **A stable, queryable "ground"** — a base of truth (knowledge base, reimbursement policy, ERP state, ledger).
|
|
84
|
+
2. **A continuous, unpredictable arrival of events** — in bursts, with no natural end.
|
|
85
|
+
3. **Each event needs *judgment* against the ground** — reasoning + retrieval, not a CRUD write.
|
|
86
|
+
4. **Actions are consequential** — getting it wrong is expensive, so *verifying before acting* has real value.
|
|
87
|
+
5. **The work is decomposable and parallelizable** — many independent units.
|
|
88
|
+
6. **Eventual consistency is acceptable** — you need durable and resilient, not synchronous-transactional-now.
|
|
89
|
+
7. **Volume/bursts break synchronous orchestration** — which is exactly where the swarm beats the pipeline.
|
|
90
|
+
|
|
91
|
+
> In one line: **"work that never stops arriving, must be judged against the rules, and can be neither lost nor executed blindly."**
|
|
92
|
+
|
|
93
|
+
### Where it fits
|
|
94
|
+
|
|
95
|
+
| Vertical | The endless rain | Horizon that shines |
|
|
96
|
+
| :--- | :--- | :--- |
|
|
97
|
+
| **IT service desk** | Tickets vs. KBs & past resolutions | 🐜 H1 durability + 🛡️ H2 verify-before-human |
|
|
98
|
+
| **Continuous compliance & fraud** | Invoices/expenses vs. reimbursement policy | 🛡️ H2 — the auditable jury *is* the control |
|
|
99
|
+
| **Supply-chain self-healing** | 2,000 SAP delay alerts at once | 🐜 H1 — SAP dies, state freezes, swarm resumes |
|
|
100
|
+
| **SOC / alert triage** | SIEM alerts vs. threat intel & runbooks | 🛡️ H2 — don't close a real breach or escalate noise |
|
|
101
|
+
| **Claims adjudication** | Insurance/health claims vs. policy | 🛡️ H2 + durable audit trail |
|
|
102
|
+
| **Trust & Safety** | Moderation queue vs. policy | 🛡️ H2 heterogeneous jury as appeals bench |
|
|
103
|
+
| **Pharmacovigilance (MDR)** | Adverse-event reports vs. safety base | 🐜 H1 + 🛡️ H2, deadline-driven |
|
|
104
|
+
|
|
105
|
+
> **The framework is general; the go-to-market is one beachhead.** The architecture is domain-agnostic — but a serious deployment proves *one* vertical first. The forest is vast; you start by clearing one clearing.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## 🧠 The Three Architectural Horizons
|
|
110
|
+
|
|
111
|
+
Each horizon is a capability lifted straight from a living system.
|
|
112
|
+
|
|
113
|
+
### 🐜 Horizon 1 — Stigmergic Swarms · *The Ant Colony*
|
|
114
|
+
|
|
115
|
+
**The biology.** A single ant cannot comprehend the anthill's blueprint, and there is no "CEO ant" barking orders. Coordination emerges through **stigmergy**: an ant finds food, carries a piece home, and lays a chemical trail (a pheromone) on the ground. Another ant — with zero knowledge of the first — smells the trail, follows it, and reinforces it. When the food runs out, the pheromone evaporates and the traffic stops. The environment *is* the algorithm.
|
|
116
|
+
|
|
117
|
+
**The framework.** Agents here **never call each other**. They only read and mutate a shared semantic field — a **pluggable ground** that plays the role of the forest floor. It ships with SQLite (zero-config, in-process) and **PostgreSQL** — lock-free `SELECT … FOR UPDATE SKIP LOCKED` claims plus `LISTEN/NOTIFY` push — with Redis and DynamoDB on the roadmap. Swap the substrate in one line, `create_ground("postgresql://…")`, and the ants never notice.
|
|
118
|
+
|
|
119
|
+
| Biology | Stigmergic |
|
|
120
|
+
| :--- | :--- |
|
|
121
|
+
| The forest floor | `PheromoneGround` (the shared DB) |
|
|
122
|
+
| Pheromone concentration | `Entropy` (`CHAOS=1.0 … ZERO=0.0`) |
|
|
123
|
+
| The trail's scent | `Status` (`RAW → HYGIENIZED → RESOLVED`) |
|
|
124
|
+
| The pheromone evaporating | An ant setting `Entropy.ZERO` |
|
|
125
|
+
| A colony surviving a dead ant | A killed thread; the task stays durable in the DB |
|
|
126
|
+
|
|
127
|
+
> **Zero coupling, durable resilience.** An ant wakes, senses high entropy (unresolved work), acts, lowers the entropy, and sleeps. Kill the process and the work simply waits in the database for the swarm to resume — eventual consistency with no orchestrator. (This is the Chaos Monkey test below.)
|
|
128
|
+
>
|
|
129
|
+
> The swarm is **event-driven**: ants idle at *zero CPU* and wake the instant the ground changes — no busy-polling — and every mutation is observable through the **`SwarmInspector`**, a flight recorder that replays any pheromone's life and charts field entropy over time.
|
|
130
|
+
>
|
|
131
|
+
> **Production reliability.** The ground is more than a queue. A **work-lease** returns a crashed worker's task to the pool (`reclaim_expired_leases`); **optimistic concurrency** (a `version` compare-and-swap) rejects a stale write from a reclaimed worker; an **idempotency key** stops a re-delivered event creating duplicate work; a **dead-letter** state (`DEAD_LETTER`) parks a poison-pill after a bounded number of retries; and an opt-in **formal state machine** (`enforce_transitions`) rejects any illegal lifecycle hop. Each is a flag on the ground — no ant changes.
|
|
132
|
+
|
|
133
|
+
### 🛡️ Horizon 2 — Byzantine Cognitive Consensus · *The Immune System*
|
|
134
|
+
|
|
135
|
+
**The biology.** Your body does not ask the brain for permission to fight a virus. When an antigen enters the bloodstream, white blood cells detect it by molecular pattern-matching and destroy it on the spot. And crucially it is a *quorum*, not a dictator — when the immune system hallucinates and a lone cell misfires, healthy tissue gets attacked (autoimmune disease). Robustness comes from many independent sentinels having to agree.
|
|
136
|
+
|
|
137
|
+
**The framework.** You would not trust a single microservice to silently mutate production state — so why trust a single LLM? Before any mutation is committed, it must survive a **Byzantine Quorum**. The `VerifierAnt` is your white blood cell; a prompt injection (`drop table`, `ignore previous instructions`) or an LLM hallucination is the antigen.
|
|
138
|
+
|
|
139
|
+
| Biology | Stigmergic |
|
|
140
|
+
| :--- | :--- |
|
|
141
|
+
| Antigen / pathogen | Prompt injection or hallucination |
|
|
142
|
+
| White blood cell | `VerifierAnt` |
|
|
143
|
+
| The immune response (a quorum of cells) | `SemanticRaft` (a jury of NLI judges) |
|
|
144
|
+
| Quarantine before the verdict | `Status.PENDING_CONSENSUS` |
|
|
145
|
+
| Pathogen neutralized | `Status.SLASHED` |
|
|
146
|
+
| All-clear, tissue healthy | `Status.RESOLVED` |
|
|
147
|
+
|
|
148
|
+
> A proposal is quarantined at `PENDING_CONSENSUS`. A jury of independent nodes each asks, in its own words, *"does this action actually follow from the original request?"* The jury can be genuinely **heterogeneous** — a fast `RuleBasedJudge`, a local NLI cross-encoder, and a provider-agnostic `LLMJudge` — so the voters fail for *uncorrelated* reasons, exactly like independent immune cells. If fewer than the threshold agree, the transaction is **slashed** and the poisoned trail evaporates so no other ant ever follows it. The vital organ (your ERP/SAP) is protected without ever consulting the user.
|
|
149
|
+
|
|
150
|
+
### 🧠 Horizon 3 — Latent State Transfer · *The Neural Synapse*
|
|
151
|
+
|
|
152
|
+
**The biology.** Neurons do not email each other sentences in English. The visual cortex does not send the amygdala the *text* "this is a lion" — it fires an electrochemical pulse, pure mathematical information, and the brain reacts in milliseconds. Forcing thought through language would mean saying every idea out loud before you could think the next one.
|
|
153
|
+
|
|
154
|
+
**The framework.** Instead of compressing reasoning into a string, agents pass the **hidden activation tensor itself**. A Reader distills a heavy document into a last-layer hidden state `[1, seq_len, hidden_dim]`, parks that tensor in the pheromone's `latent_blob`, and *erases the text*. A downstream agent injects the tensor straight into its own residual stream — pure context, zero String Tax.
|
|
155
|
+
|
|
156
|
+
| Biology | Stigmergic |
|
|
157
|
+
| :--- | :--- |
|
|
158
|
+
| Electrochemical pulse | The serialized hidden-state tensor |
|
|
159
|
+
| Synaptic transmission | `latent_blob` on the `LATENT_READY` trail |
|
|
160
|
+
| Speaking out loud (lossy) | Classic string-based agent RPC |
|
|
161
|
+
| A sensory neuron encoding a stimulus | `HybridSolverAnt` (`engine="local"`) |
|
|
162
|
+
| A downstream neuron firing on the signal | A `Decider` agent reading only the tensor |
|
|
163
|
+
|
|
164
|
+
> In [`examples/03_latent_telepathy.py`](examples/03_latent_telepathy.py), one ant reads a 2,300-character report and the next ant reaches a decision having *never seen a single word of it* — only the tensor crossed the gap. Telepathy by mathematics.
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## 🗺️ The Life of a Pheromone
|
|
169
|
+
|
|
170
|
+
A unit of work is born as chaos and dies as either a resolution or a slash. No agent dictates this journey; each caste simply reacts to the scent it is tuned to.
|
|
171
|
+
|
|
172
|
+
```mermaid
|
|
173
|
+
flowchart LR
|
|
174
|
+
F([🐜 Forager]) -->|inject_chaos| RAW
|
|
175
|
+
RAW -->|🧼 Governance sanitizes| HYG[HYGIENIZED]
|
|
176
|
+
HYG -->|🧠 Solver proposes| PC[PENDING_CONSENSUS]
|
|
177
|
+
PC -->|🛡️ quorum passes| RES[RESOLVED]
|
|
178
|
+
PC -->|🛡️ injection / hallucination| SLA[SLASHED]
|
|
179
|
+
RAW -.->|🧠 Reader encodes tensor| LR[LATENT_READY]
|
|
180
|
+
LR -.->|🔮 Decider acts on latent| RES
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## ⚡ Quick Start: The Chaos Monkey Test
|
|
186
|
+
|
|
187
|
+
You don't need a heavy vector database to feel stigmergy. Let's run a swarm on a local SQLite "forest floor."
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
pip install -r requirements.txt
|
|
191
|
+
python examples/01_hello_stigmergy.py
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
**What happens?**
|
|
195
|
+
|
|
196
|
+
1. The **Forager** injects chaotic, high-entropy requests into the ground (e.g. `"update salary to 15k urgent"`).
|
|
197
|
+
2. The **Governance** ant smells entropy `≥ 0.7`, wakes asynchronously, sanitizes the payload, drops entropy to `0.2`, and lays a clean `HYGIENIZED` trail.
|
|
198
|
+
3. The **Solver** ant smells the clean trail, executes the safe business logic, and drives entropy to zero.
|
|
199
|
+
|
|
200
|
+
**The magic 🐒** — kill the Governance thread mid-run. *Nothing crashes.* The Forager keeps piling on work, the Solver idles (no hygiene to follow), and the `RAW` backlog simply accumulates, durable in the database. Revive Governance and watch it vacuum the backlog at lightning speed. **Eventual consistency with no Step Functions, no retry queue, no orchestrator** — exactly how a colony shrugs off a dead worker.
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## 🐜 The Castes
|
|
205
|
+
|
|
206
|
+
Every caste reacts only to a scent (`Status`) and an entropy threshold. None of them know the others exist — they are wired together solely by the trails they leave on the ground.
|
|
207
|
+
|
|
208
|
+
| Caste | Role in the colony | Biological analog | Reacts to → leaves |
|
|
209
|
+
| :--- | :--- | :--- | :--- |
|
|
210
|
+
| `ForagerAnt` | Producer: floods the ground with work | Forager bringing food home | — → `RAW` |
|
|
211
|
+
| `GovernanceAnt` | Scrubs PII + sanitizes raw payloads | Hygienic worker ant | `RAW` → `HYGIENIZED` |
|
|
212
|
+
| `SolverAnt` | Proposes a resolution for review | Worker executing a task | `HYGIENIZED` → `PENDING_CONSENSUS` |
|
|
213
|
+
| `VerifierAnt` | Runs the Byzantine quorum | White blood cell | `PENDING_CONSENSUS` → `RESOLVED` / `SLASHED` |
|
|
214
|
+
| `HybridSolverAnt` | Cloud text **or** local latent encoding | Sensory neuron | `HYGIENIZED`/`RAW` → `PENDING_CONSENSUS` / `LATENT_READY` |
|
|
215
|
+
|
|
216
|
+
> Castes are built by composition over a resilient `BaseAnt` heartbeat: a `ProducerAnt` secretes, a `ConsumerAnt` claims → metabolizes → commits. A failed `tick()` is logged and swallowed — one sick ant never kills the colony.
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## 📦 Installation
|
|
221
|
+
|
|
222
|
+
Stigmergic keeps a **near-zero-dependency** core (just `pydantic`). The deep-learning horizons are strictly opt-in, so `import stigmergic` never pays the torch/transformers import tax.
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
# Horizon 1 — the stigmergic core (pydantic only)
|
|
226
|
+
pip install -r requirements.txt
|
|
227
|
+
|
|
228
|
+
# Optional — a production PostgreSQL ground (SKIP LOCKED + LISTEN/NOTIFY)
|
|
229
|
+
pip install -e ".[postgres]"
|
|
230
|
+
|
|
231
|
+
# Horizons 2 & 3 — the cognition extras (torch + transformers)
|
|
232
|
+
pip install -e ".[cognition]"
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
> Requires **Python 3.10+**. Horizons 2 and 3 run fully offline in the examples and tests via deterministic mocks, so you can explore the entire architecture before downloading a single model weight.
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## 🔬 Examples
|
|
240
|
+
|
|
241
|
+
| Demo | Horizon | What it proves |
|
|
242
|
+
| :--- | :--- | :--- |
|
|
243
|
+
| [`01_hello_stigmergy.py`](examples/01_hello_stigmergy.py) | 🐜 Swarms | Self-healing coordination — kill & revive a caste, lose zero tasks |
|
|
244
|
+
| [`02_byzantine_fault.py`](examples/02_byzantine_fault.py) | 🛡️ Consensus | A live jury slashing prompt injections while approving honest work |
|
|
245
|
+
| [`03_latent_telepathy.py`](examples/03_latent_telepathy.py) | 🧠 Latent | A decision made from a raw tensor — the source text never crossed |
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
python examples/02_byzantine_fault.py # watch the immune system slash a hack
|
|
249
|
+
python examples/03_latent_telepathy.py # watch one ant read another's mind
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
## 🧪 Testing
|
|
255
|
+
|
|
256
|
+
The whole suite is fully deterministic and **torch-free** (every juror is a `MockNLIJudge` or `RuleBasedJudge`), so it runs in a fraction of a second and proves the import hygiene holds.
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
pip install pytest
|
|
260
|
+
python -m pytest -q
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
> **158 tests**, torch-free and sub-second (8 are gated on the optional Postgres/cognition extras and skip by default), span five suites: `test_consensus.py` (quorum arithmetic — 2-of-3 passes, 1-of-3 slashes — red-flag slashing, crashing-juror resilience, heterogeneous panels), `test_ground.py` (event emission, event-driven wake, the pluggable-backend factory, SQL-injection-safe identifiers, and the **reliability core**: work-leases + reclaim, optimistic-concurrency CAS, idempotency, and the dead-letter queue), `test_observability.py` (lifecycle, entropy sparkline, replay, JSONL sink), `test_benchmark.py` (injection-capture metrics, Wilson confidence intervals, and the Byzantine experiment), and `test_servicenow_hr.py` (the end-to-end ServiceNow HR demo — learning, self-healing, PII scrubbing, injection defense). Import hygiene is asserted: no `torch`, `transformers`, or `psycopg` ever leaks into a core run.
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
## 🗂️ Project Structure
|
|
268
|
+
|
|
269
|
+
```text
|
|
270
|
+
src/stigmergic/
|
|
271
|
+
├── core/
|
|
272
|
+
│ ├── environment.py # 🐜 PheromoneGround, AbstractGround, EventSignal — the forest floor
|
|
273
|
+
│ ├── backends/ # 🔌 pluggable grounds: create_ground() · PostgresGround (LISTEN/NOTIFY)
|
|
274
|
+
│ ├── consensus.py # 🛡️ SemanticRaft, NLI/rule/LLM judges — the immune system
|
|
275
|
+
│ ├── observability.py # 🔭 SwarmInspector — the flight recorder (lifecycle, entropy, replay)
|
|
276
|
+
│ └── latent_transfer.py # 🧠 tensor (de)serialization — the synapse
|
|
277
|
+
└── agents/
|
|
278
|
+
├── base_ant.py # BaseAnt heartbeat · ConsumerAnt (event-driven) · ProducerAnt
|
|
279
|
+
├── concrete.py # ForagerAnt · GovernanceAnt · SolverAnt
|
|
280
|
+
├── verifier_ant.py # VerifierAnt (the white blood cell)
|
|
281
|
+
└── hybrid_ant.py # HybridSolverAnt (cloud text / local latent)
|
|
282
|
+
examples/ # runnable horizon demos
|
|
283
|
+
demos/ # end-to-end showcase: servicenow_hr (learn · self-heal · scrub PII · resist injection)
|
|
284
|
+
tests/ # torch-free suites: consensus · ground (+ reliability) · observability · benchmark · servicenow_hr
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
## 📊 Standards & Benchmarks
|
|
290
|
+
|
|
291
|
+
Stigmergic targets a security-sensitive category, so it is designed to be *measured against recognized standards* rather than to rest on self-asserted claims.
|
|
292
|
+
|
|
293
|
+
**Threat model — mapped to the [OWASP Top 10 for LLM Applications](https://owasp.org/www-project-top-10-for-large-language-model-applications/).** The Byzantine quorum directly targets `LLM01: Prompt Injection` and `LLM09: Overreliance` (hallucination): no single model commits state, and every verdict carries a durable, replayable audit record (`ConsensusVerdict`). The full mapping — every OWASP risk to the control that answers it, plus the honest limitations — is in [`THREAT_MODEL.md`](THREAT_MODEL.md).
|
|
294
|
+
|
|
295
|
+
**Benchmark methodology.** Two layers: a reproducible **internal harness** that measures the quorum directly, plus the public suites the field already trusts for external validation.
|
|
296
|
+
|
|
297
|
+
| Dimension | Yardstick | Status |
|
|
298
|
+
| :--- | :--- | :--- |
|
|
299
|
+
| Prompt-injection capture (internal) | OWASP `LLM01` · [`benchmarks/injection_capture`](benchmarks/injection_capture/RESULTS.md) | ✅ measured (torch-free) |
|
|
300
|
+
| Byzantine robustness (internal) | consensus under a faulty juror · [`BYZANTINE.md`](benchmarks/injection_capture/BYZANTINE.md) | ✅ measured (torch-free) |
|
|
301
|
+
| Baseline comparison (external tools) | Guardrails AI · NeMo Guardrails · [`baselines.py`](benchmarks/injection_capture/baselines.py) | 🔌 adapter ready (`run.py --baselines`) |
|
|
302
|
+
| Prompt-injection capture (external) | [AgentDojo](https://github.com/ethz-spylab/agentdojo), [InjecAgent](https://github.com/uiuc-kang-lab/InjecAgent) | 🚧 planned |
|
|
303
|
+
| Answer faithfulness (RAG) | [RAGAS](https://github.com/explodinggradients/ragas) | 🚧 planned |
|
|
304
|
+
| Throughput & self-healing | event-driven vs. polling · Chaos-Monkey drain | ✅ demonstrated in examples |
|
|
305
|
+
|
|
306
|
+
**Internal result (reproducible, torch-free).** On a hardened, adversarial 116-case corpus, the relational quorum lifts prompt-injection **capture from 45% (a keyword denylist) to 82% — at the *same* false-positive rate** — catching the keywordless paraphrased and indirect attacks the denylist waves through. Reproduce it with `python benchmarks/injection_capture/run.py`. The residual false-positive gap is adversarial-benign text — legitimate runbooks that merely *mention* `drop table` — which by design make up half the benign set; full breakdown in [`RESULTS.md`](benchmarks/injection_capture/RESULTS.md).
|
|
307
|
+
|
|
308
|
+
**A real model is not enough — consensus is (measured with `--nli`).** Swapping in a real cross-encoder NLI model does **not** simply close that gap: on its own the raw model reaches 100% capture but **over-blocks at a 90% false-positive rate** — a vivid, honest reminder that a single "real" model is not production-trustworthy. The heterogeneous panel outvotes its over-eagerness back to **82% capture at a 50% false-positive rate**. That is the whole thesis in one experiment: an uncorrelated quorum tames a single over-confident model. The cross-mode breakdown (torch-free vs. real-NLI vs. Byzantine) is in [`COMPARISON.md`](benchmarks/injection_capture/COMPARISON.md); to plug in a real LLM juror, follow [`STEP3_LLM.md`](benchmarks/injection_capture/STEP3_LLM.md).
|
|
309
|
+
|
|
310
|
+
**Why a *quorum* and not one judge (reproducible, torch-free).** The aggregate above hides what consensus is *for*, because there every juror is honest. The [Byzantine experiment](benchmarks/injection_capture/BYZANTINE.md) plants one faulty juror: a single compromised judge that approves everything **collapses to 0% capture**, yet the *same* traitor inside a 3-node quorum still **holds at 97.6%** (two honest votes reach the 2-of-3 threshold). Symmetrically, a broken juror that rejects everything drives a lone judge to a **100% false-positive rate**, while the quorum is outvoted back down to **33.3%**. A lone model is a single point of failure in both directions; an uncorrelated quorum is not. Reproduce with `python benchmarks/injection_capture/run.py --byzantine`; every mode is archived side by side in [`COMPARISON.md`](benchmarks/injection_capture/COMPARISON.md).
|
|
311
|
+
|
|
312
|
+
> Honesty first: the committed headline is the **torch-free, fully reproducible** configuration. The **Guardrails AI and NeMo Guardrails baselines are runnable adapters** — `pip install -e ".[baselines]"` and add `--baselines` to score them on the identical corpus (their numbers depend on the tool's own model/config, so they live in [`COMPARISON.md`](benchmarks/injection_capture/COMPARISON.md), not the committed headline). The public attack suites (AgentDojo, InjecAgent, RAGAS) remain a roadmap and plug into the same scored `Defense` harness. Throughput and self-healing are demonstrated by the runnable examples today.
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
## 🏗️ Why not LangChain / CrewAI?
|
|
317
|
+
|
|
318
|
+
| Trait | Commercial Orchestrators | Stigmergic | In nature |
|
|
319
|
+
| :--- | :--- | :--- | :--- |
|
|
320
|
+
| **Topology** | Centralized supervisor/nodes | Decentralized stigmergy | An ant colony |
|
|
321
|
+
| **Communication** | String-based RPC (lossy) | Tensor / latent injection | A neural synapse |
|
|
322
|
+
| **Fault tolerance** | Try/catch retries | Semantic Byzantine quorum | An immune system |
|
|
323
|
+
| **State persistence** | App memory (volatile) | Database physics (durable) | Pheromones in soil |
|
|
324
|
+
|
|
325
|
+
Commercial frameworks model a **corporation**. Stigmergic models an **organism**. Organisms are older, and they don't go down when the manager quits.
|
|
326
|
+
|
|
327
|
+
## 📚 Documentation
|
|
328
|
+
|
|
329
|
+
Beyond this README, three documents specify the engineering contract in operational (not metaphorical) language:
|
|
330
|
+
|
|
331
|
+
- [`ARCHITECTURE.md`](ARCHITECTURE.md) — the abstractions, ports & adapters, execution semantics, the four trust boundaries, and the invariants the runtime holds.
|
|
332
|
+
- [`STATE_MACHINE.md`](STATE_MACHINE.md) — the formal `Pheromone` lifecycle: every legal state and transition, who drives it, and how the reliability core overlays it.
|
|
333
|
+
- [`THREAT_MODEL.md`](THREAT_MODEL.md) — the OWASP LLM Top-10 mapping, the distributed-systems failure modes, and the residual limitations, stated plainly.
|
|
334
|
+
- [`POSITIONING.md`](POSITIONING.md) — category, beachhead, and open-core strategy.
|
|
335
|
+
|
|
336
|
+
## 🤝 Contributing
|
|
337
|
+
This is an experimental research project pushing the boundaries of Distributed Cognitive Systems. We welcome PRs for new Byzantine voting mechanisms, new `AbstractGround` backends (Redis, DynamoDB), Swarm Inspector visualizations, and Latent Transfer utilities. New organs for the organism are always welcome.
|
|
338
|
+
|
|
339
|
+
See [`CONTRIBUTING.md`](CONTRIBUTING.md) for the dev setup, the ground rules, and how to add a backend / juror / caste / baseline; [`CODE_OF_CONDUCT.md`](CODE_OF_CONDUCT.md) for community expectations; and [`CHANGELOG.md`](CHANGELOG.md) for the release history.
|
|
340
|
+
|
|
341
|
+
## 📄 License
|
|
342
|
+
Apache License 2.0. See [`LICENSE`](LICENSE) for more information.
|