From 0d13b576d7b44edd5f9557ef10cba1083c6236a2 Mon Sep 17 00:00:00 2001 From: SengokuCola <1026294844@qq.com> Date: Mon, 17 Nov 2025 18:19:39 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BC=98=E5=8C=96agent=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E6=8F=90=E5=8F=96=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 ++- changelogs/changelog.md | 7 +++- src/config/config.py | 2 +- src/memory_system/memory_retrieval.py | 59 +++++++++++++++++++-------- template/bot_config_template.toml | 2 +- template/model_config_template.toml | 2 +- 6 files changed, 55 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 03eac57b..a37896f8 100644 --- a/README.md +++ b/README.md @@ -44,14 +44,16 @@ ## 🔥 更新和安装 -**最新版本: v0.11.0** ([更新日志](changelogs/changelog.md)) +**最新版本: v0.11.3** ([更新日志](changelogs/changelog.md)) 可前往 [Release](https://github.com/MaiM-with-u/MaiBot/releases/) 页面下载最新版本 可前往 [启动器发布页面](https://github.com/MaiM-with-u/mailauncher/releases/)下载最新启动器 **GitHub 分支说明:** - `main`: 稳定发布版本(推荐) + + - `dev`: 开发测试版本(不稳定) -- `classical`: 旧版本(停止维护) +- `classical`: 经典版本(停止维护) ### 最新版本部署教程 - [🚀 最新版本部署教程](https://docs.mai-mai.org/manual/deployment/mmc_deploy_windows.html) - 基于 MaiCore 的新版本部署方式(与旧版本不兼容) diff --git a/changelogs/changelog.md b/changelogs/changelog.md index 1b01a405..a1de221a 100644 --- a/changelogs/changelog.md +++ b/changelogs/changelog.md @@ -1,6 +1,11 @@ # Changelog -## [0.11.2] - 2025-11-15 +## [0.11.3] - 2025-11-17 +### 功能更改和修复 +- 优化记忆提取策略 +- 修改readme + +## [0.11.2] - 2025-11-16 ### 🌟 主要功能更改 - "海马体Agent"记忆系统上线,最新最好的记忆系统,默认已接入lpmm - 添加黑话jargon学习系统 diff --git a/src/config/config.py b/src/config/config.py index f0810756..29619e45 100644 --- a/src/config/config.py +++ b/src/config/config.py @@ -56,7 +56,7 @@ TEMPLATE_DIR = os.path.join(PROJECT_ROOT, "template") # 考虑到,实际上配置文件中的mai_version是不会自动更新的,所以采用硬编码 # 对该字段的更新,请严格参照语义化版本规范:https://semver.org/lang/zh-CN/ -MMC_VERSION = "0.11.2" +MMC_VERSION = "0.11.3" def get_key_comment(toml_table, key): diff --git a/src/memory_system/memory_retrieval.py b/src/memory_system/memory_retrieval.py index a878f14d..0df5d73c 100644 --- a/src/memory_system/memory_retrieval.py +++ b/src/memory_system/memory_retrieval.py @@ -15,6 +15,35 @@ from src.llm_models.payload_content.message import MessageBuilder, RoleType, Mes logger = get_logger("memory_retrieval") +THINKING_BACK_NOT_FOUND_RETENTION_SECONDS = 3600 # 未找到答案记录保留时长 +THINKING_BACK_CLEANUP_INTERVAL_SECONDS = 300 # 清理频率 +_last_not_found_cleanup_ts: float = 0.0 + + +def _cleanup_stale_not_found_thinking_back() -> None: + """定期清理过期的未找到答案记录""" + global _last_not_found_cleanup_ts + + now = time.time() + if now - _last_not_found_cleanup_ts < THINKING_BACK_CLEANUP_INTERVAL_SECONDS: + return + + threshold_time = now - THINKING_BACK_NOT_FOUND_RETENTION_SECONDS + try: + deleted_rows = ( + ThinkingBack.delete() + .where( + (ThinkingBack.found_answer == 0) & + (ThinkingBack.update_time < threshold_time) + ) + .execute() + ) + if deleted_rows: + logger.info(f"清理过期的未找到答案thinking_back记录 {deleted_rows} 条") + _last_not_found_cleanup_ts = now + except Exception as e: + logger.error(f"清理未找到答案的thinking_back记录失败: {e}") + def init_memory_retrieval_prompt(): """初始化记忆检索相关的 prompt 模板和工具""" # 首先注册所有工具 @@ -312,8 +341,7 @@ async def _retrieve_concepts_with_jargon( results.append(";".join(output_parts) if len(output_parts) > 1 else output_parts[0]) logger.info(f"在jargon库中找到匹配(精确匹配): {concept},找到{len(jargon_results)}条结果") else: - # 未找到 - results.append(f"未在jargon库中找到'{concept}'的解释") + # 未找到,不返回占位信息,只记录日志 logger.info(f"在jargon库中未找到匹配: {concept}") if results: @@ -351,11 +379,10 @@ async def _retrieve_persons_info( results.append(f"【{person}】\n{person_info}") logger.info(f"查询到人物信息: {person}") else: - results.append(f"未找到人物'{person}'的信息") + # 未找到时不插入占位信息 logger.info(f"未找到人物信息: {person}") except Exception as e: logger.error(f"查询人物信息失败: {person}, 错误: {e}") - results.append(f"查询人物'{person}'信息时发生错误: {str(e)}") if results: return "【人物信息检索结果】\n" + "\n\n".join(results) + "\n" @@ -997,6 +1024,8 @@ async def _process_single_question( Optional[str]: 如果找到答案,返回格式化的结果字符串,否则返回None """ logger.info(f"开始处理问题: {question}") + + _cleanup_stale_not_found_thinking_back() # 先检查thinking_back数据库中是否有现成答案 cached_result = _query_thinking_back(chat_id, question) @@ -1005,26 +1034,22 @@ async def _process_single_question( if cached_result: cached_found_answer, cached_answer = cached_result - # 根据found_answer的值决定是否重新查询 if cached_found_answer: # found_answer == 1 (True) # found_answer == 1:20%概率重新查询 - if random.random() < 0.2: + if random.random() < 0.5: should_requery = True logger.info(f"found_answer=1,触发20%概率重新查询,问题: {question[:50]}...") - else: # found_answer == 0 (False) - # found_answer == 0:40%概率重新查询 - if random.random() < 0.4: - should_requery = True - logger.info(f"found_answer=0,触发40%概率重新查询,问题: {question[:50]}...") - - # 如果不需要重新查询,使用缓存答案 - if not should_requery: - if cached_answer: + + if not should_requery and cached_answer: logger.info(f"从thinking_back缓存中获取答案,问题: {question[:50]}...") return f"问题:{question}\n答案:{cached_answer}" - else: - # 缓存中没有答案,需要查询 + elif not cached_answer: should_requery = True + logger.info(f"found_answer=1 但缓存答案为空,重新查询,问题: {question[:50]}...") + else: + # found_answer == 0:不使用缓存,直接重新查询 + should_requery = True + logger.info(f"thinking_back存在但未找到答案,忽略缓存重新查询,问题: {question[:50]}...") # 如果没有缓存答案或需要重新查询,使用ReAct Agent查询 if not cached_result or should_requery: diff --git a/template/bot_config_template.toml b/template/bot_config_template.toml index cc540e6a..aaf3486a 100644 --- a/template/bot_config_template.toml +++ b/template/bot_config_template.toml @@ -1,5 +1,5 @@ [inner] -version = "6.21.4" +version = "6.21.5" #----以下是给开发人员阅读的,如果你只是部署了麦麦,不需要阅读---- #如果你想要修改配置文件,请递增version的值 diff --git a/template/model_config_template.toml b/template/model_config_template.toml index 998c2c13..6d956ace 100644 --- a/template/model_config_template.toml +++ b/template/model_config_template.toml @@ -1,5 +1,5 @@ [inner] -version = "1.7.7" +version = "1.7.8" # 配置文件版本号迭代规则同bot_config.toml