feat: 添加记忆自动化钩子与回写

在接收和发送消息时注册记忆自动化,并重构人物记忆回写逻辑以使用 memory_service.ingest_text。主要改动如下:

在接收消息时调用 memory_automation_service.on_incoming_message(bot 侧),在发送消息时调用 on_message_sent(send_service 侧),并加入安全的错误处理。
在 person_info 中,用 memory_service.ingest_text 替换手动操作 person.memory_points 的方式;新增 resolve_person_id_for_memory 辅助方法,并为回写计算一个 external_id 指纹。
扩展插件运行时的记忆搜索能力,使其支持 mode、chat_id、person_id、user_id、group_id、时间范围以及 respect_filter 选项。
改进 find_messages 的数据库会话处理,改为使用单一 session,并修复排序和过滤逻辑。
从 KnowledgeFetcher 中移除未使用的 LLMRequest 导入和初始化。
更新术语解释器(jargon explainer)的导入路径,使用新的模块位置。
更新 .gitignore 例外规则,允许特定的 pytest 数据文件被纳入版本控制。
文档小调整:明确人物事实提取规则(将直接使用的 “you” 改写为第三人称)。
This commit is contained in:
A-Dawn
2026-03-31 15:49:49 +08:00
parent ea9a1b5802
commit a004c59e1e
9 changed files with 170 additions and 88 deletions

View File

@@ -325,6 +325,13 @@ class ChatBot:
scope=scope,
) # 确保会话存在
try:
from src.services.memory_flow_service import memory_automation_service
await memory_automation_service.on_incoming_message(message)
except Exception as exc:
logger.warning(f"[{session_id}] 长期记忆自动摘要注册失败: {exc}")
# message.update_chat_stream(chat)
# 命令处理 - 使用新插件系统检查并处理命令。