Skip to content

feat: 修复了一些 issues 中的 bug,新增了待总结聊天内容的相关命令,新增了聊天中断一段时间后的自动总结功能,新增了给记忆注入附带时间信息的选项,新增了对于图片转述内容的支持#73

Open
mkaros2025 wants to merge 1 commit intolxfight-s-Astrbot-Plugins:masterfrom
mkaros2025:dev1

Conversation

@mkaros2025
Copy link

@mkaros2025 mkaros2025 commented Feb 16, 2026

📋 变更概览

类型 数量
新增功能 5 项
Bug 修复 2 项
精简内容 3 项
文件变更 22 个
代码行变化 +1449 / -1860

✨ 新增功能

1. 会话级隔离(conversation_id 集成)

2. Pending 管理命令

新增两个管理员命令,方便用户管理待总结内容:

命令 说明
/lmem pending [数量] 查看当前会话待总结消息预览,显示距离自动总结还需多少轮
/lmem pending-del <序号> 删除待总结中的指定轮次,支持精确控制总结内容

3. 图片转述内容的召回与总结支持

新增了对于图片转述内容的记忆召回支持和记忆总结支持

4. 空闲自动总结

新增了当会话在指定时间内无新消息时,自动归纳当前未总结的对话内容的功能

  • 新增 run_idle_summary_check() 空闲会话扫描功能
  • 新增配置项:
    • reflection_engine.enable_idle_auto_summary - 是否启用(默认关闭)
    • reflection_engine.idle_summary_timeout_seconds - 超时时间(默认 1800 秒)

5. 记忆注入带时间

  • 新增配置项 recall_engine.include_memory_time
  • 开启后,在注入给模型的记忆条目中显示记忆发生时间(格式:x年x月x日HH:MM)

6. 总结任务防丢失机制

  • 新增 _sessions_summarizing_sessions_summary_rerun_requested 集合
  • 防止同一会话并发重复总结导致的内容丢失
  • 当总结任务执行期间有新消息进入时,自动标记并在完成后重跑

🐛 Bug 修复

1. 初始化流程改进

  • 修复初始化进入后台重试时处理器未绑定的问题
  • 新增 _bind_runtime_handlers() 幂等绑定处理器
  • 确保 initializer 完成后正确绑定事件/命令处理器

2. WebUI 句柄同步

  • 修复 WebUI 启动后 /lmem webui 误判未启用的问题
  • WebUI 启动后自动同步句柄到命令处理器

🗑️ 精简内容

1. 删除冗余的 sparse_retriever.py

  • 删除 core/retrieval/sparse_retriever.py(514 行)
  • 该文件与 bm25_retriever.py 功能重复,且未被任何模块引用
  • 删除相关配置项 sparse_retrieverdense_retriever

2. 精简 ConversationManager 无用代码

移除以下从未被调用的冗余代码:

  • LRU 缓存机制(_cache, _cache_lock
  • 缓存相关方法(_update_cache, _get_from_cache, invalidate_cache, _evict_cache
  • cleanup_expired_sessions() 方法
  • 构造参数(max_cache_size, context_window_size, session_ttl

3. 精简废弃配置项

移除以下不再使用的配置:

  • session_manager.max_sessions
  • session_manager.session_ttl
  • session_manager.context_window_size

🧪 测试建议

我在私聊场景下测试了很多条聊天,没有出现什么 bug,但是没有做群聊场景下的测试,所以没法保证群聊场景下正常

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

该 PR 主要围绕“会话级隔离 + 待总结/自动总结能力增强 + 图片转述支持 + 配置与冗余清理”展开,目标是修复 /new//reset 后跨会话串扰(Issue #70),并补齐对图片轮次与空闲场景的总结/记忆流程支持。

Changes:

  • 引入 conversation_id 参与 session key 构建,实现同一聊天源下的“对话窗口级”隔离,并增加总结任务防丢失/重跑机制
  • 新增 /lmem pending/lmem pending-del 管理待总结窗口;新增空闲自动总结巡检;支持图片转述内容的召回/落库/总结
  • 清理冗余模块与配置项(移除 sparse_retriever、ConversationManager 缓存/TTL 等),并同步更新配置校验与 schema(但文档示例仍需补齐)

Reviewed changes

Copilot reviewed 21 out of 22 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
storage/conversation_store.py get_recent_sessions() 支持 limit=None,为全量会话扫描提供接口
main.py 初始化绑定幂等化;WebUI 句柄同步;启动空闲自动总结后台巡检;新增 pending 命令入口
docs/ARCHITECTURE.md 更新架构文件树,移除已删除的 sparse_retriever 记录
docs/API.md 更新配置示例中的 session_manager 字段(但未覆盖本 PR 新增配置项)
core/utils/init.py 记忆注入格式支持可选显示“发生时间”(中文年月日时分格式)
core/retrieval/vector_retriever.py 移除查询预处理逻辑与相关配置依赖
core/retrieval/sparse_retriever.py 删除冗余稀疏检索器实现文件
core/plugin_initializer.py ConversationManager 初始化参数精简(移除未使用的缓存/窗口/TTL 配置)
core/managers/conversation_manager.py 移除 LRU 缓存与过期清理;支持外部传入更细粒度 session_id;默认上下文窗口固定为 50
core/event_handler.py conversation_id 会话隔离;图片转述提取/补写;严格从当前 req 提取本轮输入;空闲自动总结扫描;总结并发防丢失与重跑
core/command_handler.py WebUI 地址展示改为多地址;reset 支持对话窗口隔离;新增 pending/pending-del;新增会话键解析 helper
core/base/config_validator.py 配置项增删:新增 capture_image_caption / include_memory_time / idle auto summary;移除 sparse/dense retriever 配置
_conf_schema.json 同步配置 schema:新增图片描述写库、注入带时间、空闲自动总结等字段;移除稀疏/稠密检索器配置
.gitignore 忽略本地 issue 跟踪文件 LOCAL_ISSUES.md
.github/workflows/* 删除多个自动化工作流文件
.github/ISSUE_TEMPLATE/* 删除 issue 模板相关文件

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 380 to 383
"session_manager": {
"max_sessions": 100,
"session_ttl": 3600,
"context_window_size": 50
"enable_full_group_capture": true,
"max_messages_per_session": 1000
},
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

配置示例里没有包含本 PR 新增/调整的配置项(例如 session_manager.capture_image_caption、recall_engine.include_memory_time、reflection_engine.enable_idle_auto_summary / idle_summary_timeout_seconds),容易让读者按文档配置后发现功能不生效。建议同步更新此处的“完整配置示例”以覆盖新增字段,并说明已移除的旧字段(max_sessions/session_ttl/context_window_size)。

Copilot uses AI. Check for mistakes.
triggered = 0

try:
sessions = await self.conversation_manager.get_recent_sessions(limit=None)
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里使用 limit=None 拉取所有 sessions 并逐个做多次 DB 查询(message_count/metadata/messages_range),会在会话数量较大时造成明显的周期性 IO 开销。建议在 store 层用 SQL 直接按 last_active_at < now-timeout 过滤并分页/限制数量,或按 last_active_at 升序扫描并在遇到未超时的会话时提前结束。

Suggested change
sessions = await self.conversation_manager.get_recent_sessions(limit=None)
max_sessions = int(
self.config_manager.get(
"reflection_engine.idle_summary_max_sessions", 200
)
)
sessions = await self.conversation_manager.get_recent_sessions(
limit=max_sessions
)

Copilot uses AI. Check for mistakes.
Comment on lines +1503 to +1506
logger.info(
f"[{session_id}] [RecallShape] prompt_has={has_prompt}, prompt_len={prompt_len}, "
f"contexts_count={contexts_count}, event_text_len={event_text_len}, "
f"event_components={component_types}, image_hints={image_hints}, "
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RecallShape 诊断日志使用 logger.info,并包含 extra_preview / tail_text_preview 等用户消息内容预览,可能在生产日志中泄露隐私数据。建议将这类包含用户内容的日志降级为 debug(或加显式开关/脱敏),并确保预览长度在任何 level 都可控。

Copilot uses AI. Check for mistakes.
Comment on lines +710 to +716
async def _resolve_conversation_session_id(self, event: AstrMessageEvent) -> str:
"""
解析插件内部会话ID:unified_msg_origin + conversation_id。
回退策略:无法获取conversation_id时返回unified_msg_origin。
"""
base_session_id = event.unified_msg_origin
if not self.context or not hasattr(self.context, "conversation_manager"):
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conversation_id 解析逻辑在 EventHandler._build_conversation_session_id 与 CommandHandler._resolve_conversation_session_id 中重复实现,后续若拼接格式/回退策略调整容易出现行为不一致。建议抽到共享 helper(或集中定义拼接常量)并在两处复用。

Copilot uses AI. Check for mistakes.
Comment on lines +601 to +605
def _get_webui_urls(self) -> list[str]:
"""获取 WebUI 可访问地址列表(优先可直连地址)"""
webui_config = self.config_manager.webui_settings
if not webui_config.get("enabled") or not self.webui_server:
return None
return []
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_get_webui_url 被替换为 _get_webui_urls 后,仓库内仍有调用点依赖旧方法(例如 tests/test_command_handler.py 里直接调用 _get_webui_url),会导致测试/CI 失败。建议保留一个 _get_webui_url() 薄封装(返回第一个可用地址或 None)或同步更新所有调用点。

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants