mirror of
https://gitcode.com/JianFeeeee/TrulyMEM-TrueHumanMEM.git
synced 2026-10-15 12:15:32 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0ebd1d7ac6 | |||
| de09eacabc | |||
| 14af13c050 | |||
| 47c5b99617 | |||
| e975fe409b | |||
| 0270e17a76 |
@ -13,12 +13,11 @@
|
|||||||
|
|
||||||
*The More Human Choice.*
|
*The More Human Choice.*
|
||||||
|
|
||||||
> ⚠️ **当前分支**: `test` — 测试分支,用于测试实验性功能。此处代码可能不稳定,不应用于生产环境。稳定版本请参阅 `main` 分支。
|
|
||||||
|
|
||||||
[](https://www.gnu.org/licenses/gpl-3.0)
|
[](https://www.gnu.org/licenses/gpl-3.0)
|
||||||
[](https://www.python.org/downloads/)
|
[](https://www.python.org/downloads/)
|
||||||
[]()
|
[]()
|
||||||
[]()
|
[]()
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@ -13,12 +13,11 @@
|
|||||||
|
|
||||||
*The More Human Choice.*
|
*The More Human Choice.*
|
||||||
|
|
||||||
> ⚠️ **Current Branch**: `test` — Testing branch for experimental features. Code here may be unstable and should not be used in production. For stable releases, see the `main` branch.
|
|
||||||
|
|
||||||
[](https://www.gnu.org/licenses/gpl-3.0)
|
[](https://www.gnu.org/licenses/gpl-3.0)
|
||||||
[](https://www.python.org/downloads/)
|
[](https://www.python.org/downloads/)
|
||||||
[]()
|
[]()
|
||||||
[]()
|
[]()
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,7 @@ fi
|
|||||||
APPDIR="$PROJECT_ROOT/TrulyMEM.AppDir"
|
APPDIR="$PROJECT_ROOT/TrulyMEM.AppDir"
|
||||||
rm -rf "$APPDIR"
|
rm -rf "$APPDIR"
|
||||||
mkdir -p "$APPDIR/usr/bin"
|
mkdir -p "$APPDIR/usr/bin"
|
||||||
|
mkdir -p "$APPDIR/usr/share/trulymem"
|
||||||
echo "===== Step 1: Build binary with PyInstaller ====="
|
echo "===== Step 1: Build binary with PyInstaller ====="
|
||||||
VENV_DIR="$PROJECT_ROOT/.venv_appimage"
|
VENV_DIR="$PROJECT_ROOT/.venv_appimage"
|
||||||
rm -rf "$VENV_DIR"
|
rm -rf "$VENV_DIR"
|
||||||
@ -80,9 +81,21 @@ Exec=TrulyMEM %U
|
|||||||
Icon=trulymem
|
Icon=trulymem
|
||||||
Terminal=true
|
Terminal=true
|
||||||
Type=Application
|
Type=Application
|
||||||
Categories=Utility;AI;
|
Categories=Utility;X-AI;
|
||||||
EOF
|
EOF
|
||||||
[ -f "$PROJECT_ROOT/pic/TrulyMEM.png" ] && cp "$PROJECT_ROOT/pic/TrulyMEM.png" "$APPDIR/trulymem.png"
|
# Copy icon file (try multiple possible locations)
|
||||||
|
if [ -f "$PROJECT_ROOT/pic/TrulyMEM.png" ]; then
|
||||||
|
cp "$PROJECT_ROOT/pic/TrulyMEM.png" "$APPDIR/trulymem.png"
|
||||||
|
elif [ -f "$PROJECT_ROOT/pic/TrulyMEM.iconset/icon_256x256.png" ]; then
|
||||||
|
cp "$PROJECT_ROOT/pic/TrulyMEM.iconset/icon_256x256.png" "$APPDIR/trulymem.png"
|
||||||
|
elif [ -f "$PROJECT_ROOT/pic/TrulyMEM.iconset/icon_128x128.png" ]; then
|
||||||
|
cp "$PROJECT_ROOT/pic/TrulyMEM.iconset/icon_128x128.png" "$APPDIR/trulymem.png"
|
||||||
|
else
|
||||||
|
echo "Warning: No icon file found, creating placeholder"
|
||||||
|
# Create a simple placeholder icon
|
||||||
|
convert -size 256x256 xc:blue "$APPDIR/trulymem.png" 2>/dev/null || \
|
||||||
|
echo "Note: Install ImageMagick to generate placeholder icon"
|
||||||
|
fi
|
||||||
APPIMAGE="$PROJECT_ROOT/TrulyMEM.AppImage"
|
APPIMAGE="$PROJECT_ROOT/TrulyMEM.AppImage"
|
||||||
rm -f "$APPIMAGE"
|
rm -f "$APPIMAGE"
|
||||||
echo "===== Step 3: Package as AppImage ====="
|
echo "===== Step 3: Package as AppImage ====="
|
||||||
@ -108,7 +121,17 @@ fi
|
|||||||
echo "===== Build Complete ====="
|
echo "===== Build Complete ====="
|
||||||
[ -f "$APPIMAGE" ] && echo "AppImage: $APPIMAGE" && ls -la "$APPIMAGE"
|
[ -f "$APPIMAGE" ] && echo "AppImage: $APPIMAGE" && ls -la "$APPIMAGE"
|
||||||
[ -d "$APPDIR" ] && echo "AppDir: $APPDIR (can be packaged manually with appimagetool)"
|
[ -d "$APPDIR" ] && echo "AppDir: $APPDIR (can be packaged manually with appimagetool)"
|
||||||
|
echo "===== Cleaning up build artifacts ====="
|
||||||
deactivate
|
deactivate
|
||||||
rm -rf "$VENV_DIR"
|
rm -rf "$VENV_DIR"
|
||||||
|
rm -rf "$PROJECT_ROOT/build/pyinstaller_build"
|
||||||
|
rm -rf "$PROJECT_ROOT/build/pyinstaller_build"
|
||||||
rm -f /tmp/appimagetool
|
rm -f /tmp/appimagetool
|
||||||
|
# Only remove AppDir if AppImage was successfully created
|
||||||
|
if [ -f "$APPIMAGE" ]; then
|
||||||
|
echo "Removing AppDir since AppImage was created successfully"
|
||||||
|
rm -rf "$APPDIR"
|
||||||
|
else
|
||||||
|
echo "Keeping AppDir for manual packaging"
|
||||||
|
fi
|
||||||
echo "Done!"
|
echo "Done!"
|
||||||
@ -107,6 +107,34 @@
|
|||||||
|
|
||||||
## context_rewrite 使用规则
|
## context_rewrite 使用规则
|
||||||
|
|
||||||
|
### ⚠️ 强制触发条件
|
||||||
|
|
||||||
|
**每调用 5 次记忆相关工具,必须调用一次 context_rewrite!**
|
||||||
|
|
||||||
|
记忆相关工具包括:
|
||||||
|
- `memory_recall` - 检索记忆
|
||||||
|
- `memory_commit` - 写入记忆
|
||||||
|
- `memory_purge` - 删除记忆
|
||||||
|
- `memory_introspect` - 查看状态
|
||||||
|
- `persona_update` - 更新人设
|
||||||
|
- `persona_clear` - 清除人设
|
||||||
|
- `task_create` - 创建任务
|
||||||
|
- `task_set_state` - 设置状态
|
||||||
|
- `task_delete` - 删除任务
|
||||||
|
- `task_link_info` - 关联信息
|
||||||
|
|
||||||
|
**触发规则**:
|
||||||
|
- 累计调用 5 次记忆工具 → 必须调用 context_rewrite
|
||||||
|
- 累计调用 10 次记忆工具 → 必须调用 context_rewrite
|
||||||
|
- 以此类推...
|
||||||
|
|
||||||
|
**目的**:
|
||||||
|
- 保持上下文精简,只保留AI真正需要的信息
|
||||||
|
- 避免无用的JSON细节填满上下文
|
||||||
|
- 提高后续推理效率
|
||||||
|
|
||||||
|
### 使用场景
|
||||||
|
|
||||||
当你已经执行了多次工具调用,且:
|
当你已经执行了多次工具调用,且:
|
||||||
- 工具结果的JSON细节你已经理解,不再需要原始格式
|
- 工具结果的JSON细节你已经理解,不再需要原始格式
|
||||||
- 但你需要记住"我调用了哪些工具、得到了什么结论"
|
- 但你需要记住"我调用了哪些工具、得到了什么结论"
|
||||||
@ -230,20 +258,27 @@ AI操作:
|
|||||||
- 查询意图: "TaskNode,工作记忆,任务链"
|
- 查询意图: "TaskNode,工作记忆,任务链"
|
||||||
- 目的: 获取之前的任务上下文,了解对话历史
|
- 目的: 获取之前的任务上下文,了解对话历史
|
||||||
|
|
||||||
2. **用户提到"刚才"、"之前"、"上次"**
|
2. **用户提到"刚才"、"之前"、"上次"、"刚刚"**
|
||||||
- 例: "刚才我们聊了什么?"
|
- 例: "刚才我们聊了什么?"
|
||||||
- 例: "继续刚才的话题"
|
- 例: "继续刚才的话题"
|
||||||
- 例: "关于刚才的成语接龙..."
|
- 例: "关于刚才的成语接龙..."
|
||||||
|
- 例: "我不是刚刚给你讲了个故事嘛"
|
||||||
|
|
||||||
3. **用户询问对话历史**
|
3. **用户使用指代词(这个故事、那个故事、这件事等)**
|
||||||
|
- 例: "你给我整体讲一下这个故事吧" → 必须查询工作记忆链确定"这个故事"指什么
|
||||||
|
- 例: "继续那个任务" → 必须查询工作记忆链确定"那个任务"是什么
|
||||||
|
- 例: "复述一下" → 必须查询工作记忆链确定要复述什么
|
||||||
|
- **关键**: 指代词必须通过工作记忆链解析,不能凭空猜测!
|
||||||
|
|
||||||
|
4. **用户询问对话历史**
|
||||||
- 例: "我们之前说了什么?"
|
- 例: "我们之前说了什么?"
|
||||||
- 例: "我们聊过X吗?"
|
- 例: "我们聊过X吗?"
|
||||||
|
|
||||||
4. **连续性任务被打断后恢复**
|
5. **连续性任务被打断后恢复**
|
||||||
- 例: 用户突然回到之前的话题
|
- 例: 用户突然回到之前的话题
|
||||||
- 例: 用户要求继续之前的任务
|
- 例: 用户要求继续之前的任务
|
||||||
|
|
||||||
5. **涉及上下文的引用**
|
6. **涉及上下文的引用**
|
||||||
- 例: "那个东西"(需要查询上下文)
|
- 例: "那个东西"(需要查询上下文)
|
||||||
- 例: "继续"(需要查询当前任务)
|
- 例: "继续"(需要查询当前任务)
|
||||||
|
|
||||||
@ -374,7 +409,9 @@ AI操作步骤:
|
|||||||
- [ ] 步骤3: 是否根据人设和工作记忆链生成回复?
|
- [ ] 步骤3: 是否根据人设和工作记忆链生成回复?
|
||||||
- [ ] 步骤4: 是否更新了工作记忆链?
|
- [ ] 步骤4: 是否更新了工作记忆链?
|
||||||
- [ ] 涉及上下文引用时是否查询了工作记忆链?
|
- [ ] 涉及上下文引用时是否查询了工作记忆链?
|
||||||
- [ ] 用户提到"刚才/之前/上次"时是否查询了工作记忆链?
|
- [ ] 用户提到"刚才/之前/上次/刚刚"时是否查询了工作记忆链?
|
||||||
|
- [ ] 用户使用指代词(这个故事、那个任务等)时是否通过工作记忆链解析?
|
||||||
|
- [ ] 累计调用5次记忆工具后是否调用了 context_rewrite?
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@ -243,19 +243,23 @@ class BackendServer:
|
|||||||
result = execute_tool(self._graph, tool_call.function.name, args)
|
result = execute_tool(self._graph, tool_call.function.name, args)
|
||||||
result_data = json.loads(result)
|
result_data = json.loads(result)
|
||||||
|
|
||||||
|
# 记录到 tool_calls,让 TUI 显示这个工具调用
|
||||||
|
tool_calls.append({
|
||||||
|
"name": tool_call.function.name,
|
||||||
|
"arguments": args,
|
||||||
|
"result": result
|
||||||
|
})
|
||||||
|
|
||||||
if result_data.get("status") == "success":
|
if result_data.get("status") == "success":
|
||||||
user_msg = messages_history[0]
|
user_msg = messages_history[0]
|
||||||
|
# 添加特殊标记,让 AI 知道这是上下文压缩的结果
|
||||||
|
compressed_content = f"<context_compressed>\n{result_data['summary']}\n</context_compressed>"
|
||||||
messages_history[:] = [
|
messages_history[:] = [
|
||||||
user_msg,
|
user_msg,
|
||||||
{"role": "assistant", "content": result_data["summary"]}
|
{"role": "assistant", "content": compressed_content}
|
||||||
]
|
]
|
||||||
|
# context_rewrite 压缩上下文后,不需要添加 tool 结果消息
|
||||||
tool_result_msg = {
|
# 因为 messages_history 已经被重写为压缩后的状态
|
||||||
"role": "tool",
|
|
||||||
"tool_call_id": tool_call.id,
|
|
||||||
"content": result
|
|
||||||
}
|
|
||||||
current_tool_results.append(tool_result_msg)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
result = execute_tool(self._graph, tool_call.function.name, args)
|
result = execute_tool(self._graph, tool_call.function.name, args)
|
||||||
|
|||||||
@ -179,10 +179,8 @@ body = {} # No parameters
|
|||||||
"model": str # Model name
|
"model": str # Model name
|
||||||
},
|
},
|
||||||
"tool_limits": {
|
"tool_limits": {
|
||||||
"persona_query_max": int, # Persona graph query limit
|
|
||||||
"persona_update_max": int, # Persona graph update limit
|
"persona_update_max": int, # Persona graph update limit
|
||||||
"task_query_max": int, # Working memory query limit
|
"task_update_max": int, # Working memory chain update limit
|
||||||
"task_update_max": int, # Working memory update limit
|
|
||||||
"memory_query_max": int, # General memory query limit
|
"memory_query_max": int, # General memory query limit
|
||||||
"memory_update_max": int # General memory update limit
|
"memory_update_max": int # General memory update limit
|
||||||
}
|
}
|
||||||
@ -211,9 +209,7 @@ body = {
|
|||||||
"model": str # Model name (default: deepseek-chat)
|
"model": str # Model name (default: deepseek-chat)
|
||||||
},
|
},
|
||||||
"tool_limits": {
|
"tool_limits": {
|
||||||
"persona_query_max": int, # Persona query limit (≥1)
|
|
||||||
"persona_update_max": int, # Persona update limit (≥1)
|
"persona_update_max": int, # Persona update limit (≥1)
|
||||||
"task_query_max": int, # Working memory query limit (≥1)
|
|
||||||
"task_update_max": int, # Working memory update limit (≥1)
|
"task_update_max": int, # Working memory update limit (≥1)
|
||||||
"memory_query_max": int, # General memory query limit (≥1)
|
"memory_query_max": int, # General memory query limit (≥1)
|
||||||
"memory_update_max": int # General memory update limit (≥1)
|
"memory_update_max": int # General memory update limit (≥1)
|
||||||
@ -237,8 +233,8 @@ result = client.update_settings(
|
|||||||
"model": "deepseek-chat"
|
"model": "deepseek-chat"
|
||||||
},
|
},
|
||||||
tool_limits={
|
tool_limits={
|
||||||
"persona_query_max": 2,
|
"persona_update_max": 2,
|
||||||
"task_query_max": 5,
|
"task_update_max": 5,
|
||||||
"memory_query_max": 30
|
"memory_query_max": 30
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@ -153,7 +153,7 @@ def main():
|
|||||||
- `memory_introspect` - View status
|
- `memory_introspect` - View status
|
||||||
- `memory_archive` - Archive memory
|
- `memory_archive` - Archive memory
|
||||||
- `memory_cleanup` - Clean data
|
- `memory_cleanup` - Clean data
|
||||||
- `context_rewrite` - Compress single-turn tool call context (experimental)
|
- `context_rewrite` - Compress single-turn tool call context
|
||||||
|
|
||||||
### Persona Tools (2)
|
### Persona Tools (2)
|
||||||
- `persona_update` - Update persona
|
- `persona_update` - Update persona
|
||||||
|
|||||||
@ -66,6 +66,9 @@ Step 4: Update working memory chain
|
|||||||
| `memory_commit` | Write memory |
|
| `memory_commit` | Write memory |
|
||||||
| `memory_purge` | Delete memory |
|
| `memory_purge` | Delete memory |
|
||||||
| `memory_introspect` | View status |
|
| `memory_introspect` | View status |
|
||||||
|
| `memory_archive` | Archive memory |
|
||||||
|
| `memory_cleanup` | Clean data |
|
||||||
|
| `context_rewrite` | Compress single-turn tool call context |
|
||||||
|
|
||||||
#### Persona Tools
|
#### Persona Tools
|
||||||
|
|
||||||
|
|||||||
@ -185,10 +185,8 @@ body = {} # 无参数
|
|||||||
"model": str # 模型名称
|
"model": str # 模型名称
|
||||||
},
|
},
|
||||||
"tool_limits": {
|
"tool_limits": {
|
||||||
"persona_query_max": int, # 人设图查询上限
|
|
||||||
"persona_update_max": int, # 人设图修改上限
|
"persona_update_max": int, # 人设图修改上限
|
||||||
"task_query_max": int, # 工作记忆查询上限
|
"task_update_max": int, # 工作记忆链修改上限
|
||||||
"task_update_max": int, # 工作记忆修改上限
|
|
||||||
"memory_query_max": int, # 一般记忆查询上限
|
"memory_query_max": int, # 一般记忆查询上限
|
||||||
"memory_update_max": int # 一般记忆修改上限
|
"memory_update_max": int # 一般记忆修改上限
|
||||||
}
|
}
|
||||||
@ -217,11 +215,9 @@ body = {
|
|||||||
"model": str # 模型名称 (默认: deepseek-chat)
|
"model": str # 模型名称 (默认: deepseek-chat)
|
||||||
},
|
},
|
||||||
"tool_limits": {
|
"tool_limits": {
|
||||||
"persona_query_max": int, # 人设图查询上限 (≥1)
|
|
||||||
"persona_update_max": int, # 人设图修改上限 (≥1)
|
"persona_update_max": int, # 人设图修改上限 (≥1)
|
||||||
"task_query_max": int, # 工作记忆查询上限 (≥1)
|
"task_update_max": int, # 工作记忆链修改上限 (≥1)
|
||||||
"task_update_max": int, # 工作记忆修改上限 (≥1)
|
"memory_query_max": int, # 一般记忆查询上限 (≥1)
|
||||||
"memory_query_max": int, # 一般记忆查询上限 (≥1)
|
|
||||||
"memory_update_max": int # 一般记忆修改上限 (≥1)
|
"memory_update_max": int # 一般记忆修改上限 (≥1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -243,8 +239,8 @@ result = client.update_settings(
|
|||||||
"model": "deepseek-chat"
|
"model": "deepseek-chat"
|
||||||
},
|
},
|
||||||
tool_limits={
|
tool_limits={
|
||||||
"persona_query_max": 2,
|
"persona_update_max": 2,
|
||||||
"task_query_max": 5,
|
"task_update_max": 5,
|
||||||
"memory_query_max": 30
|
"memory_query_max": 30
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@ -153,7 +153,7 @@ def main():
|
|||||||
- `memory_introspect` - 查看状态
|
- `memory_introspect` - 查看状态
|
||||||
- `memory_archive` - 归档记忆
|
- `memory_archive` - 归档记忆
|
||||||
- `memory_cleanup` - 清理数据
|
- `memory_cleanup` - 清理数据
|
||||||
- `context_rewrite` - 压缩单轮工具调用上下文(实验性)
|
- `context_rewrite` - 压缩单轮工具调用上下文
|
||||||
|
|
||||||
### 人设工具 (2个)
|
### 人设工具 (2个)
|
||||||
- `persona_update` - 更新人设
|
- `persona_update` - 更新人设
|
||||||
|
|||||||
@ -25,7 +25,7 @@ TrulyMEM 的解决思路:
|
|||||||
所有记忆必须通过以下方式读取:
|
所有记忆必须通过以下方式读取:
|
||||||
- `memory_recall` - 检索记忆
|
- `memory_recall` - 检索记忆
|
||||||
|
|
||||||
### 工作记忆管理(实验性)
|
### 工作记忆管理
|
||||||
|
|
||||||
`context_rewrite` 允许 AI 在单轮对话内主动压缩工具调用的临时上下文:
|
`context_rewrite` 允许 AI 在单轮对话内主动压缩工具调用的临时上下文:
|
||||||
- 将冗长的 JSON 工具结果提炼为简洁的自然语言摘要
|
- 将冗长的 JSON 工具结果提炼为简洁的自然语言摘要
|
||||||
|
|||||||
@ -66,6 +66,9 @@ system_prompt = prompt_manager.get_system_prompt()
|
|||||||
| `memory_commit` | 写入记忆 |
|
| `memory_commit` | 写入记忆 |
|
||||||
| `memory_purge` | 删除记忆 |
|
| `memory_purge` | 删除记忆 |
|
||||||
| `memory_introspect` | 查看状态 |
|
| `memory_introspect` | 查看状态 |
|
||||||
|
| `memory_archive` | 归档记忆 |
|
||||||
|
| `memory_cleanup` | 清理数据 |
|
||||||
|
| `context_rewrite` | 压缩单轮工具调用上下文 |
|
||||||
|
|
||||||
#### 人设工具
|
#### 人设工具
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user