amrita_plugin_memory 0.3.0__tar.gz → 0.3.1__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.
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/PKG-INFO +55 -42
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/README.md +54 -41
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/rethinking/_state.py +16 -0
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/rethinking/runner.py +27 -5
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/rethinking/schemas.py +47 -0
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/rethinking/tools.py +64 -5
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory.egg-info/PKG-INFO +55 -42
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/pyproject.toml +1 -1
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/LICENSE +0 -0
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/__init__.py +0 -0
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/config.py +0 -0
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/embed.py +0 -0
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/matchers.py +0 -0
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/rethinking/__init__.py +0 -0
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/rethinking/backend.py +0 -0
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/rethinking/consts.py +0 -0
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/rethinking/hooks.py +0 -0
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/rethinking/knowledge.py +0 -0
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/rethinking/nodes.py +0 -0
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/rethinking/types.py +0 -0
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/tools.py +0 -0
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/vector.py +0 -0
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory.egg-info/SOURCES.txt +0 -0
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory.egg-info/dependency_links.txt +0 -0
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory.egg-info/requires.txt +0 -0
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory.egg-info/top_level.txt +0 -0
- {amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: amrita_plugin_memory
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: Amrita长期记忆插件
|
|
5
5
|
Requires-Python: <3.14,>=3.10
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -71,6 +71,8 @@ allow_send_to_user = true
|
|
|
71
71
|
enable_knowledge = false
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
+
> 知识库依赖潜意识推理——当 `enabled = false` 时,知识库也会自动禁用。
|
|
75
|
+
|
|
74
76
|
### 4. 验证
|
|
75
77
|
|
|
76
78
|
观察日志中 `[Subconscious]` 前缀的输出:
|
|
@@ -95,6 +97,7 @@ flowchart TB
|
|
|
95
97
|
S_Write --> ChromaDB[("ChromaDB<br/>向量数据库")]
|
|
96
98
|
S_Read --> ChromaDB
|
|
97
99
|
S_Mut --> ChromaDB
|
|
100
|
+
S_LLM -->|"knowledge_list/read/search"| ChromaDB
|
|
98
101
|
end
|
|
99
102
|
|
|
100
103
|
subgraph Subconscious["底层:Subconscious Reasoning"]
|
|
@@ -112,7 +115,8 @@ flowchart TB
|
|
|
112
115
|
AgentLoop --> Profile["用户画像<br/>行级增量更新"]
|
|
113
116
|
end
|
|
114
117
|
|
|
115
|
-
Surface -->|"
|
|
118
|
+
Surface -->|"knowledge_suggest"| SuggQueue["知识建议队列"]
|
|
119
|
+
SuggQueue --> AgentLoop
|
|
116
120
|
Surface -.->|"共享 ChromaDB"| Subconscious
|
|
117
121
|
Runner -->|"持久化状态"| CachedRepo["CachedUserDataRepository"]
|
|
118
122
|
Runner -->|"usage 统计"| Insights["InsightsModel<br/>全局 Token 统计"]
|
|
@@ -150,7 +154,16 @@ flowchart TB
|
|
|
150
154
|
|
|
151
155
|
### 共享:全局知识库
|
|
152
156
|
|
|
153
|
-
|
|
157
|
+
知识库是**表层和潜意识双层共享**的资源。读取操作(`list`/`read`/`search`)通过双重 `@on_tools` 注册,对话 LLM 和后台 Agent 均可直接调用。**写入操作**(`create`/`update`/`delete`)仅限潜意识 Agent——表层通过 `knowledge_suggest` 提交建议,由 Agent 在下一轮推理中审查后决定是否实际写入:
|
|
158
|
+
|
|
159
|
+
```mermaid
|
|
160
|
+
flowchart LR
|
|
161
|
+
ChatLLM["对话 LLM"] -->|"knowledge_suggest"| Queue["建议队列<br/>(持久化)"]
|
|
162
|
+
Queue -->|"subconscious_read_suggestions"| Agent["Subconscious Agent<br/>下一轮推理"]
|
|
163
|
+
Agent -->|"审查"| Decision{"值得记录?"}
|
|
164
|
+
Decision -->|"Yes"| SubCreate["subconscious_knowledge_create"]
|
|
165
|
+
Decision -->|"No"| Drop["忽略"]
|
|
166
|
+
```
|
|
154
167
|
|
|
155
168
|
每条知识由三个组件共同管理:
|
|
156
169
|
|
|
@@ -195,23 +208,21 @@ flowchart LR
|
|
|
195
208
|
|
|
196
209
|
### 表层工具(`tools.py`)
|
|
197
210
|
|
|
198
|
-
| 工具
|
|
199
|
-
|
|
|
200
|
-
| `write_memory`
|
|
201
|
-
| `read_memory`
|
|
202
|
-
| `update_memory`
|
|
203
|
-
| `delete_memory`
|
|
204
|
-
| `list_memory`
|
|
205
|
-
| `knowledge_list`
|
|
206
|
-
| `knowledge_read`
|
|
207
|
-
| `
|
|
208
|
-
| `
|
|
209
|
-
| `knowledge_delete` | kid |
|
|
210
|
-
| `knowledge_search` | query, top_k? |
|
|
211
|
+
| 工具 | 参数 |
|
|
212
|
+
| ------------------- | -------------------------------------------- |
|
|
213
|
+
| `write_memory` | content, tags, importance(enum), scope(enum) |
|
|
214
|
+
| `read_memory` | query, top_k(5), importance?, scope(enum) |
|
|
215
|
+
| `update_memory` | id, scope, content?, tags?, importance? |
|
|
216
|
+
| `delete_memory` | id, scope |
|
|
217
|
+
| `list_memory` | limit, scope |
|
|
218
|
+
| `knowledge_list` | — |
|
|
219
|
+
| `knowledge_read` | kid, start_line?, end_line? |
|
|
220
|
+
| `knowledge_search` | query, top_k? |
|
|
221
|
+
| `knowledge_suggest` | action, title, summary, body, reason |
|
|
211
222
|
|
|
212
223
|
### 潜意识工具(`rethinking/tools.py`)
|
|
213
224
|
|
|
214
|
-
记忆和 session/画像工具注册在隔离的 `_SUBCONSCIOUS_TOOLS`
|
|
225
|
+
记忆和 session/画像工具注册在隔离的 `_SUBCONSCIOUS_TOOLS` 上。知识库中 `list`/`read`/`search` 通过双重注册同时暴露给表层和潜意识;`create`/`update`/`delete` 仅潜意识可用(表层通过 `knowledge_suggest` 提交建议):
|
|
215
226
|
|
|
216
227
|
| 工具 | 用途 |
|
|
217
228
|
| -------------------------------- | -------------------------------------- |
|
|
@@ -230,6 +241,7 @@ flowchart LR
|
|
|
230
241
|
| `subconscious_knowledge_create` | 创建知识条目 |
|
|
231
242
|
| `subconscious_knowledge_update` | 更新知识条目 |
|
|
232
243
|
| `subconscious_knowledge_delete` | 删除知识条目 |
|
|
244
|
+
| `subconscious_read_suggestions` | 读取待审查的知识建议(读取后清空) |
|
|
233
245
|
| `subconscious_knowledge_search` | 语义搜索知识库 |
|
|
234
246
|
| `subconscious_read_sessions` | 读取归档 sessions(LLM 摘要) |
|
|
235
247
|
| `subconscious_get_profile` | 读取用户画像(行滑动窗口) |
|
|
@@ -291,8 +303,9 @@ $$\text{delay} = \min(\text{base} \times \text{multiplier}^{\text{penalty}-1},\
|
|
|
291
303
|
|
|
292
304
|
`SubconsciousRunner` 将 ChatObject 作为数据容器,注入自定义 `SubconsciousBackend` + Core `ReActAgentStrategy`:
|
|
293
305
|
|
|
294
|
-
```
|
|
295
|
-
|
|
306
|
+
```mermaid
|
|
307
|
+
flowchart TD
|
|
308
|
+
LOAD_STATE --> JINJA2_RENDER --> LIMITING_MEMORY --> BUILD_MESSAGE --> REACT_BLOCK
|
|
296
309
|
```
|
|
297
310
|
|
|
298
311
|
`LIMITING_MEMORY` 在 Agent Loop 之前运行 Core `MemoryLimiter`:消息截断 → 摘要生成。`_build_config()` 将 `enable_memory_compress` 和 `loop_detect_threshold` 注入 `AmritaConfig`。
|
|
@@ -344,27 +357,27 @@ knowledge_collection_name = "amrita_global_knowledge"
|
|
|
344
357
|
enable_knowledge = true
|
|
345
358
|
```
|
|
346
359
|
|
|
347
|
-
| 字段 | 默认值 | 说明
|
|
348
|
-
| ---------------------------- | -------------------------------------- |
|
|
349
|
-
| `enabled` | `false` | 是否启用潜意识循环
|
|
350
|
-
| `target_user_id` | `""` | 目标用户 ID,为空则不启动
|
|
351
|
-
| `allowed_tools` | `[]` | 额外可用工具(从全局拉取)
|
|
352
|
-
| `max_iterations` | `10` | 单轮 ReAct 最大步数(预留)
|
|
353
|
-
| `loop_detect_threshold` | `3` | 传入 Core `loop_reasoning_trigger`
|
|
354
|
-
| `rethink_base_delay_minutes` | `30` | 惩罚退避基数
|
|
355
|
-
| `rethink_penalty_multiplier` | `1.5` | 惩罚指数倍率
|
|
356
|
-
| `rethink_max_delay_minutes` | `1440` | 惩罚延迟上限(1 天)
|
|
357
|
-
| `prompt_file` | `"prompt/subconscious_main.md.jinja2"` | 主推理提示词模板
|
|
358
|
-
| `prompt_send_file` | `"prompt/subconscious_send.md.jinja2"` | 主动消息生成模板
|
|
359
|
-
| `prompt_knowledge_file` | `"prompt/knowledge_guide.md.jinja2"` | 知识库使用指南
|
|
360
|
-
| `prompt_profile_file` | `"prompt/profile_guide.md.jinja2"` | 画像构建指南
|
|
361
|
-
| `enable_memory_compress` | `true` | 传入 Core `enable_memory_abstract`
|
|
362
|
-
| `allow_send_to_user` | `false` | 允许 Agent 主动发私聊消息
|
|
363
|
-
| `memory_warn_threshold` | `100` | ChromaDB 超此数量注入压缩提示
|
|
364
|
-
| `max_abstracts` | `5` | 摘要滑动窗口大小
|
|
365
|
-
| `knowledge_max_chars` | `10000` | 知识条目单条正文上限
|
|
366
|
-
| `knowledge_collection_name` | `"amrita_global_knowledge"` | ChromaDB 知识库 collection
|
|
367
|
-
| `enable_knowledge` | `true` |
|
|
360
|
+
| 字段 | 默认值 | 说明 |
|
|
361
|
+
| ---------------------------- | -------------------------------------- | --------------------------------------- |
|
|
362
|
+
| `enabled` | `false` | 是否启用潜意识循环 |
|
|
363
|
+
| `target_user_id` | `""` | 目标用户 ID,为空则不启动 |
|
|
364
|
+
| `allowed_tools` | `[]` | 额外可用工具(从全局拉取) |
|
|
365
|
+
| `max_iterations` | `10` | 单轮 ReAct 最大步数(预留) |
|
|
366
|
+
| `loop_detect_threshold` | `3` | 传入 Core `loop_reasoning_trigger` |
|
|
367
|
+
| `rethink_base_delay_minutes` | `30` | 惩罚退避基数 |
|
|
368
|
+
| `rethink_penalty_multiplier` | `1.5` | 惩罚指数倍率 |
|
|
369
|
+
| `rethink_max_delay_minutes` | `1440` | 惩罚延迟上限(1 天) |
|
|
370
|
+
| `prompt_file` | `"prompt/subconscious_main.md.jinja2"` | 主推理提示词模板 |
|
|
371
|
+
| `prompt_send_file` | `"prompt/subconscious_send.md.jinja2"` | 主动消息生成模板 |
|
|
372
|
+
| `prompt_knowledge_file` | `"prompt/knowledge_guide.md.jinja2"` | 知识库使用指南 |
|
|
373
|
+
| `prompt_profile_file` | `"prompt/profile_guide.md.jinja2"` | 画像构建指南 |
|
|
374
|
+
| `enable_memory_compress` | `true` | 传入 Core `enable_memory_abstract` |
|
|
375
|
+
| `allow_send_to_user` | `false` | 允许 Agent 主动发私聊消息 |
|
|
376
|
+
| `memory_warn_threshold` | `100` | ChromaDB 超此数量注入压缩提示 |
|
|
377
|
+
| `max_abstracts` | `5` | 摘要滑动窗口大小 |
|
|
378
|
+
| `knowledge_max_chars` | `10000` | 知识条目单条正文上限 |
|
|
379
|
+
| `knowledge_collection_name` | `"amrita_global_knowledge"` | ChromaDB 知识库 collection |
|
|
380
|
+
| `enable_knowledge` | `true` | 是否启用全局知识库(需 `enabled=true`) |
|
|
368
381
|
|
|
369
382
|
### 提示词模板
|
|
370
383
|
|
|
@@ -374,8 +387,8 @@ enable_knowledge = true
|
|
|
374
387
|
| ----------------------------- | ------------ | ------------------------------------------------------------------------------------------------ |
|
|
375
388
|
| `subconscious_main.md.jinja2` | 主推理提示词 | `character_prompt`, `last_run`, `last_abstracts`, `current_time`, `target_user_id`, `total_runs` |
|
|
376
389
|
| `subconscious_send.md.jinja2` | 主动消息生成 | `character_prompt`, `intent`, `memory_context`, `current_time` |
|
|
377
|
-
| `knowledge_guide.md.jinja2` | 知识库指南 |
|
|
378
|
-
| `profile_guide.md.jinja2` | 画像构建指南 |
|
|
390
|
+
| `knowledge_guide.md.jinja2` | 知识库指南 | `current_time`, `target_user_id` |
|
|
391
|
+
| `profile_guide.md.jinja2` | 画像构建指南 | `current_time`, `target_user_id` |
|
|
379
392
|
|
|
380
393
|
### 环境变量(`.env`)
|
|
381
394
|
|
|
@@ -54,6 +54,8 @@ allow_send_to_user = true
|
|
|
54
54
|
enable_knowledge = false
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
+
> 知识库依赖潜意识推理——当 `enabled = false` 时,知识库也会自动禁用。
|
|
58
|
+
|
|
57
59
|
### 4. 验证
|
|
58
60
|
|
|
59
61
|
观察日志中 `[Subconscious]` 前缀的输出:
|
|
@@ -78,6 +80,7 @@ flowchart TB
|
|
|
78
80
|
S_Write --> ChromaDB[("ChromaDB<br/>向量数据库")]
|
|
79
81
|
S_Read --> ChromaDB
|
|
80
82
|
S_Mut --> ChromaDB
|
|
83
|
+
S_LLM -->|"knowledge_list/read/search"| ChromaDB
|
|
81
84
|
end
|
|
82
85
|
|
|
83
86
|
subgraph Subconscious["底层:Subconscious Reasoning"]
|
|
@@ -95,7 +98,8 @@ flowchart TB
|
|
|
95
98
|
AgentLoop --> Profile["用户画像<br/>行级增量更新"]
|
|
96
99
|
end
|
|
97
100
|
|
|
98
|
-
Surface -->|"
|
|
101
|
+
Surface -->|"knowledge_suggest"| SuggQueue["知识建议队列"]
|
|
102
|
+
SuggQueue --> AgentLoop
|
|
99
103
|
Surface -.->|"共享 ChromaDB"| Subconscious
|
|
100
104
|
Runner -->|"持久化状态"| CachedRepo["CachedUserDataRepository"]
|
|
101
105
|
Runner -->|"usage 统计"| Insights["InsightsModel<br/>全局 Token 统计"]
|
|
@@ -133,7 +137,16 @@ flowchart TB
|
|
|
133
137
|
|
|
134
138
|
### 共享:全局知识库
|
|
135
139
|
|
|
136
|
-
|
|
140
|
+
知识库是**表层和潜意识双层共享**的资源。读取操作(`list`/`read`/`search`)通过双重 `@on_tools` 注册,对话 LLM 和后台 Agent 均可直接调用。**写入操作**(`create`/`update`/`delete`)仅限潜意识 Agent——表层通过 `knowledge_suggest` 提交建议,由 Agent 在下一轮推理中审查后决定是否实际写入:
|
|
141
|
+
|
|
142
|
+
```mermaid
|
|
143
|
+
flowchart LR
|
|
144
|
+
ChatLLM["对话 LLM"] -->|"knowledge_suggest"| Queue["建议队列<br/>(持久化)"]
|
|
145
|
+
Queue -->|"subconscious_read_suggestions"| Agent["Subconscious Agent<br/>下一轮推理"]
|
|
146
|
+
Agent -->|"审查"| Decision{"值得记录?"}
|
|
147
|
+
Decision -->|"Yes"| SubCreate["subconscious_knowledge_create"]
|
|
148
|
+
Decision -->|"No"| Drop["忽略"]
|
|
149
|
+
```
|
|
137
150
|
|
|
138
151
|
每条知识由三个组件共同管理:
|
|
139
152
|
|
|
@@ -178,23 +191,21 @@ flowchart LR
|
|
|
178
191
|
|
|
179
192
|
### 表层工具(`tools.py`)
|
|
180
193
|
|
|
181
|
-
| 工具
|
|
182
|
-
|
|
|
183
|
-
| `write_memory`
|
|
184
|
-
| `read_memory`
|
|
185
|
-
| `update_memory`
|
|
186
|
-
| `delete_memory`
|
|
187
|
-
| `list_memory`
|
|
188
|
-
| `knowledge_list`
|
|
189
|
-
| `knowledge_read`
|
|
190
|
-
| `
|
|
191
|
-
| `
|
|
192
|
-
| `knowledge_delete` | kid |
|
|
193
|
-
| `knowledge_search` | query, top_k? |
|
|
194
|
+
| 工具 | 参数 |
|
|
195
|
+
| ------------------- | -------------------------------------------- |
|
|
196
|
+
| `write_memory` | content, tags, importance(enum), scope(enum) |
|
|
197
|
+
| `read_memory` | query, top_k(5), importance?, scope(enum) |
|
|
198
|
+
| `update_memory` | id, scope, content?, tags?, importance? |
|
|
199
|
+
| `delete_memory` | id, scope |
|
|
200
|
+
| `list_memory` | limit, scope |
|
|
201
|
+
| `knowledge_list` | — |
|
|
202
|
+
| `knowledge_read` | kid, start_line?, end_line? |
|
|
203
|
+
| `knowledge_search` | query, top_k? |
|
|
204
|
+
| `knowledge_suggest` | action, title, summary, body, reason |
|
|
194
205
|
|
|
195
206
|
### 潜意识工具(`rethinking/tools.py`)
|
|
196
207
|
|
|
197
|
-
记忆和 session/画像工具注册在隔离的 `_SUBCONSCIOUS_TOOLS`
|
|
208
|
+
记忆和 session/画像工具注册在隔离的 `_SUBCONSCIOUS_TOOLS` 上。知识库中 `list`/`read`/`search` 通过双重注册同时暴露给表层和潜意识;`create`/`update`/`delete` 仅潜意识可用(表层通过 `knowledge_suggest` 提交建议):
|
|
198
209
|
|
|
199
210
|
| 工具 | 用途 |
|
|
200
211
|
| -------------------------------- | -------------------------------------- |
|
|
@@ -213,6 +224,7 @@ flowchart LR
|
|
|
213
224
|
| `subconscious_knowledge_create` | 创建知识条目 |
|
|
214
225
|
| `subconscious_knowledge_update` | 更新知识条目 |
|
|
215
226
|
| `subconscious_knowledge_delete` | 删除知识条目 |
|
|
227
|
+
| `subconscious_read_suggestions` | 读取待审查的知识建议(读取后清空) |
|
|
216
228
|
| `subconscious_knowledge_search` | 语义搜索知识库 |
|
|
217
229
|
| `subconscious_read_sessions` | 读取归档 sessions(LLM 摘要) |
|
|
218
230
|
| `subconscious_get_profile` | 读取用户画像(行滑动窗口) |
|
|
@@ -274,8 +286,9 @@ $$\text{delay} = \min(\text{base} \times \text{multiplier}^{\text{penalty}-1},\
|
|
|
274
286
|
|
|
275
287
|
`SubconsciousRunner` 将 ChatObject 作为数据容器,注入自定义 `SubconsciousBackend` + Core `ReActAgentStrategy`:
|
|
276
288
|
|
|
277
|
-
```
|
|
278
|
-
|
|
289
|
+
```mermaid
|
|
290
|
+
flowchart TD
|
|
291
|
+
LOAD_STATE --> JINJA2_RENDER --> LIMITING_MEMORY --> BUILD_MESSAGE --> REACT_BLOCK
|
|
279
292
|
```
|
|
280
293
|
|
|
281
294
|
`LIMITING_MEMORY` 在 Agent Loop 之前运行 Core `MemoryLimiter`:消息截断 → 摘要生成。`_build_config()` 将 `enable_memory_compress` 和 `loop_detect_threshold` 注入 `AmritaConfig`。
|
|
@@ -327,27 +340,27 @@ knowledge_collection_name = "amrita_global_knowledge"
|
|
|
327
340
|
enable_knowledge = true
|
|
328
341
|
```
|
|
329
342
|
|
|
330
|
-
| 字段 | 默认值 | 说明
|
|
331
|
-
| ---------------------------- | -------------------------------------- |
|
|
332
|
-
| `enabled` | `false` | 是否启用潜意识循环
|
|
333
|
-
| `target_user_id` | `""` | 目标用户 ID,为空则不启动
|
|
334
|
-
| `allowed_tools` | `[]` | 额外可用工具(从全局拉取)
|
|
335
|
-
| `max_iterations` | `10` | 单轮 ReAct 最大步数(预留)
|
|
336
|
-
| `loop_detect_threshold` | `3` | 传入 Core `loop_reasoning_trigger`
|
|
337
|
-
| `rethink_base_delay_minutes` | `30` | 惩罚退避基数
|
|
338
|
-
| `rethink_penalty_multiplier` | `1.5` | 惩罚指数倍率
|
|
339
|
-
| `rethink_max_delay_minutes` | `1440` | 惩罚延迟上限(1 天)
|
|
340
|
-
| `prompt_file` | `"prompt/subconscious_main.md.jinja2"` | 主推理提示词模板
|
|
341
|
-
| `prompt_send_file` | `"prompt/subconscious_send.md.jinja2"` | 主动消息生成模板
|
|
342
|
-
| `prompt_knowledge_file` | `"prompt/knowledge_guide.md.jinja2"` | 知识库使用指南
|
|
343
|
-
| `prompt_profile_file` | `"prompt/profile_guide.md.jinja2"` | 画像构建指南
|
|
344
|
-
| `enable_memory_compress` | `true` | 传入 Core `enable_memory_abstract`
|
|
345
|
-
| `allow_send_to_user` | `false` | 允许 Agent 主动发私聊消息
|
|
346
|
-
| `memory_warn_threshold` | `100` | ChromaDB 超此数量注入压缩提示
|
|
347
|
-
| `max_abstracts` | `5` | 摘要滑动窗口大小
|
|
348
|
-
| `knowledge_max_chars` | `10000` | 知识条目单条正文上限
|
|
349
|
-
| `knowledge_collection_name` | `"amrita_global_knowledge"` | ChromaDB 知识库 collection
|
|
350
|
-
| `enable_knowledge` | `true` |
|
|
343
|
+
| 字段 | 默认值 | 说明 |
|
|
344
|
+
| ---------------------------- | -------------------------------------- | --------------------------------------- |
|
|
345
|
+
| `enabled` | `false` | 是否启用潜意识循环 |
|
|
346
|
+
| `target_user_id` | `""` | 目标用户 ID,为空则不启动 |
|
|
347
|
+
| `allowed_tools` | `[]` | 额外可用工具(从全局拉取) |
|
|
348
|
+
| `max_iterations` | `10` | 单轮 ReAct 最大步数(预留) |
|
|
349
|
+
| `loop_detect_threshold` | `3` | 传入 Core `loop_reasoning_trigger` |
|
|
350
|
+
| `rethink_base_delay_minutes` | `30` | 惩罚退避基数 |
|
|
351
|
+
| `rethink_penalty_multiplier` | `1.5` | 惩罚指数倍率 |
|
|
352
|
+
| `rethink_max_delay_minutes` | `1440` | 惩罚延迟上限(1 天) |
|
|
353
|
+
| `prompt_file` | `"prompt/subconscious_main.md.jinja2"` | 主推理提示词模板 |
|
|
354
|
+
| `prompt_send_file` | `"prompt/subconscious_send.md.jinja2"` | 主动消息生成模板 |
|
|
355
|
+
| `prompt_knowledge_file` | `"prompt/knowledge_guide.md.jinja2"` | 知识库使用指南 |
|
|
356
|
+
| `prompt_profile_file` | `"prompt/profile_guide.md.jinja2"` | 画像构建指南 |
|
|
357
|
+
| `enable_memory_compress` | `true` | 传入 Core `enable_memory_abstract` |
|
|
358
|
+
| `allow_send_to_user` | `false` | 允许 Agent 主动发私聊消息 |
|
|
359
|
+
| `memory_warn_threshold` | `100` | ChromaDB 超此数量注入压缩提示 |
|
|
360
|
+
| `max_abstracts` | `5` | 摘要滑动窗口大小 |
|
|
361
|
+
| `knowledge_max_chars` | `10000` | 知识条目单条正文上限 |
|
|
362
|
+
| `knowledge_collection_name` | `"amrita_global_knowledge"` | ChromaDB 知识库 collection |
|
|
363
|
+
| `enable_knowledge` | `true` | 是否启用全局知识库(需 `enabled=true`) |
|
|
351
364
|
|
|
352
365
|
### 提示词模板
|
|
353
366
|
|
|
@@ -357,8 +370,8 @@ enable_knowledge = true
|
|
|
357
370
|
| ----------------------------- | ------------ | ------------------------------------------------------------------------------------------------ |
|
|
358
371
|
| `subconscious_main.md.jinja2` | 主推理提示词 | `character_prompt`, `last_run`, `last_abstracts`, `current_time`, `target_user_id`, `total_runs` |
|
|
359
372
|
| `subconscious_send.md.jinja2` | 主动消息生成 | `character_prompt`, `intent`, `memory_context`, `current_time` |
|
|
360
|
-
| `knowledge_guide.md.jinja2` | 知识库指南 |
|
|
361
|
-
| `profile_guide.md.jinja2` | 画像构建指南 |
|
|
373
|
+
| `knowledge_guide.md.jinja2` | 知识库指南 | `current_time`, `target_user_id` |
|
|
374
|
+
| `profile_guide.md.jinja2` | 画像构建指南 | `current_time`, `target_user_id` |
|
|
362
375
|
|
|
363
376
|
### 环境变量(`.env`)
|
|
364
377
|
|
{amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/rethinking/_state.py
RENAMED
|
@@ -16,6 +16,8 @@ _runner: SubconsciousRunner | None = None
|
|
|
16
16
|
_pending_messages: list[PendingMsg] = []
|
|
17
17
|
# 惩罚计数器 — 每次用户聊天取消计划时 +1,整理成功后重置
|
|
18
18
|
_penalty_count: int = 0
|
|
19
|
+
# 知识建议队列 — 对话 LLM 提议创建/更新知识,潜意识 Agent 下一轮审查
|
|
20
|
+
_knowledge_suggestions: list[dict[str, str]] = []
|
|
19
21
|
# 隔离的工具管理器 — 所有 @on_tools 装饰器通过 bound_to 注册到这里,不污染全局 ToolsManager
|
|
20
22
|
_SUBCONSCIOUS_TOOLS = MultiToolsManager()
|
|
21
23
|
|
|
@@ -70,3 +72,17 @@ def increment_penalty() -> int:
|
|
|
70
72
|
def reset_penalty() -> None:
|
|
71
73
|
global _penalty_count
|
|
72
74
|
_penalty_count = 0
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def get_knowledge_suggestions() -> list[dict[str, str]]:
|
|
78
|
+
return _knowledge_suggestions
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def set_knowledge_suggestions(suggestions: list[dict[str, str]]) -> None:
|
|
82
|
+
global _knowledge_suggestions
|
|
83
|
+
_knowledge_suggestions = suggestions
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def add_knowledge_suggestion(suggestion: dict[str, str]) -> None:
|
|
87
|
+
global _knowledge_suggestions
|
|
88
|
+
_knowledge_suggestions.append(suggestion)
|
{amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/rethinking/runner.py
RENAMED
|
@@ -277,7 +277,7 @@ class SubconsciousRunner:
|
|
|
277
277
|
mem = await repo.get_memory(_REPO_UID)
|
|
278
278
|
# extra_prompt 存 JSON 元状态
|
|
279
279
|
if mem.extra_prompt:
|
|
280
|
-
data = json.loads(mem.extra_prompt)
|
|
280
|
+
data: dict[str, Any] = json.loads(mem.extra_prompt)
|
|
281
281
|
self._total_runs = int(data.get("total_runs", 0))
|
|
282
282
|
self._last_abstracts = data.get("last_abstracts", [])
|
|
283
283
|
if isinstance(self._last_abstracts, list):
|
|
@@ -290,6 +290,10 @@ class SubconsciousRunner:
|
|
|
290
290
|
pending = data.get("pending_messages", [])
|
|
291
291
|
if isinstance(pending, list):
|
|
292
292
|
_state.set_pending(pending)
|
|
293
|
+
# 恢复知识建议队列
|
|
294
|
+
suggestions = data.get("knowledge_suggestions", [])
|
|
295
|
+
if isinstance(suggestions, list):
|
|
296
|
+
_state.set_knowledge_suggestions(suggestions)
|
|
293
297
|
# memory_json.abstract 用于 Core Jinja2 模板的 <SUMMARY> 注入
|
|
294
298
|
if mem.memory_json.abstract:
|
|
295
299
|
# 确保 abstract 也在 last_abstracts 中(兜底)
|
|
@@ -336,6 +340,7 @@ class SubconsciousRunner:
|
|
|
336
340
|
except json.JSONDecodeError:
|
|
337
341
|
pass
|
|
338
342
|
existing["pending_messages"] = _state.get_pending()
|
|
343
|
+
existing["knowledge_suggestions"] = _state.get_knowledge_suggestions()
|
|
339
344
|
mem.extra_prompt = json.dumps(existing, ensure_ascii=False)
|
|
340
345
|
await repo.update_memory_data(mem)
|
|
341
346
|
except Exception as e:
|
|
@@ -355,7 +360,7 @@ class SubconsciousRunner:
|
|
|
355
360
|
|
|
356
361
|
character_prompt = await load_character_prompt()
|
|
357
362
|
|
|
358
|
-
template = Template(main_path.read_text(encoding="utf-8"))
|
|
363
|
+
template: Template = Template(main_path.read_text(encoding="utf-8"))
|
|
359
364
|
now = datetime.now(timezone.utc)
|
|
360
365
|
prompt = await asyncio.to_thread(
|
|
361
366
|
template.render,
|
|
@@ -367,9 +372,26 @@ class SubconsciousRunner:
|
|
|
367
372
|
character_prompt=character_prompt,
|
|
368
373
|
)
|
|
369
374
|
|
|
370
|
-
# 注入知识库 &
|
|
371
|
-
|
|
372
|
-
|
|
375
|
+
# 注入知识库 & 画像指南(Jinja2 渲染,支持变量插值)
|
|
376
|
+
common_vars = {
|
|
377
|
+
"current_time": now.strftime("%Y-%m-%d %H:%M:%S UTC"),
|
|
378
|
+
"target_user_id": self._config.target_user_id or "(未配置)",
|
|
379
|
+
}
|
|
380
|
+
prompt += "\n\n" + await asyncio.to_thread(
|
|
381
|
+
Template(kn_path.read_text(encoding="utf-8")).render, **common_vars
|
|
382
|
+
)
|
|
383
|
+
prompt += "\n\n" + await asyncio.to_thread(
|
|
384
|
+
Template(pr_path.read_text(encoding="utf-8")).render, **common_vars
|
|
385
|
+
)
|
|
386
|
+
|
|
387
|
+
# 待审查的知识建议 — 注入提示让 Agent 主动拉取
|
|
388
|
+
suggestions = _state.get_knowledge_suggestions()
|
|
389
|
+
if suggestions:
|
|
390
|
+
prompt += (
|
|
391
|
+
f"\n\n📋 有 {len(suggestions)} 条来自对话 LLM 的知识建议等待审查。"
|
|
392
|
+
f"请调用 subconscious_read_suggestions 获取详情,"
|
|
393
|
+
f"审查后对值得保留的用 subconscious_knowledge_create/update 实际写入。"
|
|
394
|
+
)
|
|
373
395
|
|
|
374
396
|
# Phase 3: 膨胀感知 — 查 ChromaDB 总量,超阈值注入警告
|
|
375
397
|
try:
|
{amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/rethinking/schemas.py
RENAMED
|
@@ -281,6 +281,53 @@ KNOWLEDGE_SEARCH_SCHEMA = FunctionDefinitionSchema(
|
|
|
281
281
|
),
|
|
282
282
|
)
|
|
283
283
|
|
|
284
|
+
# 知识建议(对话 LLM 提议,潜意识 Agent 审查后实际写入)
|
|
285
|
+
|
|
286
|
+
KNOWLEDGE_SUGGEST_SCHEMA = FunctionDefinitionSchema(
|
|
287
|
+
name="knowledge_suggest",
|
|
288
|
+
description=(
|
|
289
|
+
"向全局知识库提议添加或更新知识。注意:你的提议不会直接写入——"
|
|
290
|
+
"它会被转发给后台的记忆管家(Subconscious Agent),"
|
|
291
|
+
"由它在下一轮推理中审查并决定是否实际创建或更新。"
|
|
292
|
+
"提议后无需等待结果,记忆管家会自行处理。"
|
|
293
|
+
"action: 'create' 提议新建知识,'update' 提议更新已有知识(需传 kid)"
|
|
294
|
+
),
|
|
295
|
+
parameters=FunctionParametersSchema(
|
|
296
|
+
type="object",
|
|
297
|
+
properties={
|
|
298
|
+
"action": FunctionPropertySchema(
|
|
299
|
+
type="string",
|
|
300
|
+
enum=["create", "update"],
|
|
301
|
+
description="create=提议新建,update=提议更新已有知识",
|
|
302
|
+
),
|
|
303
|
+
"title": FunctionPropertySchema(type="string", description="知识标题"),
|
|
304
|
+
"summary": FunctionPropertySchema(
|
|
305
|
+
type="string", description="知识摘要(≤200字)"
|
|
306
|
+
),
|
|
307
|
+
"body": FunctionPropertySchema(type="string", description="知识正文"),
|
|
308
|
+
"kid": FunctionPropertySchema(
|
|
309
|
+
type="string", description="update 时必传:要更新的知识条目 ID"
|
|
310
|
+
),
|
|
311
|
+
"reason": FunctionPropertySchema(
|
|
312
|
+
type="string", description="提议理由:为什么值得记录"
|
|
313
|
+
),
|
|
314
|
+
},
|
|
315
|
+
required=["action", "title", "summary", "body", "reason"],
|
|
316
|
+
),
|
|
317
|
+
)
|
|
318
|
+
|
|
319
|
+
READ_SUGGESTIONS_SCHEMA = FunctionDefinitionSchema(
|
|
320
|
+
name="subconscious_read_suggestions",
|
|
321
|
+
description=(
|
|
322
|
+
"读取对话 LLM 提交的待审查知识建议列表。"
|
|
323
|
+
"每条建议包含 action(create/update)、标题、摘要、正文、理由。"
|
|
324
|
+
"审查后对值得保留的用 subconscious_knowledge_create 或"
|
|
325
|
+
"subconscious_knowledge_update 实际写入,不合适的忽略即可。"
|
|
326
|
+
"调用后会自动清空建议队列。"
|
|
327
|
+
),
|
|
328
|
+
parameters=FunctionParametersSchema(type="object", properties={}, required=[]),
|
|
329
|
+
)
|
|
330
|
+
|
|
284
331
|
# Session 与用户画像工具
|
|
285
332
|
|
|
286
333
|
READ_SESSIONS_SCHEMA = FunctionDefinitionSchema(
|
{amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/rethinking/tools.py
RENAMED
|
@@ -27,11 +27,13 @@ from .schemas import (
|
|
|
27
27
|
KNOWLEDGE_LIST_SCHEMA,
|
|
28
28
|
KNOWLEDGE_READ_SCHEMA,
|
|
29
29
|
KNOWLEDGE_SEARCH_SCHEMA,
|
|
30
|
+
KNOWLEDGE_SUGGEST_SCHEMA,
|
|
30
31
|
KNOWLEDGE_UPDATE_SCHEMA,
|
|
31
32
|
LIST_MEMORY_SCHEMA,
|
|
32
33
|
READ_CHAT_CONTEXT_SCHEMA,
|
|
33
34
|
READ_MEMORY_SCHEMA,
|
|
34
35
|
READ_SESSIONS_SCHEMA,
|
|
36
|
+
READ_SUGGESTIONS_SCHEMA,
|
|
35
37
|
SEND_TO_USER_SCHEMA,
|
|
36
38
|
UPDATE_MEMORY_SCHEMA,
|
|
37
39
|
UPDATE_PROFILE_SCHEMA,
|
|
@@ -487,8 +489,14 @@ def _get_kb_manager():
|
|
|
487
489
|
runner = _state.get_runner()
|
|
488
490
|
if runner is None:
|
|
489
491
|
raise RuntimeError("SubconsciousRunner not initialized")
|
|
490
|
-
if
|
|
491
|
-
|
|
492
|
+
if (
|
|
493
|
+
not runner._config.enabled
|
|
494
|
+
or not runner._config.enable_knowledge
|
|
495
|
+
or runner._kb_manager is None
|
|
496
|
+
):
|
|
497
|
+
raise RuntimeError(
|
|
498
|
+
"全局知识库未启用(enabled=false 或 enable_knowledge=false)"
|
|
499
|
+
)
|
|
492
500
|
return runner._kb_manager
|
|
493
501
|
|
|
494
502
|
|
|
@@ -530,7 +538,6 @@ async def subconscious_knowledge_read(data: dict[str, Any]) -> str:
|
|
|
530
538
|
return _tools_err(str(e))
|
|
531
539
|
|
|
532
540
|
|
|
533
|
-
@on_tools(KNOWLEDGE_CREATE_SCHEMA, strict=True)
|
|
534
541
|
@on_tools(KNOWLEDGE_CREATE_SCHEMA, strict=True, bound_to=_SUBCONSCIOUS_TOOLS)
|
|
535
542
|
async def subconscious_knowledge_create(data: dict[str, Any]) -> str:
|
|
536
543
|
try:
|
|
@@ -551,7 +558,6 @@ async def subconscious_knowledge_create(data: dict[str, Any]) -> str:
|
|
|
551
558
|
return _tools_err(str(e))
|
|
552
559
|
|
|
553
560
|
|
|
554
|
-
@on_tools(KNOWLEDGE_UPDATE_SCHEMA, strict=True)
|
|
555
561
|
@on_tools(KNOWLEDGE_UPDATE_SCHEMA, strict=True, bound_to=_SUBCONSCIOUS_TOOLS)
|
|
556
562
|
async def subconscious_knowledge_update(data: dict[str, Any]) -> str:
|
|
557
563
|
try:
|
|
@@ -580,7 +586,6 @@ async def subconscious_knowledge_update(data: dict[str, Any]) -> str:
|
|
|
580
586
|
return _tools_err(str(e))
|
|
581
587
|
|
|
582
588
|
|
|
583
|
-
@on_tools(KNOWLEDGE_DELETE_SCHEMA, strict=True)
|
|
584
589
|
@on_tools(KNOWLEDGE_DELETE_SCHEMA, strict=True, bound_to=_SUBCONSCIOUS_TOOLS)
|
|
585
590
|
async def subconscious_knowledge_delete(data: dict[str, Any]) -> str:
|
|
586
591
|
try:
|
|
@@ -616,6 +621,60 @@ async def subconscious_knowledge_search(data: dict[str, Any]) -> str:
|
|
|
616
621
|
return _tools_err(str(e))
|
|
617
622
|
|
|
618
623
|
|
|
624
|
+
# 知识建议(对话 LLM → 潜意识 Agent 审查管线)
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
@on_tools(KNOWLEDGE_SUGGEST_SCHEMA, strict=True)
|
|
628
|
+
async def knowledge_suggest(data: dict[str, Any]) -> str:
|
|
629
|
+
"""对话 LLM 提交知识建议,加入队列等待潜意识 Agent 审查。"""
|
|
630
|
+
action = str(data["action"])
|
|
631
|
+
suggestion = {
|
|
632
|
+
"action": action,
|
|
633
|
+
"title": str(data["title"]),
|
|
634
|
+
"summary": str(data["summary"]),
|
|
635
|
+
"body": str(data["body"]),
|
|
636
|
+
"reason": str(data.get("reason", "")),
|
|
637
|
+
"kid": str(data["kid"]) if action == "update" and data.get("kid") else "",
|
|
638
|
+
"timestamp": datetime.now(timezone.utc).isoformat(),
|
|
639
|
+
}
|
|
640
|
+
_state.add_knowledge_suggestion(suggestion)
|
|
641
|
+
# 触发持久化
|
|
642
|
+
runner = _state.get_runner()
|
|
643
|
+
if runner is not None:
|
|
644
|
+
await runner._save_pending_to_repo()
|
|
645
|
+
logger.info(
|
|
646
|
+
f"[Subconscious] Knowledge suggestion queued: "
|
|
647
|
+
f"action={action}, title={suggestion['title'][:50]}"
|
|
648
|
+
)
|
|
649
|
+
return _tools_ok(
|
|
650
|
+
message=(
|
|
651
|
+
"知识建议已提交,后台记忆管家将在下一轮推理中审查。"
|
|
652
|
+
if action == "create"
|
|
653
|
+
else "更新建议已提交,后台记忆管家将在下一轮推理中审查。"
|
|
654
|
+
),
|
|
655
|
+
action=action,
|
|
656
|
+
)
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
@on_tools(READ_SUGGESTIONS_SCHEMA, strict=True, bound_to=_SUBCONSCIOUS_TOOLS)
|
|
660
|
+
async def subconscious_read_suggestions(data: dict[str, Any]) -> str:
|
|
661
|
+
"""潜意识 Agent 读取待审查的知识建议并清空队列。"""
|
|
662
|
+
suggestions = list(_state.get_knowledge_suggestions())
|
|
663
|
+
_state.set_knowledge_suggestions([])
|
|
664
|
+
# 持久化空队列
|
|
665
|
+
runner = _state.get_runner()
|
|
666
|
+
if runner is not None:
|
|
667
|
+
await runner._save_pending_to_repo()
|
|
668
|
+
logger.info(
|
|
669
|
+
f"[Subconscious] Read {len(suggestions)} knowledge suggestions, queue cleared"
|
|
670
|
+
)
|
|
671
|
+
return json.dumps(
|
|
672
|
+
{"status": "success", "suggestions": suggestions, "total": len(suggestions)},
|
|
673
|
+
ensure_ascii=False,
|
|
674
|
+
indent=2,
|
|
675
|
+
)
|
|
676
|
+
|
|
677
|
+
|
|
619
678
|
# Session 与用户画像工具
|
|
620
679
|
|
|
621
680
|
|
{amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: amrita_plugin_memory
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: Amrita长期记忆插件
|
|
5
5
|
Requires-Python: <3.14,>=3.10
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -71,6 +71,8 @@ allow_send_to_user = true
|
|
|
71
71
|
enable_knowledge = false
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
+
> 知识库依赖潜意识推理——当 `enabled = false` 时,知识库也会自动禁用。
|
|
75
|
+
|
|
74
76
|
### 4. 验证
|
|
75
77
|
|
|
76
78
|
观察日志中 `[Subconscious]` 前缀的输出:
|
|
@@ -95,6 +97,7 @@ flowchart TB
|
|
|
95
97
|
S_Write --> ChromaDB[("ChromaDB<br/>向量数据库")]
|
|
96
98
|
S_Read --> ChromaDB
|
|
97
99
|
S_Mut --> ChromaDB
|
|
100
|
+
S_LLM -->|"knowledge_list/read/search"| ChromaDB
|
|
98
101
|
end
|
|
99
102
|
|
|
100
103
|
subgraph Subconscious["底层:Subconscious Reasoning"]
|
|
@@ -112,7 +115,8 @@ flowchart TB
|
|
|
112
115
|
AgentLoop --> Profile["用户画像<br/>行级增量更新"]
|
|
113
116
|
end
|
|
114
117
|
|
|
115
|
-
Surface -->|"
|
|
118
|
+
Surface -->|"knowledge_suggest"| SuggQueue["知识建议队列"]
|
|
119
|
+
SuggQueue --> AgentLoop
|
|
116
120
|
Surface -.->|"共享 ChromaDB"| Subconscious
|
|
117
121
|
Runner -->|"持久化状态"| CachedRepo["CachedUserDataRepository"]
|
|
118
122
|
Runner -->|"usage 统计"| Insights["InsightsModel<br/>全局 Token 统计"]
|
|
@@ -150,7 +154,16 @@ flowchart TB
|
|
|
150
154
|
|
|
151
155
|
### 共享:全局知识库
|
|
152
156
|
|
|
153
|
-
|
|
157
|
+
知识库是**表层和潜意识双层共享**的资源。读取操作(`list`/`read`/`search`)通过双重 `@on_tools` 注册,对话 LLM 和后台 Agent 均可直接调用。**写入操作**(`create`/`update`/`delete`)仅限潜意识 Agent——表层通过 `knowledge_suggest` 提交建议,由 Agent 在下一轮推理中审查后决定是否实际写入:
|
|
158
|
+
|
|
159
|
+
```mermaid
|
|
160
|
+
flowchart LR
|
|
161
|
+
ChatLLM["对话 LLM"] -->|"knowledge_suggest"| Queue["建议队列<br/>(持久化)"]
|
|
162
|
+
Queue -->|"subconscious_read_suggestions"| Agent["Subconscious Agent<br/>下一轮推理"]
|
|
163
|
+
Agent -->|"审查"| Decision{"值得记录?"}
|
|
164
|
+
Decision -->|"Yes"| SubCreate["subconscious_knowledge_create"]
|
|
165
|
+
Decision -->|"No"| Drop["忽略"]
|
|
166
|
+
```
|
|
154
167
|
|
|
155
168
|
每条知识由三个组件共同管理:
|
|
156
169
|
|
|
@@ -195,23 +208,21 @@ flowchart LR
|
|
|
195
208
|
|
|
196
209
|
### 表层工具(`tools.py`)
|
|
197
210
|
|
|
198
|
-
| 工具
|
|
199
|
-
|
|
|
200
|
-
| `write_memory`
|
|
201
|
-
| `read_memory`
|
|
202
|
-
| `update_memory`
|
|
203
|
-
| `delete_memory`
|
|
204
|
-
| `list_memory`
|
|
205
|
-
| `knowledge_list`
|
|
206
|
-
| `knowledge_read`
|
|
207
|
-
| `
|
|
208
|
-
| `
|
|
209
|
-
| `knowledge_delete` | kid |
|
|
210
|
-
| `knowledge_search` | query, top_k? |
|
|
211
|
+
| 工具 | 参数 |
|
|
212
|
+
| ------------------- | -------------------------------------------- |
|
|
213
|
+
| `write_memory` | content, tags, importance(enum), scope(enum) |
|
|
214
|
+
| `read_memory` | query, top_k(5), importance?, scope(enum) |
|
|
215
|
+
| `update_memory` | id, scope, content?, tags?, importance? |
|
|
216
|
+
| `delete_memory` | id, scope |
|
|
217
|
+
| `list_memory` | limit, scope |
|
|
218
|
+
| `knowledge_list` | — |
|
|
219
|
+
| `knowledge_read` | kid, start_line?, end_line? |
|
|
220
|
+
| `knowledge_search` | query, top_k? |
|
|
221
|
+
| `knowledge_suggest` | action, title, summary, body, reason |
|
|
211
222
|
|
|
212
223
|
### 潜意识工具(`rethinking/tools.py`)
|
|
213
224
|
|
|
214
|
-
记忆和 session/画像工具注册在隔离的 `_SUBCONSCIOUS_TOOLS`
|
|
225
|
+
记忆和 session/画像工具注册在隔离的 `_SUBCONSCIOUS_TOOLS` 上。知识库中 `list`/`read`/`search` 通过双重注册同时暴露给表层和潜意识;`create`/`update`/`delete` 仅潜意识可用(表层通过 `knowledge_suggest` 提交建议):
|
|
215
226
|
|
|
216
227
|
| 工具 | 用途 |
|
|
217
228
|
| -------------------------------- | -------------------------------------- |
|
|
@@ -230,6 +241,7 @@ flowchart LR
|
|
|
230
241
|
| `subconscious_knowledge_create` | 创建知识条目 |
|
|
231
242
|
| `subconscious_knowledge_update` | 更新知识条目 |
|
|
232
243
|
| `subconscious_knowledge_delete` | 删除知识条目 |
|
|
244
|
+
| `subconscious_read_suggestions` | 读取待审查的知识建议(读取后清空) |
|
|
233
245
|
| `subconscious_knowledge_search` | 语义搜索知识库 |
|
|
234
246
|
| `subconscious_read_sessions` | 读取归档 sessions(LLM 摘要) |
|
|
235
247
|
| `subconscious_get_profile` | 读取用户画像(行滑动窗口) |
|
|
@@ -291,8 +303,9 @@ $$\text{delay} = \min(\text{base} \times \text{multiplier}^{\text{penalty}-1},\
|
|
|
291
303
|
|
|
292
304
|
`SubconsciousRunner` 将 ChatObject 作为数据容器,注入自定义 `SubconsciousBackend` + Core `ReActAgentStrategy`:
|
|
293
305
|
|
|
294
|
-
```
|
|
295
|
-
|
|
306
|
+
```mermaid
|
|
307
|
+
flowchart TD
|
|
308
|
+
LOAD_STATE --> JINJA2_RENDER --> LIMITING_MEMORY --> BUILD_MESSAGE --> REACT_BLOCK
|
|
296
309
|
```
|
|
297
310
|
|
|
298
311
|
`LIMITING_MEMORY` 在 Agent Loop 之前运行 Core `MemoryLimiter`:消息截断 → 摘要生成。`_build_config()` 将 `enable_memory_compress` 和 `loop_detect_threshold` 注入 `AmritaConfig`。
|
|
@@ -344,27 +357,27 @@ knowledge_collection_name = "amrita_global_knowledge"
|
|
|
344
357
|
enable_knowledge = true
|
|
345
358
|
```
|
|
346
359
|
|
|
347
|
-
| 字段 | 默认值 | 说明
|
|
348
|
-
| ---------------------------- | -------------------------------------- |
|
|
349
|
-
| `enabled` | `false` | 是否启用潜意识循环
|
|
350
|
-
| `target_user_id` | `""` | 目标用户 ID,为空则不启动
|
|
351
|
-
| `allowed_tools` | `[]` | 额外可用工具(从全局拉取)
|
|
352
|
-
| `max_iterations` | `10` | 单轮 ReAct 最大步数(预留)
|
|
353
|
-
| `loop_detect_threshold` | `3` | 传入 Core `loop_reasoning_trigger`
|
|
354
|
-
| `rethink_base_delay_minutes` | `30` | 惩罚退避基数
|
|
355
|
-
| `rethink_penalty_multiplier` | `1.5` | 惩罚指数倍率
|
|
356
|
-
| `rethink_max_delay_minutes` | `1440` | 惩罚延迟上限(1 天)
|
|
357
|
-
| `prompt_file` | `"prompt/subconscious_main.md.jinja2"` | 主推理提示词模板
|
|
358
|
-
| `prompt_send_file` | `"prompt/subconscious_send.md.jinja2"` | 主动消息生成模板
|
|
359
|
-
| `prompt_knowledge_file` | `"prompt/knowledge_guide.md.jinja2"` | 知识库使用指南
|
|
360
|
-
| `prompt_profile_file` | `"prompt/profile_guide.md.jinja2"` | 画像构建指南
|
|
361
|
-
| `enable_memory_compress` | `true` | 传入 Core `enable_memory_abstract`
|
|
362
|
-
| `allow_send_to_user` | `false` | 允许 Agent 主动发私聊消息
|
|
363
|
-
| `memory_warn_threshold` | `100` | ChromaDB 超此数量注入压缩提示
|
|
364
|
-
| `max_abstracts` | `5` | 摘要滑动窗口大小
|
|
365
|
-
| `knowledge_max_chars` | `10000` | 知识条目单条正文上限
|
|
366
|
-
| `knowledge_collection_name` | `"amrita_global_knowledge"` | ChromaDB 知识库 collection
|
|
367
|
-
| `enable_knowledge` | `true` |
|
|
360
|
+
| 字段 | 默认值 | 说明 |
|
|
361
|
+
| ---------------------------- | -------------------------------------- | --------------------------------------- |
|
|
362
|
+
| `enabled` | `false` | 是否启用潜意识循环 |
|
|
363
|
+
| `target_user_id` | `""` | 目标用户 ID,为空则不启动 |
|
|
364
|
+
| `allowed_tools` | `[]` | 额外可用工具(从全局拉取) |
|
|
365
|
+
| `max_iterations` | `10` | 单轮 ReAct 最大步数(预留) |
|
|
366
|
+
| `loop_detect_threshold` | `3` | 传入 Core `loop_reasoning_trigger` |
|
|
367
|
+
| `rethink_base_delay_minutes` | `30` | 惩罚退避基数 |
|
|
368
|
+
| `rethink_penalty_multiplier` | `1.5` | 惩罚指数倍率 |
|
|
369
|
+
| `rethink_max_delay_minutes` | `1440` | 惩罚延迟上限(1 天) |
|
|
370
|
+
| `prompt_file` | `"prompt/subconscious_main.md.jinja2"` | 主推理提示词模板 |
|
|
371
|
+
| `prompt_send_file` | `"prompt/subconscious_send.md.jinja2"` | 主动消息生成模板 |
|
|
372
|
+
| `prompt_knowledge_file` | `"prompt/knowledge_guide.md.jinja2"` | 知识库使用指南 |
|
|
373
|
+
| `prompt_profile_file` | `"prompt/profile_guide.md.jinja2"` | 画像构建指南 |
|
|
374
|
+
| `enable_memory_compress` | `true` | 传入 Core `enable_memory_abstract` |
|
|
375
|
+
| `allow_send_to_user` | `false` | 允许 Agent 主动发私聊消息 |
|
|
376
|
+
| `memory_warn_threshold` | `100` | ChromaDB 超此数量注入压缩提示 |
|
|
377
|
+
| `max_abstracts` | `5` | 摘要滑动窗口大小 |
|
|
378
|
+
| `knowledge_max_chars` | `10000` | 知识条目单条正文上限 |
|
|
379
|
+
| `knowledge_collection_name` | `"amrita_global_knowledge"` | ChromaDB 知识库 collection |
|
|
380
|
+
| `enable_knowledge` | `true` | 是否启用全局知识库(需 `enabled=true`) |
|
|
368
381
|
|
|
369
382
|
### 提示词模板
|
|
370
383
|
|
|
@@ -374,8 +387,8 @@ enable_knowledge = true
|
|
|
374
387
|
| ----------------------------- | ------------ | ------------------------------------------------------------------------------------------------ |
|
|
375
388
|
| `subconscious_main.md.jinja2` | 主推理提示词 | `character_prompt`, `last_run`, `last_abstracts`, `current_time`, `target_user_id`, `total_runs` |
|
|
376
389
|
| `subconscious_send.md.jinja2` | 主动消息生成 | `character_prompt`, `intent`, `memory_context`, `current_time` |
|
|
377
|
-
| `knowledge_guide.md.jinja2` | 知识库指南 |
|
|
378
|
-
| `profile_guide.md.jinja2` | 画像构建指南 |
|
|
390
|
+
| `knowledge_guide.md.jinja2` | 知识库指南 | `current_time`, `target_user_id` |
|
|
391
|
+
| `profile_guide.md.jinja2` | 画像构建指南 | `current_time`, `target_user_id` |
|
|
379
392
|
|
|
380
393
|
### 环境变量(`.env`)
|
|
381
394
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/rethinking/backend.py
RENAMED
|
File without changes
|
{amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/rethinking/consts.py
RENAMED
|
File without changes
|
{amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/rethinking/hooks.py
RENAMED
|
File without changes
|
|
File without changes
|
{amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/rethinking/nodes.py
RENAMED
|
File without changes
|
{amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory/rethinking/types.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{amrita_plugin_memory-0.3.0 → amrita_plugin_memory-0.3.1}/amrita_plugin_memory.egg-info/requires.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|