liquid-loop 0.7.1__tar.gz → 0.9.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.1 → liquid_loop-0.9.0}/PKG-INFO +70 -6
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/README.md +69 -5
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/liquid_loop/__init__.py +2 -2
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/liquid_loop/workspace.py +104 -12
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/liquid_loop.egg-info/PKG-INFO +70 -6
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/pyproject.toml +1 -1
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/LICENSE +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/liquid_loop/__main__.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/liquid_loop/cli.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/liquid_loop/cognitive_budget.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/liquid_loop/entropy.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/liquid_loop/mesh/__init__.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/liquid_loop/mesh/v2.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/liquid_loop/storage.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/liquid_loop.egg-info/SOURCES.txt +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/liquid_loop.egg-info/dependency_links.txt +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/liquid_loop.egg-info/entry_points.txt +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/liquid_loop.egg-info/requires.txt +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/liquid_loop.egg-info/top_level.txt +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/setup.cfg +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/tests/test_consensus_expansion.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/tests/test_entropy.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/tests/test_nucleate_dual_track.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/tests/test_peek_seal.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/tests/test_seal_persistence.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.9.0}/tests/test_self_evolve.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.9.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.9.0
|
|
4
4
|
Summary: Self-Organizing Cognitive Memory for AI Agents — Liquid Loop theory implementation
|
|
5
5
|
Author: fishbook0001
|
|
6
6
|
Maintainer: fishbook0001
|
|
@@ -39,6 +39,8 @@ Dynamic: license-file
|
|
|
39
39
|
|
|
40
40
|
# Liquid Loop
|
|
41
41
|
|
|
42
|
+

|
|
43
|
+
|
|
42
44
|
> **Self-Organizing Cognitive Memory for AI Agents** — Zero LLM dependency, pure Python implementation of the Liquid Loop theory.
|
|
43
45
|
|
|
44
46
|
[](https://pypi.org/project/liquid-loop/)
|
|
@@ -89,6 +91,58 @@ RED (entropy ≥ 0.6) — 需清理
|
|
|
89
91
|
|
|
90
92
|
---
|
|
91
93
|
|
|
94
|
+
## v0.8 反证轨 + 时间动力学(液态循环核心)
|
|
95
|
+
|
|
96
|
+
液环 v0.8 从"静态结晶"升级为**自调节记忆动力学**:记忆不是对象,而是过程。
|
|
97
|
+
|
|
98
|
+
### 反证轨(Contradiction Track)
|
|
99
|
+
|
|
100
|
+
证据可标记与记忆的关系,打破"一致即真":
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from liquid_loop import WorkspaceState
|
|
104
|
+
|
|
105
|
+
state = WorkspaceState()
|
|
106
|
+
a = state.add_anchor("用户偏好", "红还是蓝")
|
|
107
|
+
state.add_evidence(a, "用户喜欢红色") # support (默认)
|
|
108
|
+
state.add_evidence(a, "用户喜欢红色") # 2 次一致 -> 结晶, stability≈0.67
|
|
109
|
+
mem = state.memories[0]
|
|
110
|
+
state.add_evidence(a, "用户喜欢蓝色",
|
|
111
|
+
relation="contradiction", # 冲突证据
|
|
112
|
+
target_memory_id=mem.id) # 显式指向被反驳的记忆
|
|
113
|
+
# -> mem.stability 降到 ≈0.40(一致增稳 / 冲突降稳)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
稳定性公式:`stability = support / (support + 2·contradiction + 1)`。
|
|
117
|
+
`contradiction_weight=2.0` 使单条冲突的降稳效力 ≈ 两条支持,直接对抗**群体幻觉固化**。
|
|
118
|
+
|
|
119
|
+
### 时间动力学 `state.step(dt)`
|
|
120
|
+
|
|
121
|
+
显式演化步(记忆随时间衰减 / 被新证据强化):
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
# 无新支持证据时,时间推进使稳定性衰减
|
|
125
|
+
state.step(dt=10, decay_rate=0.05)
|
|
126
|
+
# M(t+1) = M(t) + reinforcement − decay − contradiction_penalty
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
- 每条证据权重按 `(1−decay_rate)^dt` 衰减(无强化则价值流失,下限 0.05)
|
|
130
|
+
- 记忆在**自上次 step 以来获得新 support** 时恢复到固有稳定性(强化);否则时间衰减且不超过固有上限
|
|
131
|
+
|
|
132
|
+
### 实验验证(examples/experiments/,全部 PASS)
|
|
133
|
+
|
|
134
|
+
| 实验 | 问题 | 结论 |
|
|
135
|
+
|------|------|------|
|
|
136
|
+
| **E2 错误记忆恢复** | 能否主动遗忘错误并恢复? | 80%错误+20%真实 → 反证轨使错误 stability 0.67→0.30、正确升至 0.69 主导 ✅ |
|
|
137
|
+
| **E3 多 Agent 冲突** | mesh v2 能否形成稳定共享认知? | A support / B contradiction / C noise → 核心 claim 进入受争议稳定区(0.40),噪声隔离 ✅ |
|
|
138
|
+
| **E1 长期漂移** | 1000 轮随机注入是否收敛? | 300 轮压测 → 48 记忆(≤池×3)、plateau、LEI GREEN、avg_stab 0.80 ✅ |
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
python3 examples/experiments/run_all.py # 生成 REPORT_v0.8.json
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
92
146
|
## 快速开始
|
|
93
147
|
|
|
94
148
|
### 安装
|
|
@@ -173,9 +227,17 @@ print(health["CCI"], health["consensus_crystals"])
|
|
|
173
227
|
|
|
174
228
|
---
|
|
175
229
|
|
|
176
|
-
## 定位:Self-Regulating
|
|
230
|
+
## 定位:Self-Regulating Memory State Evolution
|
|
231
|
+
|
|
232
|
+
> **North-Star 公理(一切代码与论文围绕它校验):**
|
|
233
|
+
>
|
|
234
|
+
> **Liquid Loop is not a memory storage mechanism; it is a self-regulating memory state evolution mechanism.**
|
|
235
|
+
>
|
|
236
|
+
> (液环不是一种记忆存储机制,而是一种自调节的记忆状态演化机制。)
|
|
237
|
+
|
|
238
|
+
液环的本质不是"AI 意识 / 认知层",而是一套 **agent 系统的自调节持久记忆动力学(Self-Regulating Persistent Memory Dynamics for Agent Systems)**。`AuditChain + LEI(Entropy) + Memory decay + Contradiction Track` 组合成闭环,使记忆从"外部管理"转向"内部自组织"。
|
|
177
239
|
|
|
178
|
-
|
|
240
|
+
**边界(防止退化为"智能记忆管理器")**:记忆状态本身是一个**演化对象**,而非被管理的数据对象。市场已有的"记忆评分 / 自动删除 / 权重调整"范式把记忆当被管理的数据——液环要保护的是 **memory homeostasis(记忆稳态)**:记忆在变化环境中经 输入→吸收→凝聚→稳定→衰减→重构,自身维持一致性,而非被外部规则调度。
|
|
179
241
|
|
|
180
242
|
```
|
|
181
243
|
Input Evidence
|
|
@@ -267,9 +329,11 @@ pytest -v
|
|
|
267
329
|
## 路线图
|
|
268
330
|
|
|
269
331
|
- [x] 多 Agent 液环耦合(`liquid_loop.mesh` v2 共识协议,2026-07-15 落地)
|
|
270
|
-
- [
|
|
271
|
-
- [
|
|
272
|
-
- [
|
|
332
|
+
- [x] **[v0.8] 反证轨(Evidence Graph)**:Evidence 分 support / contradiction,一致增稳、冲突降稳,驱动 memory stability score(不再"一致即真")
|
|
333
|
+
- [x] **[v0.8] 显式时间动力学**:`M(t+1) = M(t) + reinforcement − decay − contradiction_penalty`,让记忆成为"过程"而非"对象"(真正的液态循环)
|
|
334
|
+
- [x] **[v0.8] 三实验全 PASS**:E2 错误记忆恢复 → E3 多 agent 冲突 → E1 长期漂移(见上节)
|
|
335
|
+
- [x] **[v0.9] 冲突检测 O(g²)→O(d²)**:`_detect_conflicts` 按 content 去重后只对 distinct 内容求两两重叠(d≤g),overlap_cache 复用;语义更纯净(度量不同论点分歧),大规模高频写入性能提升(非正确性变更)
|
|
336
|
+
- [x] **[v0.9] 液态算法正式落地**:时间动力学 / 反证轨 / 双轨成核在 v0.8 已实现并经 E1/E2/E3 三实验背书,v0.9 作为稳定版正式发布(README 顶部 Hero Banner 已上线)
|
|
273
337
|
- [ ] LoCoMo / LongMemEval 基准对比
|
|
274
338
|
- [ ] 边缘端部署优化(<50KB)
|
|
275
339
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Liquid Loop
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+
|
|
3
5
|
> **Self-Organizing Cognitive Memory for AI Agents** — Zero LLM dependency, pure Python implementation of the Liquid Loop theory.
|
|
4
6
|
|
|
5
7
|
[](https://pypi.org/project/liquid-loop/)
|
|
@@ -50,6 +52,58 @@ RED (entropy ≥ 0.6) — 需清理
|
|
|
50
52
|
|
|
51
53
|
---
|
|
52
54
|
|
|
55
|
+
## v0.8 反证轨 + 时间动力学(液态循环核心)
|
|
56
|
+
|
|
57
|
+
液环 v0.8 从"静态结晶"升级为**自调节记忆动力学**:记忆不是对象,而是过程。
|
|
58
|
+
|
|
59
|
+
### 反证轨(Contradiction Track)
|
|
60
|
+
|
|
61
|
+
证据可标记与记忆的关系,打破"一致即真":
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from liquid_loop import WorkspaceState
|
|
65
|
+
|
|
66
|
+
state = WorkspaceState()
|
|
67
|
+
a = state.add_anchor("用户偏好", "红还是蓝")
|
|
68
|
+
state.add_evidence(a, "用户喜欢红色") # support (默认)
|
|
69
|
+
state.add_evidence(a, "用户喜欢红色") # 2 次一致 -> 结晶, stability≈0.67
|
|
70
|
+
mem = state.memories[0]
|
|
71
|
+
state.add_evidence(a, "用户喜欢蓝色",
|
|
72
|
+
relation="contradiction", # 冲突证据
|
|
73
|
+
target_memory_id=mem.id) # 显式指向被反驳的记忆
|
|
74
|
+
# -> mem.stability 降到 ≈0.40(一致增稳 / 冲突降稳)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
稳定性公式:`stability = support / (support + 2·contradiction + 1)`。
|
|
78
|
+
`contradiction_weight=2.0` 使单条冲突的降稳效力 ≈ 两条支持,直接对抗**群体幻觉固化**。
|
|
79
|
+
|
|
80
|
+
### 时间动力学 `state.step(dt)`
|
|
81
|
+
|
|
82
|
+
显式演化步(记忆随时间衰减 / 被新证据强化):
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
# 无新支持证据时,时间推进使稳定性衰减
|
|
86
|
+
state.step(dt=10, decay_rate=0.05)
|
|
87
|
+
# M(t+1) = M(t) + reinforcement − decay − contradiction_penalty
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
- 每条证据权重按 `(1−decay_rate)^dt` 衰减(无强化则价值流失,下限 0.05)
|
|
91
|
+
- 记忆在**自上次 step 以来获得新 support** 时恢复到固有稳定性(强化);否则时间衰减且不超过固有上限
|
|
92
|
+
|
|
93
|
+
### 实验验证(examples/experiments/,全部 PASS)
|
|
94
|
+
|
|
95
|
+
| 实验 | 问题 | 结论 |
|
|
96
|
+
|------|------|------|
|
|
97
|
+
| **E2 错误记忆恢复** | 能否主动遗忘错误并恢复? | 80%错误+20%真实 → 反证轨使错误 stability 0.67→0.30、正确升至 0.69 主导 ✅ |
|
|
98
|
+
| **E3 多 Agent 冲突** | mesh v2 能否形成稳定共享认知? | A support / B contradiction / C noise → 核心 claim 进入受争议稳定区(0.40),噪声隔离 ✅ |
|
|
99
|
+
| **E1 长期漂移** | 1000 轮随机注入是否收敛? | 300 轮压测 → 48 记忆(≤池×3)、plateau、LEI GREEN、avg_stab 0.80 ✅ |
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
python3 examples/experiments/run_all.py # 生成 REPORT_v0.8.json
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
53
107
|
## 快速开始
|
|
54
108
|
|
|
55
109
|
### 安装
|
|
@@ -134,9 +188,17 @@ print(health["CCI"], health["consensus_crystals"])
|
|
|
134
188
|
|
|
135
189
|
---
|
|
136
190
|
|
|
137
|
-
## 定位:Self-Regulating
|
|
191
|
+
## 定位:Self-Regulating Memory State Evolution
|
|
192
|
+
|
|
193
|
+
> **North-Star 公理(一切代码与论文围绕它校验):**
|
|
194
|
+
>
|
|
195
|
+
> **Liquid Loop is not a memory storage mechanism; it is a self-regulating memory state evolution mechanism.**
|
|
196
|
+
>
|
|
197
|
+
> (液环不是一种记忆存储机制,而是一种自调节的记忆状态演化机制。)
|
|
198
|
+
|
|
199
|
+
液环的本质不是"AI 意识 / 认知层",而是一套 **agent 系统的自调节持久记忆动力学(Self-Regulating Persistent Memory Dynamics for Agent Systems)**。`AuditChain + LEI(Entropy) + Memory decay + Contradiction Track` 组合成闭环,使记忆从"外部管理"转向"内部自组织"。
|
|
138
200
|
|
|
139
|
-
|
|
201
|
+
**边界(防止退化为"智能记忆管理器")**:记忆状态本身是一个**演化对象**,而非被管理的数据对象。市场已有的"记忆评分 / 自动删除 / 权重调整"范式把记忆当被管理的数据——液环要保护的是 **memory homeostasis(记忆稳态)**:记忆在变化环境中经 输入→吸收→凝聚→稳定→衰减→重构,自身维持一致性,而非被外部规则调度。
|
|
140
202
|
|
|
141
203
|
```
|
|
142
204
|
Input Evidence
|
|
@@ -228,9 +290,11 @@ pytest -v
|
|
|
228
290
|
## 路线图
|
|
229
291
|
|
|
230
292
|
- [x] 多 Agent 液环耦合(`liquid_loop.mesh` v2 共识协议,2026-07-15 落地)
|
|
231
|
-
- [
|
|
232
|
-
- [
|
|
233
|
-
- [
|
|
293
|
+
- [x] **[v0.8] 反证轨(Evidence Graph)**:Evidence 分 support / contradiction,一致增稳、冲突降稳,驱动 memory stability score(不再"一致即真")
|
|
294
|
+
- [x] **[v0.8] 显式时间动力学**:`M(t+1) = M(t) + reinforcement − decay − contradiction_penalty`,让记忆成为"过程"而非"对象"(真正的液态循环)
|
|
295
|
+
- [x] **[v0.8] 三实验全 PASS**:E2 错误记忆恢复 → E3 多 agent 冲突 → E1 长期漂移(见上节)
|
|
296
|
+
- [x] **[v0.9] 冲突检测 O(g²)→O(d²)**:`_detect_conflicts` 按 content 去重后只对 distinct 内容求两两重叠(d≤g),overlap_cache 复用;语义更纯净(度量不同论点分歧),大规模高频写入性能提升(非正确性变更)
|
|
297
|
+
- [x] **[v0.9] 液态算法正式落地**:时间动力学 / 反证轨 / 双轨成核在 v0.8 已实现并经 E1/E2/E3 三实验背书,v0.9 作为稳定版正式发布(README 顶部 Hero Banner 已上线)
|
|
234
298
|
- [ ] LoCoMo / LongMemEval 基准对比
|
|
235
299
|
- [ ] 边缘端部署优化(<50KB)
|
|
236
300
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"""Liquid Loop — Workspace Cognitive Runtime v0.
|
|
2
|
-
__version__ = "0.
|
|
1
|
+
"""Liquid Loop — Workspace Cognitive Runtime v0.9.0 (反证轨 + 时间动力学, CPE-fused, SEAL dual-opt, dual-track multi-agent, MESH v2 integration)"""
|
|
2
|
+
__version__ = "0.9.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
|
|
@@ -249,16 +256,15 @@ class WorkspaceState:
|
|
|
249
256
|
return a
|
|
250
257
|
|
|
251
258
|
def add_evidence(self, anchor, content: str, quality: float = 1.0, agent_id: str = "",
|
|
252
|
-
dedup: bool = False
|
|
259
|
+
dedup: bool = False, relation: str = "support",
|
|
260
|
+
target_memory_id: str = "") -> Optional[Evidence]:
|
|
253
261
|
"""向指定锚点添加一条证据。
|
|
254
262
|
|
|
255
263
|
anchor 参数兼容:锚点名称(str) | 锚点ID(str) | Anchor对象
|
|
256
264
|
agent_id:多智能体共用写入者标识(缺省空=legacy/单实例)
|
|
257
|
-
dedup:幂等去重开关(默认 False
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
- True(mesh/API 层显式启用):同锚点+同内容+同 agent 已存在则复用,防网络重试/高频喂入膨胀。
|
|
261
|
-
幂等应由 mesh/API 层按需开启,核心模型默认不吞掉"重复观察"这一结晶信号。
|
|
265
|
+
dedup:幂等去重开关(默认 False,核心语义允许重复写入以触发结晶)。
|
|
266
|
+
relation:反证轨关系 "support"(一致, 默认) | "contradiction"(冲突) —— 见 v0.8 反证轨。
|
|
267
|
+
target_memory_id:relation="contradiction" 时可选显式指向被反驳的 memory。
|
|
262
268
|
"""
|
|
263
269
|
target = None
|
|
264
270
|
if isinstance(anchor, Anchor):
|
|
@@ -278,6 +284,7 @@ class WorkspaceState:
|
|
|
278
284
|
e = Evidence(
|
|
279
285
|
id=uid(), anchor_id=target.id, content=content,
|
|
280
286
|
quality=quality, timestamp=now(), agent_id=agent_id,
|
|
287
|
+
relation=relation, target_memory_id=target_memory_id,
|
|
281
288
|
)
|
|
282
289
|
self.evidences.append(e)
|
|
283
290
|
target.evidence_ids.append(e.id)
|
|
@@ -287,9 +294,10 @@ class WorkspaceState:
|
|
|
287
294
|
return e
|
|
288
295
|
|
|
289
296
|
def _on_evidence_added(self, anchor_id: str):
|
|
290
|
-
"""
|
|
297
|
+
"""证据添加后的统一后处理:衰减→成核→反证轨稳定性→冲突检测→预算稳态"""
|
|
291
298
|
self._decay_anchor(anchor_id)
|
|
292
299
|
self._nucleate(anchor_id)
|
|
300
|
+
self._update_memory_stability(anchor_id)
|
|
293
301
|
self._recalc_anchor(anchor_id)
|
|
294
302
|
self._detect_conflicts(anchor_id)
|
|
295
303
|
self._stabilize_budget()
|
|
@@ -389,7 +397,11 @@ class WorkspaceState:
|
|
|
389
397
|
阈值从环境变量 LIQUID_CONFLICT_THRESHOLD 读取(默认 0.2)。
|
|
390
398
|
复用 CPE 泛化防线思路:证据间平均关键词重叠 < threshold 且 >= 3 条 -> 潜在冲突/漂移。
|
|
391
399
|
保守处理:只标记'需人工确认',不武断判相反(避免过度工程化误报)。
|
|
392
|
-
|
|
400
|
+
|
|
401
|
+
性能(v0.9):原 O(g²) 全量成对扫描。相同 content 的两条证据重叠恒为 1.0,
|
|
402
|
+
对"内容分歧度"无信息量,故先按 content 去重为 distinct 集,只对 distinct 内容
|
|
403
|
+
求两两重叠 -> O(d²)(d = distinct content 数 ≤ g)。overlap_cache 复用。
|
|
404
|
+
语义更纯净:度量"不同论点间的分歧",重复写入不再稀释冲突信号。
|
|
393
405
|
"""
|
|
394
406
|
import os
|
|
395
407
|
conflict_threshold = float(os.environ.get('LIQUID_CONFLICT_THRESHOLD', '0.2'))
|
|
@@ -397,11 +409,20 @@ class WorkspaceState:
|
|
|
397
409
|
group = [e for e in self.evidences if e.anchor_id == anchor_id]
|
|
398
410
|
if len(group) < 3:
|
|
399
411
|
return
|
|
412
|
+
# ── O(g²) -> O(d²):content 去重,相同 content 对的重叠恒为 1.0 不参与分歧度量 ──
|
|
413
|
+
distinct: list = []
|
|
414
|
+
seen: set = set()
|
|
415
|
+
for e in group:
|
|
416
|
+
if e.content and e.content not in seen:
|
|
417
|
+
seen.add(e.content)
|
|
418
|
+
distinct.append(e.content)
|
|
419
|
+
n = len(distinct)
|
|
420
|
+
if n < 2:
|
|
421
|
+
return
|
|
400
422
|
overlaps = []
|
|
401
|
-
for i in range(
|
|
402
|
-
for j in range(i + 1,
|
|
403
|
-
|
|
404
|
-
overlaps.append(_keyword_overlap(group[i].content, group[j].content, self.overlap_cache))
|
|
423
|
+
for i in range(n):
|
|
424
|
+
for j in range(i + 1, n):
|
|
425
|
+
overlaps.append(_keyword_overlap(distinct[i], distinct[j], self.overlap_cache))
|
|
405
426
|
if not overlaps:
|
|
406
427
|
return
|
|
407
428
|
avg = sum(overlaps) / len(overlaps)
|
|
@@ -441,6 +462,77 @@ class WorkspaceState:
|
|
|
441
462
|
self.updated_at = now()
|
|
442
463
|
return m
|
|
443
464
|
|
|
465
|
+
# ─────────────────────────────────────────────────────────────
|
|
466
|
+
# v0.8 反证轨 + 时间动力学(液态循环核心)
|
|
467
|
+
# ─────────────────────────────────────────────────────────────
|
|
468
|
+
|
|
469
|
+
def _update_memory_stability(self, anchor_id: str):
|
|
470
|
+
"""反证轨:一致证据(support)增稳,冲突证据(contradiction)降稳。
|
|
471
|
+
|
|
472
|
+
稳定性 = support / (support + CONTRADICTION_WEIGHT * contradiction + 1)
|
|
473
|
+
- 同锚点下 content 相同的 support 证据计为支持
|
|
474
|
+
- relation="contradiction" 的证据计为反驳(显式 target_memory_id 或同锚点无指定则作用于该锚点结晶)
|
|
475
|
+
- 有 support 证据则刷新 last_reinforced(时间动力学强化信号)
|
|
476
|
+
"""
|
|
477
|
+
CONTRADICTION_WEIGHT = 2.0
|
|
478
|
+
group = [e for e in self.evidences if e.anchor_id == anchor_id and not e.archived]
|
|
479
|
+
group_ids = {e.id for e in group}
|
|
480
|
+
anchor_memories = [m for m in self.memories
|
|
481
|
+
if any(eid in group_ids for eid in m.evidence_ids)]
|
|
482
|
+
for m in anchor_memories:
|
|
483
|
+
supports = [e for e in group
|
|
484
|
+
if e.relation in ("support", "") and e.content == m.content]
|
|
485
|
+
if m.id:
|
|
486
|
+
contradicts = [e for e in group
|
|
487
|
+
if e.relation == "contradiction"
|
|
488
|
+
and (e.target_memory_id == m.id or not e.target_memory_id)]
|
|
489
|
+
else:
|
|
490
|
+
contradicts = [e for e in group
|
|
491
|
+
if e.relation == "contradiction" and not e.target_memory_id]
|
|
492
|
+
s = len(supports)
|
|
493
|
+
c = len(contradicts)
|
|
494
|
+
m.support_count = s
|
|
495
|
+
m.contradiction_count = c
|
|
496
|
+
m.stability = round(min(1.0, max(0.0,
|
|
497
|
+
s / (s + CONTRADICTION_WEIGHT * c + 1))), 3)
|
|
498
|
+
if supports:
|
|
499
|
+
m.last_reinforced = max(e.timestamp for e in supports)
|
|
500
|
+
|
|
501
|
+
def step(self, dt: int = 1, decay_rate: float = 0.05):
|
|
502
|
+
"""显式时间动力学步(v0.8 液态循环核心):
|
|
503
|
+
|
|
504
|
+
M(t+1) = M(t) + reinforcement − decay − contradiction_penalty
|
|
505
|
+
|
|
506
|
+
- 每条证据按 (1−decay_rate)^dt 衰减权重(无强化则价值流失,下限 0.05)
|
|
507
|
+
- 每个 memory 按 support/contradiction 计数重算固有稳定性(矛盾惩罚持续作用);
|
|
508
|
+
若本轮有 support 证据 → 稳定性恢复到固有值(强化);否则按时间衰减(无强化流失)
|
|
509
|
+
- 重算锚点稳定性与审计更新时间
|
|
510
|
+
"""
|
|
511
|
+
# 1. 证据权重时间衰减
|
|
512
|
+
for e in self.evidences:
|
|
513
|
+
if not e.archived:
|
|
514
|
+
e.weight = max(e.weight * ((1 - decay_rate) ** dt), 0.05)
|
|
515
|
+
# 2. 记忆稳定性:固有(计数驱动) + 时间衰减/强化
|
|
516
|
+
for a in self.anchors:
|
|
517
|
+
self._update_memory_stability(a.id)
|
|
518
|
+
last_step = getattr(self, "_last_step_at", "")
|
|
519
|
+
now_dt = datetime.now(timezone.utc)
|
|
520
|
+
for m in self.memories:
|
|
521
|
+
intrinsic = m.stability # _update_memory_stability 已写入固有稳定性
|
|
522
|
+
# 强化 = 自上次 step 以来有过新 support 证据(last_reinforced 晚于上次 step)
|
|
523
|
+
reinforced = bool(m.last_reinforced) and (not last_step or m.last_reinforced > last_step)
|
|
524
|
+
if reinforced:
|
|
525
|
+
m.stability = intrinsic # 被强化:恢复到固有稳定性
|
|
526
|
+
else:
|
|
527
|
+
# 无新强化:时间衰减,且不超过固有上限
|
|
528
|
+
m.stability = round(max(0.0, min(intrinsic,
|
|
529
|
+
m.stability * ((1 - decay_rate) ** dt))), 3)
|
|
530
|
+
self._last_step_at = now()
|
|
531
|
+
# 3. 重算锚点稳定性
|
|
532
|
+
for a in self.anchors:
|
|
533
|
+
self._recalc_anchor(a.id)
|
|
534
|
+
self.updated_at = now()
|
|
535
|
+
|
|
444
536
|
|
|
445
537
|
# ==============================================================================
|
|
446
538
|
# 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.9.0
|
|
4
4
|
Summary: Self-Organizing Cognitive Memory for AI Agents — Liquid Loop theory implementation
|
|
5
5
|
Author: fishbook0001
|
|
6
6
|
Maintainer: fishbook0001
|
|
@@ -39,6 +39,8 @@ Dynamic: license-file
|
|
|
39
39
|
|
|
40
40
|
# Liquid Loop
|
|
41
41
|
|
|
42
|
+

|
|
43
|
+
|
|
42
44
|
> **Self-Organizing Cognitive Memory for AI Agents** — Zero LLM dependency, pure Python implementation of the Liquid Loop theory.
|
|
43
45
|
|
|
44
46
|
[](https://pypi.org/project/liquid-loop/)
|
|
@@ -89,6 +91,58 @@ RED (entropy ≥ 0.6) — 需清理
|
|
|
89
91
|
|
|
90
92
|
---
|
|
91
93
|
|
|
94
|
+
## v0.8 反证轨 + 时间动力学(液态循环核心)
|
|
95
|
+
|
|
96
|
+
液环 v0.8 从"静态结晶"升级为**自调节记忆动力学**:记忆不是对象,而是过程。
|
|
97
|
+
|
|
98
|
+
### 反证轨(Contradiction Track)
|
|
99
|
+
|
|
100
|
+
证据可标记与记忆的关系,打破"一致即真":
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from liquid_loop import WorkspaceState
|
|
104
|
+
|
|
105
|
+
state = WorkspaceState()
|
|
106
|
+
a = state.add_anchor("用户偏好", "红还是蓝")
|
|
107
|
+
state.add_evidence(a, "用户喜欢红色") # support (默认)
|
|
108
|
+
state.add_evidence(a, "用户喜欢红色") # 2 次一致 -> 结晶, stability≈0.67
|
|
109
|
+
mem = state.memories[0]
|
|
110
|
+
state.add_evidence(a, "用户喜欢蓝色",
|
|
111
|
+
relation="contradiction", # 冲突证据
|
|
112
|
+
target_memory_id=mem.id) # 显式指向被反驳的记忆
|
|
113
|
+
# -> mem.stability 降到 ≈0.40(一致增稳 / 冲突降稳)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
稳定性公式:`stability = support / (support + 2·contradiction + 1)`。
|
|
117
|
+
`contradiction_weight=2.0` 使单条冲突的降稳效力 ≈ 两条支持,直接对抗**群体幻觉固化**。
|
|
118
|
+
|
|
119
|
+
### 时间动力学 `state.step(dt)`
|
|
120
|
+
|
|
121
|
+
显式演化步(记忆随时间衰减 / 被新证据强化):
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
# 无新支持证据时,时间推进使稳定性衰减
|
|
125
|
+
state.step(dt=10, decay_rate=0.05)
|
|
126
|
+
# M(t+1) = M(t) + reinforcement − decay − contradiction_penalty
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
- 每条证据权重按 `(1−decay_rate)^dt` 衰减(无强化则价值流失,下限 0.05)
|
|
130
|
+
- 记忆在**自上次 step 以来获得新 support** 时恢复到固有稳定性(强化);否则时间衰减且不超过固有上限
|
|
131
|
+
|
|
132
|
+
### 实验验证(examples/experiments/,全部 PASS)
|
|
133
|
+
|
|
134
|
+
| 实验 | 问题 | 结论 |
|
|
135
|
+
|------|------|------|
|
|
136
|
+
| **E2 错误记忆恢复** | 能否主动遗忘错误并恢复? | 80%错误+20%真实 → 反证轨使错误 stability 0.67→0.30、正确升至 0.69 主导 ✅ |
|
|
137
|
+
| **E3 多 Agent 冲突** | mesh v2 能否形成稳定共享认知? | A support / B contradiction / C noise → 核心 claim 进入受争议稳定区(0.40),噪声隔离 ✅ |
|
|
138
|
+
| **E1 长期漂移** | 1000 轮随机注入是否收敛? | 300 轮压测 → 48 记忆(≤池×3)、plateau、LEI GREEN、avg_stab 0.80 ✅ |
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
python3 examples/experiments/run_all.py # 生成 REPORT_v0.8.json
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
92
146
|
## 快速开始
|
|
93
147
|
|
|
94
148
|
### 安装
|
|
@@ -173,9 +227,17 @@ print(health["CCI"], health["consensus_crystals"])
|
|
|
173
227
|
|
|
174
228
|
---
|
|
175
229
|
|
|
176
|
-
## 定位:Self-Regulating
|
|
230
|
+
## 定位:Self-Regulating Memory State Evolution
|
|
231
|
+
|
|
232
|
+
> **North-Star 公理(一切代码与论文围绕它校验):**
|
|
233
|
+
>
|
|
234
|
+
> **Liquid Loop is not a memory storage mechanism; it is a self-regulating memory state evolution mechanism.**
|
|
235
|
+
>
|
|
236
|
+
> (液环不是一种记忆存储机制,而是一种自调节的记忆状态演化机制。)
|
|
237
|
+
|
|
238
|
+
液环的本质不是"AI 意识 / 认知层",而是一套 **agent 系统的自调节持久记忆动力学(Self-Regulating Persistent Memory Dynamics for Agent Systems)**。`AuditChain + LEI(Entropy) + Memory decay + Contradiction Track` 组合成闭环,使记忆从"外部管理"转向"内部自组织"。
|
|
177
239
|
|
|
178
|
-
|
|
240
|
+
**边界(防止退化为"智能记忆管理器")**:记忆状态本身是一个**演化对象**,而非被管理的数据对象。市场已有的"记忆评分 / 自动删除 / 权重调整"范式把记忆当被管理的数据——液环要保护的是 **memory homeostasis(记忆稳态)**:记忆在变化环境中经 输入→吸收→凝聚→稳定→衰减→重构,自身维持一致性,而非被外部规则调度。
|
|
179
241
|
|
|
180
242
|
```
|
|
181
243
|
Input Evidence
|
|
@@ -267,9 +329,11 @@ pytest -v
|
|
|
267
329
|
## 路线图
|
|
268
330
|
|
|
269
331
|
- [x] 多 Agent 液环耦合(`liquid_loop.mesh` v2 共识协议,2026-07-15 落地)
|
|
270
|
-
- [
|
|
271
|
-
- [
|
|
272
|
-
- [
|
|
332
|
+
- [x] **[v0.8] 反证轨(Evidence Graph)**:Evidence 分 support / contradiction,一致增稳、冲突降稳,驱动 memory stability score(不再"一致即真")
|
|
333
|
+
- [x] **[v0.8] 显式时间动力学**:`M(t+1) = M(t) + reinforcement − decay − contradiction_penalty`,让记忆成为"过程"而非"对象"(真正的液态循环)
|
|
334
|
+
- [x] **[v0.8] 三实验全 PASS**:E2 错误记忆恢复 → E3 多 agent 冲突 → E1 长期漂移(见上节)
|
|
335
|
+
- [x] **[v0.9] 冲突检测 O(g²)→O(d²)**:`_detect_conflicts` 按 content 去重后只对 distinct 内容求两两重叠(d≤g),overlap_cache 复用;语义更纯净(度量不同论点分歧),大规模高频写入性能提升(非正确性变更)
|
|
336
|
+
- [x] **[v0.9] 液态算法正式落地**:时间动力学 / 反证轨 / 双轨成核在 v0.8 已实现并经 E1/E2/E3 三实验背书,v0.9 作为稳定版正式发布(README 顶部 Hero Banner 已上线)
|
|
273
337
|
- [ ] LoCoMo / LongMemEval 基准对比
|
|
274
338
|
- [ ] 边缘端部署优化(<50KB)
|
|
275
339
|
|
|
@@ -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.9.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
|