mirror of https://github.com/Mai-with-u/MaiBot.git
fix:优化agent模式提取逻辑,修复配置文件版本问题
parent
060ce5d55b
commit
0d13b576d7
|
|
@ -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 的新版本部署方式(与旧版本不兼容)
|
||||
|
|
|
|||
|
|
@ -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学习系统
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
[inner]
|
||||
version = "6.21.4"
|
||||
version = "6.21.5"
|
||||
|
||||
#----以下是给开发人员阅读的,如果你只是部署了麦麦,不需要阅读----
|
||||
#如果你想要修改配置文件,请递增version的值
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
[inner]
|
||||
version = "1.7.7"
|
||||
version = "1.7.8"
|
||||
|
||||
# 配置文件版本号迭代规则同bot_config.toml
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue