feat: 重构聊天系统的内存处理与格式化功能
- 更新了DefaultReplyer,采用新的内存格式化工具以提供更优质的内存描述。 - 已移除 Config 类中已弃用的内存配置。 - 在主系统中增强内存系统初始化检查,确保配置正确。 - 优化了MemoryManager,使其可直接使用全局配置进行内存设置。 - 新增了一个内存格式化工具,用于将内存对象转换为自然语言描述。 - 更新了内存工具,提供了更清晰的内存创建与管理指南。 - 精炼插件工具与使用提示,提升用户交互体验与记忆准确性。 - 根据内存系统结构的变化调整了机器人配置模板。
This commit is contained in:
@@ -585,17 +585,29 @@ class DefaultReplyer:
|
||||
|
||||
if memories:
|
||||
logger.info(f"[记忆图] 检索到 {len(memories)} 条相关记忆")
|
||||
|
||||
# 使用新的格式化工具构建完整的记忆描述
|
||||
from src.memory_graph.utils.memory_formatter import (
|
||||
format_memory_for_prompt,
|
||||
get_memory_type_label,
|
||||
)
|
||||
|
||||
for memory in memories:
|
||||
topic = memory.metadata.get("topic", "")
|
||||
mem_type = memory.metadata.get("memory_type", "未知")
|
||||
if topic:
|
||||
# 使用格式化工具生成完整的主谓宾描述
|
||||
content = format_memory_for_prompt(memory, include_metadata=False)
|
||||
|
||||
# 获取记忆类型
|
||||
mem_type = memory.memory_type.value if memory.memory_type else "未知"
|
||||
|
||||
if content:
|
||||
all_memories.append({
|
||||
"content": topic,
|
||||
"content": content,
|
||||
"memory_type": mem_type,
|
||||
"importance": memory.importance,
|
||||
"relevance": 0.7,
|
||||
"source": "memory_graph",
|
||||
})
|
||||
logger.debug(f"[记忆构建] 格式化记忆: [{mem_type}] {content[:50]}...")
|
||||
else:
|
||||
logger.debug("[记忆图] 未找到相关记忆")
|
||||
except Exception as e:
|
||||
@@ -629,8 +641,13 @@ class DefaultReplyer:
|
||||
logger.debug(f"[记忆构建] 空记忆详情: {running_memory}")
|
||||
continue
|
||||
|
||||
# 使用全局记忆类型映射表
|
||||
chinese_type = get_memory_type_chinese_label(memory_type)
|
||||
# 使用记忆图的类型映射(优先)或全局映射
|
||||
try:
|
||||
from src.memory_graph.utils.memory_formatter import get_memory_type_label
|
||||
chinese_type = get_memory_type_label(memory_type)
|
||||
except ImportError:
|
||||
# 回退到全局映射
|
||||
chinese_type = get_memory_type_chinese_label(memory_type)
|
||||
|
||||
# 提取纯净内容(如果包含旧格式的元数据)
|
||||
clean_content = content
|
||||
|
||||
Reference in New Issue
Block a user