feat:将A_memorix画像功能接入maisaka检索工具以及自动注入#1666
Conversation
Describe: - 新增 Maisaka 内置 query_person_profile 工具,支持按 person_id 或 person_name 查询 A_memorix 人物画像,并返回结构化摘要。 - 在 a_memorix.integration 配置中增加画像查询、自动注入和注入数量上限开关,同时提升 CONFIG_VERSION。 - Planner 调用前自动收集当前会话相关人物画像,并与 deferred tools 提示一起作为内部参考注入。 - 补充 query_memory 配置路径修正、画像工具、配置字段和自动注入流程测试。
演练此 PR 实现了人物画像查询和自动注入功能,包括新的 变更人物画像查询和注入功能
预计代码审查工作量🎯 3 (中等) | ⏱️ ~25 分钟 可能相关的 PR
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f5663ac6b6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| def _is_bot_user_id(user_id: str) -> bool: | ||
| bot_user_id = _clean_text(getattr(global_config.bot, "qq_account", "")) | ||
| return bool(user_id and bot_user_id and user_id == bot_user_id) |
There was a problem hiding this comment.
Use platform-aware bot identity filtering
当前机器人过滤只比较 global_config.bot.qq_account,会把非 QQ 平台(如 Telegram)中的机器人账号当作普通用户候选,从而把机器人画像注入到 Planner,并挤占 max_profiles 名额,导致真实用户画像被跳过。仓库里已有跨平台判定逻辑(src/chat/utils/utils.py 的 is_bot_self/get_bot_account),这里应按 platform + user_id 过滤而不是仅按 QQ 账号字符串比较。
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/maisaka/person_profile_injector.py (1)
44-45: ⚡ Quick win已确认类型的配置对象上,建议改为直接属性访问。
这里的
global_config/integration_config字段是确定结构,继续使用getattr(..., fallback)会弱化类型检查并增加不必要回退分支。♻️ 建议修改
def _is_bot_user_id(user_id: str) -> bool: - bot_user_id = _clean_text(getattr(global_config.bot, "qq_account", "")) + bot_user_id = _clean_text(global_config.bot.qq_account) return bool(user_id and bot_user_id and user_id == bot_user_id) @@ integration_config = global_config.a_memorix.integration - if not bool(getattr(integration_config, "enable_person_profile_injection", True)): + if not integration_config.enable_person_profile_injection: return [] @@ try: - max_profiles = int(getattr(integration_config, "person_profile_injection_max_profiles", 3) or 3) + max_profiles = int(integration_config.person_profile_injection_max_profiles) except (TypeError, ValueError): max_profiles = 3As per coding guidelines "When a variable/instance type is confirmed (prioritize type annotations unless proven incorrect), you do not need to use
orfor fallback operations. Minimize use ofgetattrandsetattrmethods; only use them for dynamic class handling or pytest Monkeypatch. When refactoring code with these methods, check if the class instance has the attribute and replace with direct property access if it does."Also applies to: 223-227
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/maisaka/person_profile_injector.py` around lines 44 - 45, Replace getattr fallback usage with direct attribute access on the known config objects: instead of _clean_text(getattr(global_config.bot, "qq_account", "")) use the confirmed property (global_config.bot.qq_account) and pass that into _clean_text, and similarly replace any getattr/inexact access in the later block (the code around lines referencing 223-227) to use integration_config.<property> or global_config.<property> directly; update any null/empty checks to operate on the cleaned value returned by _clean_text so the equality check (user_id == bot_user_id) and truthiness logic remain correct.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/maisaka/person_profile_injector.py`:
- Around line 44-45: Replace getattr fallback usage with direct attribute access
on the known config objects: instead of _clean_text(getattr(global_config.bot,
"qq_account", "")) use the confirmed property (global_config.bot.qq_account) and
pass that into _clean_text, and similarly replace any getattr/inexact access in
the later block (the code around lines referencing 223-227) to use
integration_config.<property> or global_config.<property> directly; update any
null/empty checks to operate on the cleaned value returned by _clean_text so the
equality check (user_id == bot_user_id) and truthiness logic remain correct.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: fedbd596-e29a-4552-9b8a-49ab129ff3b2
📒 Files selected for processing (10)
pytests/test_maisaka_builtin_query_memory.pypytests/test_maisaka_builtin_query_person_profile.pypytests/test_maisaka_person_profile_config.pypytests/test_maisaka_person_profile_injector.pysrc/config/config.pysrc/config/official_configs.pysrc/maisaka/builtin_tool/__init__.pysrc/maisaka/builtin_tool/query_person_profile.pysrc/maisaka/person_profile_injector.pysrc/maisaka/reasoning_engine.py
There was a problem hiding this comment.
Pull request overview
该 PR 将 A_memorix 的“人物画像(profile)”能力接入 Maisaka:一方面新增内置检索工具供 Planner 主动查询,另一方面在每轮 Planner 请求前自动注入与当前对话对象相关的画像摘要,辅助模型稳定理解人物背景。
Changes:
- 新增
query_person_profile内置工具,并接入 Maisaka 内置工具注册表。 - 新增人物画像自动注入服务,在 Planner 调用前构造一次性注入消息(含 deferred tools 提示与画像参考块)。
- 扩展 A_memorix 集成配置项(开关与注入上限),并补充相应 pytest 覆盖。
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/maisaka/reasoning_engine.py | 在 Planner 调用前增加一次性注入消息构造流程,并在打断重试时缓存最新消息批次。 |
| src/maisaka/person_profile_injector.py | 新增“人物画像自动注入”服务:候选人收集、画像查询与参考块格式化。 |
| src/maisaka/builtin_tool/query_person_profile.py | 新增 query_person_profile 内置工具实现与结构化返回。 |
| src/maisaka/builtin_tool/init.py | 注册 query_person_profile 工具,并按配置控制启用状态。 |
| src/config/official_configs.py | 为 A_memorix 集成新增画像查询开关、自动注入开关与注入上限配置。 |
| src/config/config.py | 配置版本号递增以反映新增配置字段。 |
| pytests/test_maisaka_person_profile_injector.py | 覆盖候选人收集逻辑、注入内容构造、与 reasoning_engine 注入消息拼接。 |
| pytests/test_maisaka_person_profile_config.py | 覆盖新配置字段在 WebUI schema 中的暴露与约束。 |
| pytests/test_maisaka_builtin_query_person_profile.py | 覆盖新工具的入参校验、按 person_id/person_name 查询与工具列表启用开关。 |
| pytests/test_maisaka_builtin_query_memory.py | 更新测试配置结构以匹配 a_memorix.integration.memory_query_default_limit。 |
Comments suppressed due to low confidence (1)
src/maisaka/reasoning_engine.py:700
- 这一行日志内容出现明显乱码(疑似文件编码/复制导致的 mojibake),会影响线上排障与可观测性。建议将该提示文本恢复为可读的中文/英文,并检查该文件保存编码是否为 UTF-8。
logger.info(
f"{self._runtime.log_prefix} 淇濇寔娲昏穬鐘舵€侊紝璺宠繃 Timing Gate 鐩存帴閲嶈瘯 Planner: "
f"鍥炲悎={round_index + 2}"
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| blocks: list[str] = [] | ||
| for candidate in candidates: | ||
| try: | ||
| payload = await memory_service.profile_admin( | ||
| action="query", | ||
| person_id=candidate.person_id, | ||
| limit=PROFILE_QUERY_LIMIT, | ||
| ) | ||
| except Exception as exc: |
zh-CN目标翻译作为常规 GitHub 编辑面;常规翻译以 Crowdin ->l10n_*PR 回流为准,详见docs/i18n.md请填写以下内容
(删除掉中括号内的空格,并替换为小写的x)
main分支 禁止修改,请确认本次提交的分支 不是main分支src/A_memorix,我确认已阅读src/A_memorix/MODIFICATION_POLICY.md,不涉及则无需勾选其他信息
Summary by CodeRabbit
发布说明
新功能
测试