liquid-loop 0.7.0__tar.gz → 0.8.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.
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/PKG-INFO +89 -7
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/README.md +88 -6
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/liquid_loop/__init__.py +2 -2
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/liquid_loop/workspace.py +92 -6
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/liquid_loop.egg-info/PKG-INFO +89 -7
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/pyproject.toml +1 -1
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/LICENSE +0 -0
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/liquid_loop/__main__.py +0 -0
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/liquid_loop/cli.py +0 -0
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/liquid_loop/cognitive_budget.py +0 -0
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/liquid_loop/entropy.py +0 -0
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/liquid_loop/mesh/__init__.py +0 -0
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/liquid_loop/mesh/v2.py +0 -0
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/liquid_loop/storage.py +0 -0
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/liquid_loop.egg-info/SOURCES.txt +0 -0
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/liquid_loop.egg-info/dependency_links.txt +0 -0
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/liquid_loop.egg-info/entry_points.txt +0 -0
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/liquid_loop.egg-info/requires.txt +0 -0
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/liquid_loop.egg-info/top_level.txt +0 -0
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/setup.cfg +0 -0
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/tests/test_consensus_expansion.py +0 -0
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/tests/test_entropy.py +0 -0
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/tests/test_nucleate_dual_track.py +0 -0
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/tests/test_peek_seal.py +0 -0
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/tests/test_seal_persistence.py +0 -0
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/tests/test_self_evolve.py +0 -0
- {liquid_loop-0.7.0 → liquid_loop-0.8.0}/tests/test_workspace.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: liquid-loop
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.0
|
|
4
4
|
Summary: Self-Organizing Cognitive Memory for AI Agents — Liquid Loop theory implementation
|
|
5
5
|
Author: fishbook0001
|
|
6
6
|
Maintainer: fishbook0001
|
|
@@ -72,7 +72,7 @@ Dynamic: license-file
|
|
|
72
72
|
| **Anchor** 锚点 | 晶种 | 认知关注点,有稳定性值 s ∈ [0,1] |
|
|
73
73
|
| **Evidence** 证据 | 附着粒子 | 锚点下的具体观察,权重指数衰减 w×0.95ᵗ |
|
|
74
74
|
| **Memory** 结晶 | 结晶体 | 2+ 条一致 Evidence 自动凝聚,有置信度 c |
|
|
75
|
-
| **Entropy** 熵值 | 流体无序度 | 八维加权(锚点漂移 / 冲突密度 / 碎片 / 活跃间隔 / 价值衰减 / 锚定强度 / CPE 三维) |
|
|
75
|
+
| **Entropy** 熵值 (LEI) | 流体无序度 | 八维加权(锚点漂移 / 冲突密度 / 碎片 / 活跃间隔 / 价值衰减 / 锚定强度 / CPE 三维) |
|
|
76
76
|
|
|
77
77
|
**状态判定:**
|
|
78
78
|
```
|
|
@@ -81,6 +81,64 @@ YELLOW (0.3 ≤ entropy < 0.6) — 需关注
|
|
|
81
81
|
RED (entropy ≥ 0.6) — 需清理
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
+
> **关于 "Entropy" 的语义澄清 — Liquid Entropy Index (LEI)**
|
|
85
|
+
>
|
|
86
|
+
> 本项目中的 `entropy` 是 **Liquid Entropy Index (LEI): a system-stability deviation metric, inspired by entropy but NOT equivalent to thermodynamic entropy.**
|
|
87
|
+
> 它不是物理熵 `S = -k Σ pᵢ log pᵢ`,而是对**系统状态偏离稳定流形程度**的综合度量——由八个可解释分量人工加权而成(锚点漂移 / 冲突密度 / 证据碎片 / 活跃间隔 / 价值衰减 / 锚定强度 + CPE 三维:回顾性衰退 / 策略漂移 / 泛化崩塌)。
|
|
88
|
+
> 代码层函数名保留 `calculate()`(历史连续性);文档 / 论文层一律以 **LEI** 指称,避免与热力学熵混淆。
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## v0.8 反证轨 + 时间动力学(液态循环核心)
|
|
93
|
+
|
|
94
|
+
液环 v0.8 从"静态结晶"升级为**自调节记忆动力学**:记忆不是对象,而是过程。
|
|
95
|
+
|
|
96
|
+
### 反证轨(Contradiction Track)
|
|
97
|
+
|
|
98
|
+
证据可标记与记忆的关系,打破"一致即真":
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from liquid_loop import WorkspaceState
|
|
102
|
+
|
|
103
|
+
state = WorkspaceState()
|
|
104
|
+
a = state.add_anchor("用户偏好", "红还是蓝")
|
|
105
|
+
state.add_evidence(a, "用户喜欢红色") # support (默认)
|
|
106
|
+
state.add_evidence(a, "用户喜欢红色") # 2 次一致 -> 结晶, stability≈0.67
|
|
107
|
+
mem = state.memories[0]
|
|
108
|
+
state.add_evidence(a, "用户喜欢蓝色",
|
|
109
|
+
relation="contradiction", # 冲突证据
|
|
110
|
+
target_memory_id=mem.id) # 显式指向被反驳的记忆
|
|
111
|
+
# -> mem.stability 降到 ≈0.40(一致增稳 / 冲突降稳)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
稳定性公式:`stability = support / (support + 2·contradiction + 1)`。
|
|
115
|
+
`contradiction_weight=2.0` 使单条冲突的降稳效力 ≈ 两条支持,直接对抗**群体幻觉固化**。
|
|
116
|
+
|
|
117
|
+
### 时间动力学 `state.step(dt)`
|
|
118
|
+
|
|
119
|
+
显式演化步(记忆随时间衰减 / 被新证据强化):
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
# 无新支持证据时,时间推进使稳定性衰减
|
|
123
|
+
state.step(dt=10, decay_rate=0.05)
|
|
124
|
+
# M(t+1) = M(t) + reinforcement − decay − contradiction_penalty
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
- 每条证据权重按 `(1−decay_rate)^dt` 衰减(无强化则价值流失,下限 0.05)
|
|
128
|
+
- 记忆在**自上次 step 以来获得新 support** 时恢复到固有稳定性(强化);否则时间衰减且不超过固有上限
|
|
129
|
+
|
|
130
|
+
### 实验验证(examples/experiments/,全部 PASS)
|
|
131
|
+
|
|
132
|
+
| 实验 | 问题 | 结论 |
|
|
133
|
+
|------|------|------|
|
|
134
|
+
| **E2 错误记忆恢复** | 能否主动遗忘错误并恢复? | 80%错误+20%真实 → 反证轨使错误 stability 0.67→0.30、正确升至 0.69 主导 ✅ |
|
|
135
|
+
| **E3 多 Agent 冲突** | mesh v2 能否形成稳定共享认知? | A support / B contradiction / C noise → 核心 claim 进入受争议稳定区(0.40),噪声隔离 ✅ |
|
|
136
|
+
| **E1 长期漂移** | 1000 轮随机注入是否收敛? | 300 轮压测 → 48 记忆(≤池×3)、plateau、LEI GREEN、avg_stab 0.80 ✅ |
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
python3 examples/experiments/run_all.py # 生成 REPORT_v0.8.json
|
|
140
|
+
```
|
|
141
|
+
|
|
84
142
|
---
|
|
85
143
|
|
|
86
144
|
## 快速开始
|
|
@@ -93,7 +151,7 @@ pip install liquid-loop
|
|
|
93
151
|
|
|
94
152
|
### 3 分钟上手
|
|
95
153
|
```python
|
|
96
|
-
from liquid_loop import WorkspaceState, load, save,
|
|
154
|
+
from liquid_loop import WorkspaceState, load, save, calculate
|
|
97
155
|
|
|
98
156
|
# 1. 创建/加载工作区
|
|
99
157
|
state = WorkspaceState() # 或 load(Path("."))
|
|
@@ -111,7 +169,7 @@ for m in state.memories:
|
|
|
111
169
|
print(f"结晶: {m.content[:50]}... (置信度={m.confidence:.2f})")
|
|
112
170
|
|
|
113
171
|
# 5. 监控认知健康
|
|
114
|
-
entropy =
|
|
172
|
+
entropy = calculate(state)
|
|
115
173
|
print(f"熵值: {entropy:.4f} → {'🟢GREEN' if entropy < 0.3 else '🟡YELLOW' if entropy < 0.6 else '🔴RED'}")
|
|
116
174
|
|
|
117
175
|
# 6. 持久化
|
|
@@ -167,6 +225,26 @@ print(health["CCI"], health["consensus_crystals"])
|
|
|
167
225
|
|
|
168
226
|
---
|
|
169
227
|
|
|
228
|
+
## 定位:Self-Regulating Persistent Memory Dynamics
|
|
229
|
+
|
|
230
|
+
液环的本质不是"AI 意识",而是一套 **agent 系统的自调节持久记忆动力学(Self-Regulating Persistent Memory Dynamics for Agent Systems)**。`AuditChain + LEI(Entropy) + Memory decay` 三者组合形成闭环,使记忆从"外部管理"转向"内部自组织":
|
|
231
|
+
|
|
232
|
+
```
|
|
233
|
+
Input Evidence
|
|
234
|
+
↓
|
|
235
|
+
Memory State ←──────────────┐
|
|
236
|
+
↓ │
|
|
237
|
+
LEI Evaluation (八维熵) │
|
|
238
|
+
↓ │
|
|
239
|
+
Decay / Reinforcement ────────┘
|
|
240
|
+
↓
|
|
241
|
+
AuditChain (SHA256 链式追溯)
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
这比单独的 memory store 更接近一个可被实验检验的**动态系统**:输入驱动状态、熵评估稳定性、衰减/强化回流状态、审计链保证来源可信。
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
170
248
|
## 架构对比
|
|
171
249
|
|
|
172
250
|
```
|
|
@@ -213,7 +291,7 @@ liquid-loop/
|
|
|
213
291
|
│ ├── __init__.py # 公共 API 导出
|
|
214
292
|
│ ├── workspace.py # 核心数据模型 + AuditChain + auto_classify + decay
|
|
215
293
|
│ ├── storage.py # JSON 持久化 + 审计链写入
|
|
216
|
-
│ ├── entropy.py #
|
|
294
|
+
│ ├── entropy.py # 八维熵值计算(含 CPE 三维)
|
|
217
295
|
│ ├── mesh/ # MESH v2 多智能体共识协议集成(validate_evidence / compute_cci / ...)
|
|
218
296
|
│ └── cli.py # Click CLI (11 命令)
|
|
219
297
|
├── examples/
|
|
@@ -240,12 +318,16 @@ pytest -v
|
|
|
240
318
|
|
|
241
319
|
## 路线图
|
|
242
320
|
|
|
243
|
-
- [ ] 语义一致性结晶(嵌入相似度替代精确匹配)
|
|
244
321
|
- [x] 多 Agent 液环耦合(`liquid_loop.mesh` v2 共识协议,2026-07-15 落地)
|
|
245
|
-
- [ ]
|
|
322
|
+
- [x] **[v0.8] 反证轨(Evidence Graph)**:Evidence 分 support / contradiction,一致增稳、冲突降稳,驱动 memory stability score(不再"一致即真")
|
|
323
|
+
- [x] **[v0.8] 显式时间动力学**:`M(t+1) = M(t) + reinforcement − decay − contradiction_penalty`,让记忆成为"过程"而非"对象"(真正的液态循环)
|
|
324
|
+
- [x] **[v0.8] 三实验全 PASS**:E2 错误记忆恢复 → E3 多 agent 冲突 → E1 长期漂移(见上节)
|
|
325
|
+
- [ ] **[v0.9 优化项]**:`_detect_conflicts` 由每证据 O(g²) 两两扫描改为增量/采样(大规模高频写入性能,非正确性)
|
|
246
326
|
- [ ] LoCoMo / LongMemEval 基准对比
|
|
247
327
|
- [ ] 边缘端部署优化(<50KB)
|
|
248
328
|
|
|
329
|
+
> 零向量是液环的硬约束:一致性判定永不引入 embedding / 相似度(这正是液环要替代的方案)。
|
|
330
|
+
|
|
249
331
|
---
|
|
250
332
|
|
|
251
333
|
## 许可证
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
| **Anchor** 锚点 | 晶种 | 认知关注点,有稳定性值 s ∈ [0,1] |
|
|
34
34
|
| **Evidence** 证据 | 附着粒子 | 锚点下的具体观察,权重指数衰减 w×0.95ᵗ |
|
|
35
35
|
| **Memory** 结晶 | 结晶体 | 2+ 条一致 Evidence 自动凝聚,有置信度 c |
|
|
36
|
-
| **Entropy** 熵值 | 流体无序度 | 八维加权(锚点漂移 / 冲突密度 / 碎片 / 活跃间隔 / 价值衰减 / 锚定强度 / CPE 三维) |
|
|
36
|
+
| **Entropy** 熵值 (LEI) | 流体无序度 | 八维加权(锚点漂移 / 冲突密度 / 碎片 / 活跃间隔 / 价值衰减 / 锚定强度 / CPE 三维) |
|
|
37
37
|
|
|
38
38
|
**状态判定:**
|
|
39
39
|
```
|
|
@@ -42,6 +42,64 @@ YELLOW (0.3 ≤ entropy < 0.6) — 需关注
|
|
|
42
42
|
RED (entropy ≥ 0.6) — 需清理
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
+
> **关于 "Entropy" 的语义澄清 — Liquid Entropy Index (LEI)**
|
|
46
|
+
>
|
|
47
|
+
> 本项目中的 `entropy` 是 **Liquid Entropy Index (LEI): a system-stability deviation metric, inspired by entropy but NOT equivalent to thermodynamic entropy.**
|
|
48
|
+
> 它不是物理熵 `S = -k Σ pᵢ log pᵢ`,而是对**系统状态偏离稳定流形程度**的综合度量——由八个可解释分量人工加权而成(锚点漂移 / 冲突密度 / 证据碎片 / 活跃间隔 / 价值衰减 / 锚定强度 + CPE 三维:回顾性衰退 / 策略漂移 / 泛化崩塌)。
|
|
49
|
+
> 代码层函数名保留 `calculate()`(历史连续性);文档 / 论文层一律以 **LEI** 指称,避免与热力学熵混淆。
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## v0.8 反证轨 + 时间动力学(液态循环核心)
|
|
54
|
+
|
|
55
|
+
液环 v0.8 从"静态结晶"升级为**自调节记忆动力学**:记忆不是对象,而是过程。
|
|
56
|
+
|
|
57
|
+
### 反证轨(Contradiction Track)
|
|
58
|
+
|
|
59
|
+
证据可标记与记忆的关系,打破"一致即真":
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from liquid_loop import WorkspaceState
|
|
63
|
+
|
|
64
|
+
state = WorkspaceState()
|
|
65
|
+
a = state.add_anchor("用户偏好", "红还是蓝")
|
|
66
|
+
state.add_evidence(a, "用户喜欢红色") # support (默认)
|
|
67
|
+
state.add_evidence(a, "用户喜欢红色") # 2 次一致 -> 结晶, stability≈0.67
|
|
68
|
+
mem = state.memories[0]
|
|
69
|
+
state.add_evidence(a, "用户喜欢蓝色",
|
|
70
|
+
relation="contradiction", # 冲突证据
|
|
71
|
+
target_memory_id=mem.id) # 显式指向被反驳的记忆
|
|
72
|
+
# -> mem.stability 降到 ≈0.40(一致增稳 / 冲突降稳)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
稳定性公式:`stability = support / (support + 2·contradiction + 1)`。
|
|
76
|
+
`contradiction_weight=2.0` 使单条冲突的降稳效力 ≈ 两条支持,直接对抗**群体幻觉固化**。
|
|
77
|
+
|
|
78
|
+
### 时间动力学 `state.step(dt)`
|
|
79
|
+
|
|
80
|
+
显式演化步(记忆随时间衰减 / 被新证据强化):
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
# 无新支持证据时,时间推进使稳定性衰减
|
|
84
|
+
state.step(dt=10, decay_rate=0.05)
|
|
85
|
+
# M(t+1) = M(t) + reinforcement − decay − contradiction_penalty
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
- 每条证据权重按 `(1−decay_rate)^dt` 衰减(无强化则价值流失,下限 0.05)
|
|
89
|
+
- 记忆在**自上次 step 以来获得新 support** 时恢复到固有稳定性(强化);否则时间衰减且不超过固有上限
|
|
90
|
+
|
|
91
|
+
### 实验验证(examples/experiments/,全部 PASS)
|
|
92
|
+
|
|
93
|
+
| 实验 | 问题 | 结论 |
|
|
94
|
+
|------|------|------|
|
|
95
|
+
| **E2 错误记忆恢复** | 能否主动遗忘错误并恢复? | 80%错误+20%真实 → 反证轨使错误 stability 0.67→0.30、正确升至 0.69 主导 ✅ |
|
|
96
|
+
| **E3 多 Agent 冲突** | mesh v2 能否形成稳定共享认知? | A support / B contradiction / C noise → 核心 claim 进入受争议稳定区(0.40),噪声隔离 ✅ |
|
|
97
|
+
| **E1 长期漂移** | 1000 轮随机注入是否收敛? | 300 轮压测 → 48 记忆(≤池×3)、plateau、LEI GREEN、avg_stab 0.80 ✅ |
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
python3 examples/experiments/run_all.py # 生成 REPORT_v0.8.json
|
|
101
|
+
```
|
|
102
|
+
|
|
45
103
|
---
|
|
46
104
|
|
|
47
105
|
## 快速开始
|
|
@@ -54,7 +112,7 @@ pip install liquid-loop
|
|
|
54
112
|
|
|
55
113
|
### 3 分钟上手
|
|
56
114
|
```python
|
|
57
|
-
from liquid_loop import WorkspaceState, load, save,
|
|
115
|
+
from liquid_loop import WorkspaceState, load, save, calculate
|
|
58
116
|
|
|
59
117
|
# 1. 创建/加载工作区
|
|
60
118
|
state = WorkspaceState() # 或 load(Path("."))
|
|
@@ -72,7 +130,7 @@ for m in state.memories:
|
|
|
72
130
|
print(f"结晶: {m.content[:50]}... (置信度={m.confidence:.2f})")
|
|
73
131
|
|
|
74
132
|
# 5. 监控认知健康
|
|
75
|
-
entropy =
|
|
133
|
+
entropy = calculate(state)
|
|
76
134
|
print(f"熵值: {entropy:.4f} → {'🟢GREEN' if entropy < 0.3 else '🟡YELLOW' if entropy < 0.6 else '🔴RED'}")
|
|
77
135
|
|
|
78
136
|
# 6. 持久化
|
|
@@ -128,6 +186,26 @@ print(health["CCI"], health["consensus_crystals"])
|
|
|
128
186
|
|
|
129
187
|
---
|
|
130
188
|
|
|
189
|
+
## 定位:Self-Regulating Persistent Memory Dynamics
|
|
190
|
+
|
|
191
|
+
液环的本质不是"AI 意识",而是一套 **agent 系统的自调节持久记忆动力学(Self-Regulating Persistent Memory Dynamics for Agent Systems)**。`AuditChain + LEI(Entropy) + Memory decay` 三者组合形成闭环,使记忆从"外部管理"转向"内部自组织":
|
|
192
|
+
|
|
193
|
+
```
|
|
194
|
+
Input Evidence
|
|
195
|
+
↓
|
|
196
|
+
Memory State ←──────────────┐
|
|
197
|
+
↓ │
|
|
198
|
+
LEI Evaluation (八维熵) │
|
|
199
|
+
↓ │
|
|
200
|
+
Decay / Reinforcement ────────┘
|
|
201
|
+
↓
|
|
202
|
+
AuditChain (SHA256 链式追溯)
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
这比单独的 memory store 更接近一个可被实验检验的**动态系统**:输入驱动状态、熵评估稳定性、衰减/强化回流状态、审计链保证来源可信。
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
131
209
|
## 架构对比
|
|
132
210
|
|
|
133
211
|
```
|
|
@@ -174,7 +252,7 @@ liquid-loop/
|
|
|
174
252
|
│ ├── __init__.py # 公共 API 导出
|
|
175
253
|
│ ├── workspace.py # 核心数据模型 + AuditChain + auto_classify + decay
|
|
176
254
|
│ ├── storage.py # JSON 持久化 + 审计链写入
|
|
177
|
-
│ ├── entropy.py #
|
|
255
|
+
│ ├── entropy.py # 八维熵值计算(含 CPE 三维)
|
|
178
256
|
│ ├── mesh/ # MESH v2 多智能体共识协议集成(validate_evidence / compute_cci / ...)
|
|
179
257
|
│ └── cli.py # Click CLI (11 命令)
|
|
180
258
|
├── examples/
|
|
@@ -201,12 +279,16 @@ pytest -v
|
|
|
201
279
|
|
|
202
280
|
## 路线图
|
|
203
281
|
|
|
204
|
-
- [ ] 语义一致性结晶(嵌入相似度替代精确匹配)
|
|
205
282
|
- [x] 多 Agent 液环耦合(`liquid_loop.mesh` v2 共识协议,2026-07-15 落地)
|
|
206
|
-
- [ ]
|
|
283
|
+
- [x] **[v0.8] 反证轨(Evidence Graph)**:Evidence 分 support / contradiction,一致增稳、冲突降稳,驱动 memory stability score(不再"一致即真")
|
|
284
|
+
- [x] **[v0.8] 显式时间动力学**:`M(t+1) = M(t) + reinforcement − decay − contradiction_penalty`,让记忆成为"过程"而非"对象"(真正的液态循环)
|
|
285
|
+
- [x] **[v0.8] 三实验全 PASS**:E2 错误记忆恢复 → E3 多 agent 冲突 → E1 长期漂移(见上节)
|
|
286
|
+
- [ ] **[v0.9 优化项]**:`_detect_conflicts` 由每证据 O(g²) 两两扫描改为增量/采样(大规模高频写入性能,非正确性)
|
|
207
287
|
- [ ] LoCoMo / LongMemEval 基准对比
|
|
208
288
|
- [ ] 边缘端部署优化(<50KB)
|
|
209
289
|
|
|
290
|
+
> 零向量是液环的硬约束:一致性判定永不引入 embedding / 相似度(这正是液环要替代的方案)。
|
|
291
|
+
|
|
210
292
|
---
|
|
211
293
|
|
|
212
294
|
## 许可证
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"""Liquid Loop — Workspace Cognitive Runtime v0.
|
|
2
|
-
__version__ = "0.
|
|
1
|
+
"""Liquid Loop — Workspace Cognitive Runtime v0.8.0 (反证轨 + 时间动力学, CPE-fused, SEAL dual-opt, dual-track multi-agent, MESH v2 integration)"""
|
|
2
|
+
__version__ = "0.8.0"
|
|
3
3
|
|
|
4
4
|
from .workspace import (
|
|
5
5
|
WorkspaceState, Anchor, Evidence, Memory, Conflict,
|
|
@@ -156,6 +156,8 @@ class Evidence:
|
|
|
156
156
|
quality: str = "normal"
|
|
157
157
|
archived: bool = False # 预算超额冷归档标记(PEEK 落地,零丢失)
|
|
158
158
|
agent_id: str = "" # 多智能体共用:写入者标识(共用机制,缺省=legacy/单实例)
|
|
159
|
+
relation: str = "support" # 反证轨:evidence 与 memory 的关系 "support"(一致) | "contradiction"(冲突) | ""(legacy 视为 support)
|
|
160
|
+
target_memory_id: str = "" # relation=contradiction 时,可选显式指向被反驳的 memory(缺省=同锚点最近结晶)
|
|
159
161
|
|
|
160
162
|
|
|
161
163
|
@dataclass
|
|
@@ -167,6 +169,11 @@ class Memory:
|
|
|
167
169
|
confidence: float = 0.0
|
|
168
170
|
scope: str = "private" # 结晶来源: private(同 agent≥2一致) / consensus(跨 distinct owner≥2一致)
|
|
169
171
|
contributors: list[str] = field(default_factory=list) # 参与成核的 agent_id 列表
|
|
172
|
+
# ── v0.8 反证轨 + 时间动力学 ──
|
|
173
|
+
stability: float = 1.0 # 反证轨稳定性:一致增稳、冲突降稳(0~1)
|
|
174
|
+
support_count: int = 0 # 支持该 memory 的证据数
|
|
175
|
+
contradiction_count: int = 0 # 反驳该 memory 的证据数
|
|
176
|
+
last_reinforced: str = "" # 最近一次被 support 证据强化的时间戳(时间动力学用)
|
|
170
177
|
|
|
171
178
|
|
|
172
179
|
@dataclass
|
|
@@ -248,11 +255,16 @@ class WorkspaceState:
|
|
|
248
255
|
self.updated_at = now()
|
|
249
256
|
return a
|
|
250
257
|
|
|
251
|
-
def add_evidence(self, anchor, content: str, quality: float = 1.0, agent_id: str = ""
|
|
258
|
+
def add_evidence(self, anchor, content: str, quality: float = 1.0, agent_id: str = "",
|
|
259
|
+
dedup: bool = False, relation: str = "support",
|
|
260
|
+
target_memory_id: str = "") -> Optional[Evidence]:
|
|
252
261
|
"""向指定锚点添加一条证据。
|
|
253
262
|
|
|
254
263
|
anchor 参数兼容:锚点名称(str) | 锚点ID(str) | Anchor对象
|
|
255
264
|
agent_id:多智能体共用写入者标识(缺省空=legacy/单实例)
|
|
265
|
+
dedup:幂等去重开关(默认 False,核心语义允许重复写入以触发结晶)。
|
|
266
|
+
relation:反证轨关系 "support"(一致, 默认) | "contradiction"(冲突) —— 见 v0.8 反证轨。
|
|
267
|
+
target_memory_id:relation="contradiction" 时可选显式指向被反驳的 memory。
|
|
256
268
|
"""
|
|
257
269
|
target = None
|
|
258
270
|
if isinstance(anchor, Anchor):
|
|
@@ -264,13 +276,15 @@ class WorkspaceState:
|
|
|
264
276
|
target = next((a for a in self.anchors if a.id == anchor), None)
|
|
265
277
|
if not target:
|
|
266
278
|
return None
|
|
267
|
-
#
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
279
|
+
# 幂等去重(仅当 dedup=True):同锚点+同内容+同 agent 已存在则复用
|
|
280
|
+
if dedup:
|
|
281
|
+
for ex in self.evidences:
|
|
282
|
+
if ex.anchor_id == target.id and ex.content == content and ex.agent_id == agent_id:
|
|
283
|
+
return ex
|
|
271
284
|
e = Evidence(
|
|
272
285
|
id=uid(), anchor_id=target.id, content=content,
|
|
273
286
|
quality=quality, timestamp=now(), agent_id=agent_id,
|
|
287
|
+
relation=relation, target_memory_id=target_memory_id,
|
|
274
288
|
)
|
|
275
289
|
self.evidences.append(e)
|
|
276
290
|
target.evidence_ids.append(e.id)
|
|
@@ -280,9 +294,10 @@ class WorkspaceState:
|
|
|
280
294
|
return e
|
|
281
295
|
|
|
282
296
|
def _on_evidence_added(self, anchor_id: str):
|
|
283
|
-
"""
|
|
297
|
+
"""证据添加后的统一后处理:衰减→成核→反证轨稳定性→冲突检测→预算稳态"""
|
|
284
298
|
self._decay_anchor(anchor_id)
|
|
285
299
|
self._nucleate(anchor_id)
|
|
300
|
+
self._update_memory_stability(anchor_id)
|
|
286
301
|
self._recalc_anchor(anchor_id)
|
|
287
302
|
self._detect_conflicts(anchor_id)
|
|
288
303
|
self._stabilize_budget()
|
|
@@ -434,6 +449,77 @@ class WorkspaceState:
|
|
|
434
449
|
self.updated_at = now()
|
|
435
450
|
return m
|
|
436
451
|
|
|
452
|
+
# ─────────────────────────────────────────────────────────────
|
|
453
|
+
# v0.8 反证轨 + 时间动力学(液态循环核心)
|
|
454
|
+
# ─────────────────────────────────────────────────────────────
|
|
455
|
+
|
|
456
|
+
def _update_memory_stability(self, anchor_id: str):
|
|
457
|
+
"""反证轨:一致证据(support)增稳,冲突证据(contradiction)降稳。
|
|
458
|
+
|
|
459
|
+
稳定性 = support / (support + CONTRADICTION_WEIGHT * contradiction + 1)
|
|
460
|
+
- 同锚点下 content 相同的 support 证据计为支持
|
|
461
|
+
- relation="contradiction" 的证据计为反驳(显式 target_memory_id 或同锚点无指定则作用于该锚点结晶)
|
|
462
|
+
- 有 support 证据则刷新 last_reinforced(时间动力学强化信号)
|
|
463
|
+
"""
|
|
464
|
+
CONTRADICTION_WEIGHT = 2.0
|
|
465
|
+
group = [e for e in self.evidences if e.anchor_id == anchor_id and not e.archived]
|
|
466
|
+
group_ids = {e.id for e in group}
|
|
467
|
+
anchor_memories = [m for m in self.memories
|
|
468
|
+
if any(eid in group_ids for eid in m.evidence_ids)]
|
|
469
|
+
for m in anchor_memories:
|
|
470
|
+
supports = [e for e in group
|
|
471
|
+
if e.relation in ("support", "") and e.content == m.content]
|
|
472
|
+
if m.id:
|
|
473
|
+
contradicts = [e for e in group
|
|
474
|
+
if e.relation == "contradiction"
|
|
475
|
+
and (e.target_memory_id == m.id or not e.target_memory_id)]
|
|
476
|
+
else:
|
|
477
|
+
contradicts = [e for e in group
|
|
478
|
+
if e.relation == "contradiction" and not e.target_memory_id]
|
|
479
|
+
s = len(supports)
|
|
480
|
+
c = len(contradicts)
|
|
481
|
+
m.support_count = s
|
|
482
|
+
m.contradiction_count = c
|
|
483
|
+
m.stability = round(min(1.0, max(0.0,
|
|
484
|
+
s / (s + CONTRADICTION_WEIGHT * c + 1))), 3)
|
|
485
|
+
if supports:
|
|
486
|
+
m.last_reinforced = max(e.timestamp for e in supports)
|
|
487
|
+
|
|
488
|
+
def step(self, dt: int = 1, decay_rate: float = 0.05):
|
|
489
|
+
"""显式时间动力学步(v0.8 液态循环核心):
|
|
490
|
+
|
|
491
|
+
M(t+1) = M(t) + reinforcement − decay − contradiction_penalty
|
|
492
|
+
|
|
493
|
+
- 每条证据按 (1−decay_rate)^dt 衰减权重(无强化则价值流失,下限 0.05)
|
|
494
|
+
- 每个 memory 按 support/contradiction 计数重算固有稳定性(矛盾惩罚持续作用);
|
|
495
|
+
若本轮有 support 证据 → 稳定性恢复到固有值(强化);否则按时间衰减(无强化流失)
|
|
496
|
+
- 重算锚点稳定性与审计更新时间
|
|
497
|
+
"""
|
|
498
|
+
# 1. 证据权重时间衰减
|
|
499
|
+
for e in self.evidences:
|
|
500
|
+
if not e.archived:
|
|
501
|
+
e.weight = max(e.weight * ((1 - decay_rate) ** dt), 0.05)
|
|
502
|
+
# 2. 记忆稳定性:固有(计数驱动) + 时间衰减/强化
|
|
503
|
+
for a in self.anchors:
|
|
504
|
+
self._update_memory_stability(a.id)
|
|
505
|
+
last_step = getattr(self, "_last_step_at", "")
|
|
506
|
+
now_dt = datetime.now(timezone.utc)
|
|
507
|
+
for m in self.memories:
|
|
508
|
+
intrinsic = m.stability # _update_memory_stability 已写入固有稳定性
|
|
509
|
+
# 强化 = 自上次 step 以来有过新 support 证据(last_reinforced 晚于上次 step)
|
|
510
|
+
reinforced = bool(m.last_reinforced) and (not last_step or m.last_reinforced > last_step)
|
|
511
|
+
if reinforced:
|
|
512
|
+
m.stability = intrinsic # 被强化:恢复到固有稳定性
|
|
513
|
+
else:
|
|
514
|
+
# 无新强化:时间衰减,且不超过固有上限
|
|
515
|
+
m.stability = round(max(0.0, min(intrinsic,
|
|
516
|
+
m.stability * ((1 - decay_rate) ** dt))), 3)
|
|
517
|
+
self._last_step_at = now()
|
|
518
|
+
# 3. 重算锚点稳定性
|
|
519
|
+
for a in self.anchors:
|
|
520
|
+
self._recalc_anchor(a.id)
|
|
521
|
+
self.updated_at = now()
|
|
522
|
+
|
|
437
523
|
|
|
438
524
|
# ==============================================================================
|
|
439
525
|
# CPERegularizer — 能力保留正则化引擎(借鉴 UIUC CPE 论文 arXiv:2605.09315)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: liquid-loop
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.8.0
|
|
4
4
|
Summary: Self-Organizing Cognitive Memory for AI Agents — Liquid Loop theory implementation
|
|
5
5
|
Author: fishbook0001
|
|
6
6
|
Maintainer: fishbook0001
|
|
@@ -72,7 +72,7 @@ Dynamic: license-file
|
|
|
72
72
|
| **Anchor** 锚点 | 晶种 | 认知关注点,有稳定性值 s ∈ [0,1] |
|
|
73
73
|
| **Evidence** 证据 | 附着粒子 | 锚点下的具体观察,权重指数衰减 w×0.95ᵗ |
|
|
74
74
|
| **Memory** 结晶 | 结晶体 | 2+ 条一致 Evidence 自动凝聚,有置信度 c |
|
|
75
|
-
| **Entropy** 熵值 | 流体无序度 | 八维加权(锚点漂移 / 冲突密度 / 碎片 / 活跃间隔 / 价值衰减 / 锚定强度 / CPE 三维) |
|
|
75
|
+
| **Entropy** 熵值 (LEI) | 流体无序度 | 八维加权(锚点漂移 / 冲突密度 / 碎片 / 活跃间隔 / 价值衰减 / 锚定强度 / CPE 三维) |
|
|
76
76
|
|
|
77
77
|
**状态判定:**
|
|
78
78
|
```
|
|
@@ -81,6 +81,64 @@ YELLOW (0.3 ≤ entropy < 0.6) — 需关注
|
|
|
81
81
|
RED (entropy ≥ 0.6) — 需清理
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
+
> **关于 "Entropy" 的语义澄清 — Liquid Entropy Index (LEI)**
|
|
85
|
+
>
|
|
86
|
+
> 本项目中的 `entropy` 是 **Liquid Entropy Index (LEI): a system-stability deviation metric, inspired by entropy but NOT equivalent to thermodynamic entropy.**
|
|
87
|
+
> 它不是物理熵 `S = -k Σ pᵢ log pᵢ`,而是对**系统状态偏离稳定流形程度**的综合度量——由八个可解释分量人工加权而成(锚点漂移 / 冲突密度 / 证据碎片 / 活跃间隔 / 价值衰减 / 锚定强度 + CPE 三维:回顾性衰退 / 策略漂移 / 泛化崩塌)。
|
|
88
|
+
> 代码层函数名保留 `calculate()`(历史连续性);文档 / 论文层一律以 **LEI** 指称,避免与热力学熵混淆。
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## v0.8 反证轨 + 时间动力学(液态循环核心)
|
|
93
|
+
|
|
94
|
+
液环 v0.8 从"静态结晶"升级为**自调节记忆动力学**:记忆不是对象,而是过程。
|
|
95
|
+
|
|
96
|
+
### 反证轨(Contradiction Track)
|
|
97
|
+
|
|
98
|
+
证据可标记与记忆的关系,打破"一致即真":
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from liquid_loop import WorkspaceState
|
|
102
|
+
|
|
103
|
+
state = WorkspaceState()
|
|
104
|
+
a = state.add_anchor("用户偏好", "红还是蓝")
|
|
105
|
+
state.add_evidence(a, "用户喜欢红色") # support (默认)
|
|
106
|
+
state.add_evidence(a, "用户喜欢红色") # 2 次一致 -> 结晶, stability≈0.67
|
|
107
|
+
mem = state.memories[0]
|
|
108
|
+
state.add_evidence(a, "用户喜欢蓝色",
|
|
109
|
+
relation="contradiction", # 冲突证据
|
|
110
|
+
target_memory_id=mem.id) # 显式指向被反驳的记忆
|
|
111
|
+
# -> mem.stability 降到 ≈0.40(一致增稳 / 冲突降稳)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
稳定性公式:`stability = support / (support + 2·contradiction + 1)`。
|
|
115
|
+
`contradiction_weight=2.0` 使单条冲突的降稳效力 ≈ 两条支持,直接对抗**群体幻觉固化**。
|
|
116
|
+
|
|
117
|
+
### 时间动力学 `state.step(dt)`
|
|
118
|
+
|
|
119
|
+
显式演化步(记忆随时间衰减 / 被新证据强化):
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
# 无新支持证据时,时间推进使稳定性衰减
|
|
123
|
+
state.step(dt=10, decay_rate=0.05)
|
|
124
|
+
# M(t+1) = M(t) + reinforcement − decay − contradiction_penalty
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
- 每条证据权重按 `(1−decay_rate)^dt` 衰减(无强化则价值流失,下限 0.05)
|
|
128
|
+
- 记忆在**自上次 step 以来获得新 support** 时恢复到固有稳定性(强化);否则时间衰减且不超过固有上限
|
|
129
|
+
|
|
130
|
+
### 实验验证(examples/experiments/,全部 PASS)
|
|
131
|
+
|
|
132
|
+
| 实验 | 问题 | 结论 |
|
|
133
|
+
|------|------|------|
|
|
134
|
+
| **E2 错误记忆恢复** | 能否主动遗忘错误并恢复? | 80%错误+20%真实 → 反证轨使错误 stability 0.67→0.30、正确升至 0.69 主导 ✅ |
|
|
135
|
+
| **E3 多 Agent 冲突** | mesh v2 能否形成稳定共享认知? | A support / B contradiction / C noise → 核心 claim 进入受争议稳定区(0.40),噪声隔离 ✅ |
|
|
136
|
+
| **E1 长期漂移** | 1000 轮随机注入是否收敛? | 300 轮压测 → 48 记忆(≤池×3)、plateau、LEI GREEN、avg_stab 0.80 ✅ |
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
python3 examples/experiments/run_all.py # 生成 REPORT_v0.8.json
|
|
140
|
+
```
|
|
141
|
+
|
|
84
142
|
---
|
|
85
143
|
|
|
86
144
|
## 快速开始
|
|
@@ -93,7 +151,7 @@ pip install liquid-loop
|
|
|
93
151
|
|
|
94
152
|
### 3 分钟上手
|
|
95
153
|
```python
|
|
96
|
-
from liquid_loop import WorkspaceState, load, save,
|
|
154
|
+
from liquid_loop import WorkspaceState, load, save, calculate
|
|
97
155
|
|
|
98
156
|
# 1. 创建/加载工作区
|
|
99
157
|
state = WorkspaceState() # 或 load(Path("."))
|
|
@@ -111,7 +169,7 @@ for m in state.memories:
|
|
|
111
169
|
print(f"结晶: {m.content[:50]}... (置信度={m.confidence:.2f})")
|
|
112
170
|
|
|
113
171
|
# 5. 监控认知健康
|
|
114
|
-
entropy =
|
|
172
|
+
entropy = calculate(state)
|
|
115
173
|
print(f"熵值: {entropy:.4f} → {'🟢GREEN' if entropy < 0.3 else '🟡YELLOW' if entropy < 0.6 else '🔴RED'}")
|
|
116
174
|
|
|
117
175
|
# 6. 持久化
|
|
@@ -167,6 +225,26 @@ print(health["CCI"], health["consensus_crystals"])
|
|
|
167
225
|
|
|
168
226
|
---
|
|
169
227
|
|
|
228
|
+
## 定位:Self-Regulating Persistent Memory Dynamics
|
|
229
|
+
|
|
230
|
+
液环的本质不是"AI 意识",而是一套 **agent 系统的自调节持久记忆动力学(Self-Regulating Persistent Memory Dynamics for Agent Systems)**。`AuditChain + LEI(Entropy) + Memory decay` 三者组合形成闭环,使记忆从"外部管理"转向"内部自组织":
|
|
231
|
+
|
|
232
|
+
```
|
|
233
|
+
Input Evidence
|
|
234
|
+
↓
|
|
235
|
+
Memory State ←──────────────┐
|
|
236
|
+
↓ │
|
|
237
|
+
LEI Evaluation (八维熵) │
|
|
238
|
+
↓ │
|
|
239
|
+
Decay / Reinforcement ────────┘
|
|
240
|
+
↓
|
|
241
|
+
AuditChain (SHA256 链式追溯)
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
这比单独的 memory store 更接近一个可被实验检验的**动态系统**:输入驱动状态、熵评估稳定性、衰减/强化回流状态、审计链保证来源可信。
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
170
248
|
## 架构对比
|
|
171
249
|
|
|
172
250
|
```
|
|
@@ -213,7 +291,7 @@ liquid-loop/
|
|
|
213
291
|
│ ├── __init__.py # 公共 API 导出
|
|
214
292
|
│ ├── workspace.py # 核心数据模型 + AuditChain + auto_classify + decay
|
|
215
293
|
│ ├── storage.py # JSON 持久化 + 审计链写入
|
|
216
|
-
│ ├── entropy.py #
|
|
294
|
+
│ ├── entropy.py # 八维熵值计算(含 CPE 三维)
|
|
217
295
|
│ ├── mesh/ # MESH v2 多智能体共识协议集成(validate_evidence / compute_cci / ...)
|
|
218
296
|
│ └── cli.py # Click CLI (11 命令)
|
|
219
297
|
├── examples/
|
|
@@ -240,12 +318,16 @@ pytest -v
|
|
|
240
318
|
|
|
241
319
|
## 路线图
|
|
242
320
|
|
|
243
|
-
- [ ] 语义一致性结晶(嵌入相似度替代精确匹配)
|
|
244
321
|
- [x] 多 Agent 液环耦合(`liquid_loop.mesh` v2 共识协议,2026-07-15 落地)
|
|
245
|
-
- [ ]
|
|
322
|
+
- [x] **[v0.8] 反证轨(Evidence Graph)**:Evidence 分 support / contradiction,一致增稳、冲突降稳,驱动 memory stability score(不再"一致即真")
|
|
323
|
+
- [x] **[v0.8] 显式时间动力学**:`M(t+1) = M(t) + reinforcement − decay − contradiction_penalty`,让记忆成为"过程"而非"对象"(真正的液态循环)
|
|
324
|
+
- [x] **[v0.8] 三实验全 PASS**:E2 错误记忆恢复 → E3 多 agent 冲突 → E1 长期漂移(见上节)
|
|
325
|
+
- [ ] **[v0.9 优化项]**:`_detect_conflicts` 由每证据 O(g²) 两两扫描改为增量/采样(大规模高频写入性能,非正确性)
|
|
246
326
|
- [ ] LoCoMo / LongMemEval 基准对比
|
|
247
327
|
- [ ] 边缘端部署优化(<50KB)
|
|
248
328
|
|
|
329
|
+
> 零向量是液环的硬约束:一致性判定永不引入 embedding / 相似度(这正是液环要替代的方案)。
|
|
330
|
+
|
|
249
331
|
---
|
|
250
332
|
|
|
251
333
|
## 许可证
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "liquid-loop"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.8.0"
|
|
8
8
|
description = "Self-Organizing Cognitive Memory for AI Agents — Liquid Loop theory implementation"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = {text = "MIT"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|