fix(A_memorix):调整episode重建逻辑#1709
Conversation
Walkthrough此 PR 重构了摘要导入的返回值结构和 episode 增量处理流程:新增 Changes摘要导入结果重构与 Episode 增量处理
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 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.
Pull request overview
该 PR 调整了 A_memorix 的聊天摘要导入返回结构,并在运行时侧将 episode 重建从“按 source 全量重建”改为“按新段落 hash 增量入队”,以减少不必要的 token 消耗并为后续增量处理提供更精确的输入。
Changes:
SummaryImporter.import_from_stream()返回值从(success, detail)二元组升级为SummaryImportResult,并在成功时返回新增摘要段落的paragraph_hash与source。_execute_import()改为返回段落 hash,供上层做 episode 增量入队。sdk_memory_kernel.summarize_chat_stream()改为将paragraph_hash入队到 episode pending 队列,并在返回 payload 中附带相关 id 列表。
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/A_memorix/core/utils/summary_importer.py | 引入 SummaryImportResult,并让导入流程返回新增段落 hash 以支撑增量 episode 处理。 |
| src/A_memorix/core/runtime/sdk_memory_kernel.py | 使用新的导入结果结构,将摘要段落增量入队 episode pending,并扩展返回 payload。 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def __iter__(self) -> Iterator[bool | str]: | ||
| yield self.success | ||
| yield self.detail | ||
|
|
| success = bool(getattr(import_result, "success", False)) | ||
| detail = str(getattr(import_result, "detail", "") or "") | ||
| paragraph_hash = str(getattr(import_result, "paragraph_hash", "") or "").strip() | ||
| source = ( | ||
| str(getattr(import_result, "source", "") or "").strip() |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/A_memorix/core/runtime/sdk_memory_kernel.py (1)
1192-1198: ⚡ Quick win直接访问已确认存在的 dataclass 属性,避免不必要的
getattr()。
SummaryImportResult是一个 frozen dataclass,其字段success、detail、paragraph_hash、source都已显式声明。在确认属性存在的情况下使用getattr()违反了代码规范(应最小化getattr/setattr的使用)。改用直接属性访问:♻️ 建议修改
- success = bool(getattr(import_result, "success", False)) - detail = str(getattr(import_result, "detail", "") or "") - paragraph_hash = str(getattr(import_result, "paragraph_hash", "") or "").strip() - source = ( - str(getattr(import_result, "source", "") or "").strip() - or self._build_source("chat_summary", chat_id, []) - ) + success = bool(import_result.success) + detail = str(import_result.detail or "") + paragraph_hash = str(import_result.paragraph_hash or "").strip() + source = str(import_result.source or "").strip() or self._build_source("chat_summary", chat_id, [])🤖 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/A_memorix/core/runtime/sdk_memory_kernel.py` around lines 1192 - 1198, The code uses getattr() to read fields from the frozen dataclass SummaryImportResult (via import_result) even though its attributes success, detail, paragraph_hash and source are defined; replace the getattr calls with direct attribute access (e.g., import_result.success, import_result.detail, import_result.paragraph_hash, import_result.source) and preserve the existing fallback/normalization logic (bool(...) for success, str(...).strip() for paragraph_hash and source, and fallback to self._build_source("chat_summary", chat_id, []) when import_result.source is empty).
🤖 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/A_memorix/core/runtime/sdk_memory_kernel.py`:
- Around line 1192-1198: The code uses getattr() to read fields from the frozen
dataclass SummaryImportResult (via import_result) even though its attributes
success, detail, paragraph_hash and source are defined; replace the getattr
calls with direct attribute access (e.g., import_result.success,
import_result.detail, import_result.paragraph_hash, import_result.source) and
preserve the existing fallback/normalization logic (bool(...) for success,
str(...).strip() for paragraph_hash and source, and fallback to
self._build_source("chat_summary", chat_id, []) when import_result.source is
empty).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: d9a84c41-5af1-4a2c-ab4e-4532887d14de
📒 Files selected for processing (2)
src/A_memorix/core/runtime/sdk_memory_kernel.pysrc/A_memorix/core/utils/summary_importer.py
zh-CN目标翻译作为常规 GitHub 编辑面;常规翻译以 Crowdin ->l10n_*PR 回流为准,详见docs/i18n.md请填写以下内容
(删除掉中括号内的空格,并替换为小写的x)
main分支 禁止修改,请确认本次提交的分支 不是main分支src/A_memorix,我确认已阅读src/A_memorix/MODIFICATION_POLICY.md,不涉及则无需勾选其他信息
Summary by CodeRabbit
发布说明