Skip to content

Feature/a memorix disabled by default#1624

Merged
SengokuCola merged 2 commits into
Mai-with-u:devfrom
A-Dawn:feature/a-memorix-disabled-by-default
May 3, 2026
Merged

Feature/a memorix disabled by default#1624
SengokuCola merged 2 commits into
Mai-with-u:devfrom
A-Dawn:feature/a-memorix-disabled-by-default

Conversation

@A-Dawn
Copy link
Copy Markdown
Collaborator

@A-Dawn A-Dawn commented May 3, 2026

  • ✅ 接受:与main直接相关的Bug修复:提交到dev分支
  • 新增功能类pr需要经过issue提前讨论,否则不会被合并
  • 🌐 i18n 提醒:除 bootstrap 或紧急修复外,请不要把非 zh-CN 目标翻译作为常规 GitHub 编辑面;常规翻译以 Crowdin -> l10n_* PR 回流为准,详见 docs/i18n.md

请填写以下内容

(删除掉中括号内的空格,并替换为小写的x

    • main 分支 禁止修改,请确认本次提交的分支 不是 main 分支
    • 我确认我阅读了贡献指南
    • 本次更新类型为:BUG修复
    • 本次更新类型为:功能新增
    • 本次更新是否经过测试
    • 如果本次修改涉及 src/A_memorix,我确认已阅读 src/A_memorix/MODIFICATION_POLICY.md,不涉及则无需勾选
  1. 请填写破坏性更新的具体内容(如有):迁移记忆系统配置文件生成逻辑以及读取逻辑到原生的bot_config.toml,除此之外修改了前端部分源码以保证功能对齐
  2. 请简要说明本次更新的内容和目的:

其他信息

  • 关联 Issue:Close #
  • 截图/GIF
  • 附加信息:

Summary by CodeRabbit

  • New Features

    • 引入长期记忆子系统的配置管理,包括存储、嵌入、检索、阈值、过滤、剧集和人物画像等设置。
    • 配置系统版本升级至 8.9.21,支持动态配置重载功能。
  • Bug Fixes & Improvements

    • 优化配置文件路径处理和配置加载机制。

Copilot AI review requested due to automatic review settings May 3, 2026 12:19
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 3, 2026

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

该PR将A_Memorix的配置管理从直接读取TOML文件改为通过全局配置管理器,涉及新增配置数据模型、主机服务重构、运行时优化和相关测试更新,以支持统一的配置生命周期管理和动态重载机制。

Changes

A_Memorix 配置系统全局管理集成

Layer / File(s) Summary
配置数据模型
src/config/official_configs.py
定义 AMemorixConfig 及其子配置类族(插件、存储、embedding、检索、阈值、过滤、episode、人物画像、记忆演化、Web导入/调优等),共12个子配置类通过 default_factory 聚合,提供UI标签与图标。
全局配置升级
src/config/config.py
CONFIG_VERSION 升级至 8.9.21,扩展 Config 模型新增 a_memorix 字段;新增 A_MEMORIX_LEGACY_CONFIG_PATH 常量;实现 _normalize_a_memorix_legacy_config()_migrate_legacy_a_memorix_config() 处理遗留配置迁移和归一化,集成至 load_config_from_file() 流程。
主机服务重构
src/A_memorix/host_service.py
重新实现 _read_config() 从全局配置管理器读取,通过 _config_model_to_runtime_dict() 转换为运行时字典;改造 get_raw_config_with_meta() 动态构建 tomlkit 文档;新增 _write_config_to_bot_config() 统一配置写入并支持回调触发;添加 register_config_reload_callback()on_config_reload() 实现配置重载钩子;get_config_path() 改由 _get_bot_config_path() 供给。
运行时优化
src/A_memorix/core/runtime/__init__.py
新增 __getattr__() 实现 KernelSearchRequestSDKMemoryKernel 的惰性导入,减少模块初始化耦合。
初始化整合
src/main.py
在文件监视器启动后调用 a_memorix_host_service.register_config_reload_callback() 注册配置重载回调。
WebUI支持
src/webui/routers/config.py
导入 AMemorixConfig 并在 /config/schema/section 路由的 section_map 中注册 "a_memorix" 键映射,支持新配置段的schema生成。
测试适配
pytests/A_memorix_test/test_feedback_correction_chat_flow.py, pytests/test_maisaka_builtin_query_memory.py, pytests/webui/test_memory_routes.py, pytests/webui/test_memory_routes_integration.py
反馈纠正测试新增 monkeypatch 参数和后修正mocks;内存查询测试调整配置命名空间;WebUI路由测试统一使用 bot_config.toml 路径;集成测试引入 _FakeEmbeddingManager 内存嵌入,移除磁盘TOML文件生成流程。

Sequence Diagram

sequenceDiagram
    participant Old as 旧流程
    participant New as 新流程
    participant HostService as 主机服务
    participant ConfigMgr as 全局配置管理器
    participant File as 文件系统
    participant Callback as 回调机制

    rect rgb(200, 150, 100, 0.5)
    Note over Old,New: 旧配置读取方式
    Old->>HostService: get_raw_config()
    HostService->>File: 直接读取 a_memorix.toml
    File-->>HostService: TOML内容
    HostService-->>Old: 原始TOML字符串
    end

    rect rgb(100, 150, 200, 0.5)
    Note over New,Callback: 新配置读取方式
    New->>HostService: get_raw_config_with_meta()
    HostService->>ConfigMgr: get_global_config().a_memorix
    ConfigMgr->>ConfigMgr: 从全局状态读取
    ConfigMgr-->>HostService: AMemorixConfig 模型
    HostService->>HostService: 转换为运行时dict→tomlkit文档
    HostService-->>New: TOML字符串 + exists/using_default元数据
    end

    rect rgb(150, 200, 100, 0.5)
    Note over New,Callback: 配置更新与重载
    New->>HostService: update_config(新值)
    HostService->>HostService: _write_config_to_bot_config()
    HostService->>File: 写入 bot_config.toml
    File-->>HostService: 成功
    HostService->>ConfigMgr: 重新加载bot作用域配置
    ConfigMgr-->>HostService: 更新完成
    HostService->>Callback: 触发 on_config_reload('bot')
    Callback-->>HostService: 重载确认
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.84% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed 标题明确反映了PR的主要目标——禁用A_memorix(长期记忆系统)并默认关闭,这与配置迁移到bot_config.toml的核心变更相符。
Description check ✅ Passed 提交者完整填写了检查清单,标记了分支检查、贡献指南确认、更新类型(BUG修复)、测试状态和MODIFICATION_POLICY确认,且说明了破坏性更新内容和目的。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@SengokuCola SengokuCola merged commit ce224e0 into Mai-with-u:dev May 3, 2026
4 of 6 checks passed
@github-project-automation github-project-automation Bot moved this to 已完成 in MaiM to the GATE May 3, 2026
Copy link
Copy Markdown

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

This PR migrates A_Memorix (长期记忆) configuration into the main bot_config.toml, makes the subsystem disabled by default via config, and wires A_Memorix runtime to follow config hot-reloads (plus corresponding WebUI + test updates).

Changes:

  • Add AMemorixConfig to the official config model and Config, including legacy config/a_memorix.toml migration into bot_config.toml.
  • Update A_Memorix host service to read/write config from bot_config.toml and reload on config hot-reload events.
  • Adjust WebUI config schema routing and update/extend tests to reflect the new config location and runtime behavior.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/webui/routers/config.py Exposes a_memorix as a configurable section in the generic config schema endpoint.
src/main.py Registers A_Memorix config hot-reload callback during initialization.
src/config/official_configs.py Introduces AMemorixConfig and all nested config classes; defaults to disabled.
src/config/config.py Adds a_memorix into global config, bumps config version, and migrates legacy a_memorix.toml.
src/A_memorix/host_service.py Switches A_Memorix to use bot_config.toml, supports writing into [a_memorix], and reacts to hot reload.
src/A_memorix/core/runtime/init.py Avoids eager imports via lazy __getattr__ for kernel types.
pytests/webui/test_memory_routes_integration.py Updates integration setup to mock config via host service + patches embedding adapter.
pytests/webui/test_memory_routes.py Updates expected config path responses to bot_config.toml.
pytests/test_maisaka_builtin_query_memory.py Fixes test config patching to align with global_config.memory.*.
pytests/A_memorix_test/test_feedback_correction_chat_flow.py Updates monkeypatch signatures and disables visual planner in test flow.

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

Comment on lines +335 to +339
current = doc.get("a_memorix")
if isinstance(current, dict):
_update_toml_doc(current, bot_config_payload)
else:
doc["a_memorix"] = bot_config_payload
Comment on lines +324 to +346
async def _write_config_to_bot_config(self, config: Dict[str, Any]) -> tuple[Path, Optional[Path]]:
path = self.get_config_path()
path.parent.mkdir(parents=True, exist_ok=True)
backup_path = _backup_config_file(path)
if path.exists():
with path.open("r", encoding="utf-8") as handle:
doc = tomlkit.load(handle)
else:
doc = tomlkit.document()

bot_config_payload = self._runtime_dict_to_bot_config_dict(config)
current = doc.get("a_memorix")
if isinstance(current, dict):
_update_toml_doc(current, bot_config_payload)
else:
doc["a_memorix"] = bot_config_payload

with path.open("w", encoding="utf-8") as handle:
tomlkit.dump(doc, handle)

await _get_config_manager().reload_config(changed_scopes=("bot",))
if not self._reload_callback_registered:
await self.reload()
"telemetry": TelemetryConfig,
"maim_message": MaimMessageConfig,
"memory": MemoryConfig,
"a_memorix": AMemorixConfig,
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.

3 participants