Skip to content

Fix #1269: fix: summarizer 模型没有进行“总结”,而是进行“对话”。换了许多个模型仍然一样#1968

Open
Memtensor-AI wants to merge 1 commit into
dev-20260624-v2.0.22from
bugfix/autodev-1269
Open

Fix #1269: fix: summarizer 模型没有进行“总结”,而是进行“对话”。换了许多个模型仍然一样#1968
Memtensor-AI wants to merge 1 commit into
dev-20260624-v2.0.22from
bugfix/autodev-1269

Conversation

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

Description

Fixes issue #1269: the Memos UI "memory summary" was showing the LLM's chat reply instead of a summary, because the mem_reader chat-extraction prompt (instructions + examples + Conversation:\n<turns>\n\nYour Output:) was sent as a single user role message. Weak instruction-following LLMs (qwen2.5:1.5b, phi4-mini, GLM 4.7, etc.) then continued the trailing user: ... lines as if they were the live conversation, replying to the user's last message rather than emitting the structured JSON whose summary field becomes TreeNodeTextualMemoryMetadata.background and the UI summary.

This change adds build_chat_extraction_messages in src/memos/mem_reader/utils.py that splits the rendered prompt at the Conversation: / 对话: marker, placing instructions, examples, and the JSON schema in a system message and the conversation block (plus a strict "Return ONLY the single JSON object... do not reply to or continue the conversation" trailer) in the user message. The three chat call sites (SimpleStructMemReader, StrategyStructMemReader, MultiModalMemReader) are rewired to use the helper. Doc / general_string templates without the marker fall back to a single user message so non-chat callers are unaffected.

Verification: pytest tests/mem_reader/test_simple_structure.py -q 7 passed (TDD: red on the import error before the helper existed, green after); broader tests/mem_reader/ suite has 44 passed, 2 pre-existing markitdown-related failures (verified to also fail on base branch — unrelated); tests/mem_chat/ tests/mem_os/ smoke 27 passed; ruff check and ruff format --check clean on all five touched files.

Related Issue (Required): Fixes #1269

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g. code style improvements, linting)
  • Documentation update

How Has This Been Tested?

Automated tests are pending.

  • Unit Test
  • Test Script Or Test Steps (please provide)
  • Pipeline Automated API Test (please provide)

Checklist

  • I have performed a self-review of my own code
  • I have commented my code in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have created related documentation issue/PR in MemOS-Docs (if applicable)
  • I have linked the issue to this PR (if applicable)
  • I have mentioned the person who will review this PR

@MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller please review this PR.

Reviewer Checklist

The mem_reader chat path was sending the entire prompt (instructions +
examples + ``Conversation:\n<turns>\n\nYour Output:``) as a single
``user`` role message. Weak instruction-following LLMs (qwen2.5:1.5b,
phi4-mini, etc.) then continued the trailing ``user: ...`` lines as
if they were the live conversation, replying to the user's last
message instead of emitting the structured JSON. The resulting
``summary`` field (surfaced as ``TreeNodeTextualMemoryMetadata.background``
in the Memos UI memory summary) became a chat reply, not a summary.

Introduce ``build_chat_extraction_messages`` in
``src/memos/mem_reader/utils.py`` that splits the rendered prompt at
the ``Conversation:`` / ``对话:`` marker, placing instructions /
examples / format spec in a ``system`` message and the conversation
block (plus a strict ``Return ONLY the single JSON object... do not
reply to or continue the conversation`` trailer) in the ``user``
message. Doc / general_string templates without the marker fall back
to a single ``user`` message so non-chat callers are unaffected.

Rewire the three chat call sites (``SimpleStructMemReader``,
``StrategyStructMemReader``, ``MultiModalMemReader``) to use the new
helper and add regression tests covering both the system+user shape
and the fallback case.

Refs: #1269
@Memtensor-AI

Copy link
Copy Markdown
Collaborator Author

❌ Automated Test Results: FAILED

Auto-fix retry 1/2 triggered.

Failed tests:

  • test_out_of_range_rejected_or_clamped_to_valid[negative_1]
  • test_out_of_range_rejected_or_clamped_to_valid[negative_60s]
  • test_out_of_range_rejected_or_clamped_to_valid[negative_one_day]
  • test_out_of_range_rejected_or_clamped_to_valid[max_plus_1]
  • test_out_of_range_rejected_or_clamped_to_valid[max_plus_one_day]
  • test_out_of_range_rejected_or_clamped_to_valid[hundred_x_max]
  • test_invalid_type_does_not_crash_or_corrupt[string_number]
  • test_invalid_type_does_not_crash_or_corrupt[string_text]
  • test_invalid_type_does_not_crash_or_corrupt[none_value]
  • test_invalid_type_does_not_crash_or_corrupt[dict_value]
Error details
Tests failed. Failed cases: test_out_of_range_rejected_or_clamped_to_valid[negative_1], test_out_of_range_rejected_or_clamped_to_valid[negative_60s], test_out_of_range_rejected_or_clamped_to_valid[negative_one_day], test_out_of_range_rejected_or_clamped_to_valid[max_plus_1], test_out_of_range_rejected_or_clamped_to_valid[max_plus_one_day]

Branch: bugfix/autodev-1269

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated bug Something isn't working | 功能异常

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants