Files
TrulyMEM-TrueHumanMEM/test_message_order.py
JianFeeeee b7a6a3c1a9 Enhance: Add detailed usage examples for all memory tools
为所有记忆工具添加详细的使用示例,帮助AI理解工具的作用和使用方法:
1. memory_recall: 添加查询人设图、工作记忆链、用户偏好等示例
2. memory_commit: 添加记录用户偏好、项目信息、游戏状态等示例
3. memory_purge: 添加软删除、纠错替代等示例
4. persona_update: 添加切换角色、添加属性等示例
5. task_create: 添加创建任务节点的完整流程示例
6. task_set_state: 添加任务状态转换的完整流程示例
7. task_link_info: 添加关联信息节点的完整流程示例

更新系统提示词:
- 强化工作记忆链机制说明
- 添加完整的成语接龙游戏示例(三轮对话)
- 明确强制查询和更新场景
- 强调工作记忆链是唯一上下文载体

解决问题: AI无法通过自己写入的记忆链恢复上下文记忆

Generated with CodeArts Agent
2026-04-12 11:09:31 +08:00

55 lines
1.8 KiB
Python

"""测试消息顺序"""
from graph_memory_tui.core.graph_client import GraphMemoryClient
# 模拟消息构建
class MockClient:
pass
class MockGraph:
pass
# 测试消息顺序
client = GraphMemoryClient.__new__(GraphMemoryClient)
client.client = MockClient()
client.graph = MockGraph()
client.tools = []
client.system_prompt = 'You are a helpful assistant.'
# 模拟第一次调用(无工具结果)
print('=== 第一次调用(无工具结果)===')
messages = [{'role': 'system', 'content': client.system_prompt}]
messages.append({'role': 'user', 'content': '你好'})
for i, msg in enumerate(messages):
content = str(msg.get('content', ''))[:50]
print(f'{i+1}. {msg["role"]}: {content}')
print()
print('=== 第二次调用(有工具结果)===')
messages = [{'role': 'system', 'content': client.system_prompt}]
messages.append({'role': 'user', 'content': '你好'})
messages.append({
'role': 'assistant',
'content': None,
'tool_calls': [{'id': 'call_123', 'type': 'function', 'function': {'name': 'memory_recall', 'arguments': '{}'}}]
})
messages.append({'role': 'tool', 'tool_call_id': 'call_123', 'content': '查询结果...'})
for i, msg in enumerate(messages):
role = msg.get('role')
if role == 'tool':
tid = msg.get('tool_call_id')
print(f'{i+1}. {role}: tool_call_id={tid}')
elif role == 'assistant' and msg.get('tool_calls'):
tc_count = len(msg.get('tool_calls'))
print(f'{i+1}. {role}: tool_calls={tc_count}')
else:
content = str(msg.get('content', ''))[:50]
print(f'{i+1}. {role}: {content}')
print()
print('✅ 消息顺序正确!')
print('AI 可以看到:')
print('1. 用户说了什么')
print('2. 自己调用了什么工具')
print('3. 工具返回了什么结果')