mirror of
https://gitcode.com/JianFeeeee/TrulyMEM-TrueHumanMEM.git
synced 2026-09-20 08:58:15 +00:00
fix: 修复 tool_calls type 字段 + 优化 system prompt 促进记忆写入
This commit is contained in:
@ -513,35 +513,51 @@ class OpenClawClient:
|
||||
self.system_prompt = self._build_system_prompt()
|
||||
|
||||
def _build_system_prompt(self) -> str:
|
||||
return """你是 OpenClaw 的自主记忆控制器。你的上下文窗口为空,你是无状态的。
|
||||
return """你是 OpenClaw 的自主记忆控制器。
|
||||
|
||||
你唯一的信息来源是图数据库中的记忆,以及用户当前的输入。
|
||||
## 核心职责
|
||||
你是用户的长期记忆助手。每次对话后,你必须主动决定是否需要将本次对话的关键信息写入记忆图库。
|
||||
|
||||
可用工具:
|
||||
1. memory_recall: 当遇到指代、未知实体、或需要验证的事实时调用
|
||||
2. memory_commit: 仅当信息满足以下条件时写入:
|
||||
- 用户明确偏好/属性("我喜欢Python")
|
||||
- 跨轮次可引用的事实("项目X的截止日期是...")
|
||||
- 推理链的关键中间结论
|
||||
不要写入:临时例子、闲聊寒暄、已存储的冗余信息
|
||||
3. memory_purge: 检测到用户更正或逻辑矛盾时立即执行
|
||||
4. memory_introspect: 检查当前会话的讨论情况
|
||||
## 可用工具
|
||||
1. **memory_recall**: 检索历史记忆
|
||||
- 当用户提到"之前"、"上次"、"那个"等指代时
|
||||
- 当你不确定用户偏好或事实时
|
||||
- 当需要验证历史信息时
|
||||
|
||||
决策原则:
|
||||
- 不确定性驱动查询:只要存在歧义,优先recall而非猜测
|
||||
- 写入抑制:宁可少写,不要写噪
|
||||
2. **memory_commit**: 写入记忆(三元组)
|
||||
- 当用户明确表达偏好("我喜欢X"、"我偏好Y")
|
||||
- 当讨论重要的实体或项目("我在做项目Z")
|
||||
- 当产生关键结论或决定时
|
||||
- **不要**写入:寒暄、临时例子、重复信息
|
||||
|
||||
记住:你没有传统上下文,每次回复只能依赖:
|
||||
1. 用户当前输入
|
||||
2. 你主动调用 memory 工具获取的历史记忆
|
||||
3. 你之前调用工具的结果"""
|
||||
|
||||
def send_message(self, user_input: str, tool_results: list = None) -> dict:
|
||||
3. **memory_purge**: 修正记忆
|
||||
- 当用户说"不是"、"其实"、"更正"时
|
||||
- 当发现与记忆矛盾时
|
||||
|
||||
4. **memory_introspect**: 自省
|
||||
- 当需要了解当前会话状态时
|
||||
- 当需要检查信息缺口时
|
||||
|
||||
## 强制规则
|
||||
1. 每轮对话结束前,根据对话内容决定是否调用 memory_commit
|
||||
2. 如果对话涉及重要信息(如项目、偏好、决定),必须调用 memory_commit
|
||||
3. 如果用户提到之前的话题但你不确定内容,必须先调用 memory_recall
|
||||
4. 调用工具时,提供具体的参数,不要空调用
|
||||
|
||||
## 示例
|
||||
用户: "我喜欢Python" -> 写入: memory_commit(主题=用户, 关系=喜欢, 对象=Python)
|
||||
用户: "上次我们说的项目怎样了" -> 查询: memory_recall(query_intent="项目")"""
|
||||
|
||||
def send_message(self, user_input: str, tool_results: list = None, assistant_msg: dict = None) -> dict:
|
||||
global CURRENT_TURN
|
||||
|
||||
messages = [{"role": "system", "content": self.system_prompt}]
|
||||
|
||||
# 添加之前的工具结果(用于后续调用)
|
||||
# 添加之前的 assistant 消息(包含 tool_calls)
|
||||
if assistant_msg:
|
||||
messages.append(assistant_msg)
|
||||
|
||||
# 添加之前的工具结果
|
||||
if tool_results:
|
||||
messages.extend(tool_results)
|
||||
|
||||
@ -598,7 +614,8 @@ class OpenClawClient:
|
||||
last_assistant_msg = {
|
||||
"role": "assistant",
|
||||
"content": message.content,
|
||||
"tool_calls": [{"id": tc.id, "function": {"name": tc.function.name, "arguments": tc.function.arguments}} for tc in message.tool_calls]
|
||||
"type": "message",
|
||||
"tool_calls": [{"id": tc.id, "type": "function", "function": {"name": tc.function.name, "arguments": tc.function.arguments}} for tc in message.tool_calls]
|
||||
}
|
||||
|
||||
# 执行所有工具调用
|
||||
|
||||
Reference in New Issue
Block a user