liquid-loop 0.7.1__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.1 → liquid_loop-0.8.0}/PKG-INFO +57 -4
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/README.md +56 -3
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/liquid_loop/__init__.py +2 -2
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/liquid_loop/workspace.py +86 -7
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/liquid_loop.egg-info/PKG-INFO +57 -4
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/pyproject.toml +1 -1
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/LICENSE +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/liquid_loop/__main__.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/liquid_loop/cli.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/liquid_loop/cognitive_budget.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/liquid_loop/entropy.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/liquid_loop/mesh/__init__.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/liquid_loop/mesh/v2.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/liquid_loop/storage.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/liquid_loop.egg-info/SOURCES.txt +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/liquid_loop.egg-info/dependency_links.txt +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/liquid_loop.egg-info/entry_points.txt +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/liquid_loop.egg-info/requires.txt +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/liquid_loop.egg-info/top_level.txt +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/setup.cfg +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/tests/test_consensus_expansion.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/tests/test_entropy.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/tests/test_nucleate_dual_track.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/tests/test_peek_seal.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/tests/test_seal_persistence.py +0 -0
- {liquid_loop-0.7.1 → liquid_loop-0.8.0}/tests/test_self_evolve.py +0 -0
- {liquid_loop-0.7.1 → 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
|
|
@@ -89,6 +89,58 @@ RED (entropy ≥ 0.6) — 需清理
|
|
|
89
89
|
|
|
90
90
|
---
|
|
91
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
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
92
144
|
## 快速开始
|
|
93
145
|
|
|
94
146
|
### 安装
|
|
@@ -267,9 +319,10 @@ pytest -v
|
|
|
267
319
|
## 路线图
|
|
268
320
|
|
|
269
321
|
- [x] 多 Agent 液环耦合(`liquid_loop.mesh` v2 共识协议,2026-07-15 落地)
|
|
270
|
-
- [
|
|
271
|
-
- [
|
|
272
|
-
- [
|
|
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²) 两两扫描改为增量/采样(大规模高频写入性能,非正确性)
|
|
273
326
|
- [ ] LoCoMo / LongMemEval 基准对比
|
|
274
327
|
- [ ] 边缘端部署优化(<50KB)
|
|
275
328
|
|
|
@@ -50,6 +50,58 @@ RED (entropy ≥ 0.6) — 需清理
|
|
|
50
50
|
|
|
51
51
|
---
|
|
52
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
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
53
105
|
## 快速开始
|
|
54
106
|
|
|
55
107
|
### 安装
|
|
@@ -228,9 +280,10 @@ pytest -v
|
|
|
228
280
|
## 路线图
|
|
229
281
|
|
|
230
282
|
- [x] 多 Agent 液环耦合(`liquid_loop.mesh` v2 共识协议,2026-07-15 落地)
|
|
231
|
-
- [
|
|
232
|
-
- [
|
|
233
|
-
- [
|
|
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²) 两两扫描改为增量/采样(大规模高频写入性能,非正确性)
|
|
234
287
|
- [ ] LoCoMo / LongMemEval 基准对比
|
|
235
288
|
- [ ] 边缘端部署优化(<50KB)
|
|
236
289
|
|
|
@@ -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
|
|
@@ -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()
|
|
@@ -441,6 +449,77 @@ class WorkspaceState:
|
|
|
441
449
|
self.updated_at = now()
|
|
442
450
|
return m
|
|
443
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
|
+
|
|
444
523
|
|
|
445
524
|
# ==============================================================================
|
|
446
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
|
|
@@ -89,6 +89,58 @@ RED (entropy ≥ 0.6) — 需清理
|
|
|
89
89
|
|
|
90
90
|
---
|
|
91
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
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
92
144
|
## 快速开始
|
|
93
145
|
|
|
94
146
|
### 安装
|
|
@@ -267,9 +319,10 @@ pytest -v
|
|
|
267
319
|
## 路线图
|
|
268
320
|
|
|
269
321
|
- [x] 多 Agent 液环耦合(`liquid_loop.mesh` v2 共识协议,2026-07-15 落地)
|
|
270
|
-
- [
|
|
271
|
-
- [
|
|
272
|
-
- [
|
|
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²) 两两扫描改为增量/采样(大规模高频写入性能,非正确性)
|
|
273
326
|
- [ ] LoCoMo / LongMemEval 基准对比
|
|
274
327
|
- [ ] 边缘端部署优化(<50KB)
|
|
275
328
|
|
|
@@ -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
|