docs: P3-P5 implementation plans + skill update
This commit is contained in:
parent
7fabc58bf3
commit
db3d3d8e85
|
|
@ -0,0 +1,44 @@
|
|||
# P3: CREATIVE.md 隔离 — 防止双写入冲突
|
||||
|
||||
## 问题
|
||||
MEMORY.md 同时被 `memory` 工具(写环境事实/约定)和织忆(写记忆/经验)写入,可能导致 `§` 分隔符污染和数据混乱。
|
||||
|
||||
## 方案(参考 Memory-OS: 把 Icarus 写目标从 MEMORY.md 拆到 CREATIVE.md)
|
||||
|
||||
1. 在 `~/.hermes/` 下创建 `CREATIVE.md` 文件(初始内容为空,带标记头)
|
||||
2. 修改 Hermes 织忆插件的 `sync_turn` 方法:将记忆写出目标从 MEMORY.md 改为 CREATIVE.md
|
||||
3. 确保 Hermes 的 `system_prompt_block()` 返回 `CREATIVE.md` 的内容(如果文件存在)
|
||||
4. 当前 `sync_turn` 使用的是 Hermes 原生 memory 工具写入 → 需要确认是直接写文件还是通过工具
|
||||
|
||||
## 具体文件
|
||||
|
||||
### `~/.hermes/CREATIVE.md` — 创建
|
||||
```markdown
|
||||
# CREATIVE.md — 织忆(A06)工作记忆与学习状态
|
||||
> 由 Hermes 织忆插件自动管理,`memory` 工具请写入 MEMORY.md
|
||||
> 创建日期:2026-07-02
|
||||
|
||||
<!-- 织忆自动写入区 — 请勿手动编辑 -->
|
||||
```
|
||||
|
||||
### `~/.hermes/hermes-agent/plugins/memory/zhiyi/__init__.py` — 修改 sync_turn
|
||||
当前 sync_turn(~391行附近)把对话写入织忆后端(/commit API),同时可能也写 MEMORY.md。
|
||||
需要确认:插件代码是否直接写 MEMORY.md?如果没写,那 P3 的动作为:
|
||||
1. 在 `system_prompt_block()` 方法中:检测并返回 CREATIVE.md 内容
|
||||
2. 织忆本身通过 /commit 存储到 LanceDB,和 MEMORY.md 无关 → 没有直接冲突
|
||||
3. 所以 P3 = 创建 CREATIVE.md + 让 system_prompt_block 使用它 + 说明织忆的专用存储不在 MEMORY.md
|
||||
|
||||
## 验证
|
||||
```bash
|
||||
# CREATIVE.md 文件存在
|
||||
ls -la ~/.hermes/CREATIVE.md
|
||||
# 插件 system_prompt_block 返回正确
|
||||
cd ~/.hermes/hermes-agent && python3 -c "
|
||||
from plugins.memory.zhiyi import HermesZhiYiMemoryProvider
|
||||
p = HermesZhiYiMemoryProvider()
|
||||
p.initialize(session_id='test')
|
||||
block = p.system_prompt_block()
|
||||
print('CREATIVE.md in prompt:', 'CREATIVE.md' in block or '工作记忆' in block)
|
||||
print(f'block length: {len(block)}')
|
||||
"
|
||||
```
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
# P4: 强制注入 Prompt — SOUL.md Ground Truth 扩展
|
||||
|
||||
## 问题
|
||||
SOUL.md 虽然有 4 级 Ground Truth 层级,但缺少显式的"注入记忆优先"指令。
|
||||
当 [织忆 Memory] 被注入系统提示时,Agent 可能视其为"建议"而非"权威",
|
||||
导致 Agent 仍去调 memory_search / session_search 重新发现已经有的信息。
|
||||
|
||||
## 方案(参考 Memory-OS Layer 7 的做法)
|
||||
|
||||
在 `~/.hermes/SOUL.md` 中补充:
|
||||
|
||||
### 1. Ground Truth 层级中显式加入"注入记忆"级别
|
||||
```markdown
|
||||
## Ground Truth
|
||||
|
||||
Authoritative sources, in priority order:
|
||||
|
||||
1. **Terminal output** — stdout, stderr, exit codes. Ground truth for current system state.
|
||||
2. **Injected memory — [织忆], [fabric], [qdrant], [sessions]** — Ground truth for documented knowledge and prior decisions.
|
||||
When injected memory contradicts your assumptions or training knowledge, injected memory wins.
|
||||
Never treat a question as novel when the answer is already in your prompt.
|
||||
3. **Official documentation** — man pages, --help, upstream docs. Authoritative for APIs and configs.
|
||||
4. **Training knowledge** — reference only. Always verify against sources 1-3.
|
||||
```
|
||||
|
||||
### 2. 上下文注入约定章节
|
||||
```markdown
|
||||
## Context injection convention
|
||||
|
||||
When context is injected into the system prompt, it is labeled by source:
|
||||
- [织忆 Memory] — from ZhiYi semantic recall (+ graph navigation)
|
||||
- [织忆 Graph] — from ZhiYi knowledge graph (Obsidian notes)
|
||||
|
||||
Injected memory takes priority level 2 in Ground Truth. This means: you
|
||||
already know this. Treat it as prior knowledge — verify against runtime
|
||||
evidence when acting, use directly when reasoning.
|
||||
```
|
||||
|
||||
### 3. 记忆反馈规则
|
||||
```markdown
|
||||
**Memory feedback rule:** When you retrieve memory from 织忆 (via memory_search,
|
||||
memory_graph_navigate, or prefetch injection) and reference it in your response,
|
||||
you should consider its trust_score. Higher trust_score = more reliable facts.
|
||||
Use memory_feedback to mark useful/unuseful results — this trains the trust scoring system.
|
||||
```
|
||||
|
||||
## 验证
|
||||
```bash
|
||||
grep -A 20 "## Ground Truth" ~/.hermes/SOUL.md | head -25
|
||||
grep -A 30 "## Context injection convention" ~/.hermes/SOUL.md | head -15
|
||||
```
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
# P5: Wiki 策展管线 — 自动知识库
|
||||
|
||||
## 问题
|
||||
织忆能存储和检索记忆,但没有"知识库"的概念:将外部文档(.md 文章、技术笔记、项目文档)
|
||||
自动提取为结构化知识条目,写入织忆系统供后续 recall 搜索。
|
||||
|
||||
## 方案(参考 Memory-OS Layer 5+6,适配织忆架构)
|
||||
|
||||
Memory-OS 用 Wiki Agent(LLM 提取概念/实体/对比)+ Continuous Ingest(嵌入 Qdrant)。
|
||||
织忆的替代方案:Python 脚本扫描 Obsidian Vault → LLM 提取知识点 → 通过 /commit API 写入织忆。
|
||||
|
||||
## 实现
|
||||
|
||||
### 新增文件: `scripts/wiki_curator.py`
|
||||
|
||||
```python
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Wiki Curator — 自动知识策展管线
|
||||
扫描 Obsidian vault 中的 .md 文件,用 LLM 提取知识点,通过织忆 API 存入结构性记忆。
|
||||
|
||||
流程:
|
||||
1. 扫描 ~/mc/小唯/ 和 ~/obsidian/ 中的 .md 文件(排除缓存/临时文件)
|
||||
2. SHA-256 diff 检测(只处理新增/修改的文件)
|
||||
3. LLM 提取:
|
||||
- 概念(concept):什么是 X?
|
||||
- 实体(entity):X 的属性/参数/配置
|
||||
- 关系(relation):X 和 Y 的关系
|
||||
4. 通过织忆 /commit API 写入 memories(category='wiki')
|
||||
5. 更新状态文件(记录已处理的文件哈希)
|
||||
"""
|
||||
|
||||
# 配置
|
||||
WIKI_DIRS = [
|
||||
"~/mc/小唯/", # 织忆设计文档/技术笔记
|
||||
"~/mc/牧尘/", # 系统配置/命令记录
|
||||
# 可根据需要扩展
|
||||
]
|
||||
ZHIYI_API = "http://localhost:7821"
|
||||
ZHIYI_KEY = "zhiyi-dev-key-2026"
|
||||
STATE_FILE = "~/.hermes/wiki_curator_state.json"
|
||||
```
|
||||
|
||||
### 处理逻辑
|
||||
|
||||
对每个新/修改的文件:
|
||||
1. 读取内容,过滤掉过短(<500字)或明显非知识性的文件
|
||||
2. 调用 LLM(Hermes 的模型或 NewAPI)提取:
|
||||
```json
|
||||
{
|
||||
"concepts": [{"name": "X", "summary": "...", "details": "..."}],
|
||||
"entities": [{"name": "Y", "attributes": {...}}],
|
||||
"relations": [{"source": "X", "relation": "uses", "target": "Y"}]
|
||||
}
|
||||
```
|
||||
3. 对每个提取的概念/实体,通过织忆 /commit API 写入
|
||||
4. 对每个关系,通过织忆 /api/v1/graph/edge API 写入
|
||||
|
||||
### 定时任务
|
||||
|
||||
创建 cronjob 每周运行两次(周一/周四凌晨3点):
|
||||
```bash
|
||||
hermes cron add "织忆 Wiki 策展" --schedule "0 3 * * 1,4" \
|
||||
--prompt "执行 wiki_curator.py 扫描检查" \
|
||||
--script ~/.hermes/scripts/wiki_curator.py
|
||||
```
|
||||
|
||||
## 验证
|
||||
```bash
|
||||
# 手动运行
|
||||
python3 ~/.hermes/scripts/wiki_curator.py --dry-run
|
||||
|
||||
# 验证织忆端已有 wiki 类记忆
|
||||
curl -s -X POST -H "X-API-Key: zhiyi-dev-key-2026" \
|
||||
-d '{"query":"织忆设计","top_k":5}' \
|
||||
http://localhost:7821/api/v1/recall
|
||||
```
|
||||
Loading…
Reference in New Issue