Fix #1269: fix: summarizer 模型没有进行“总结”,而是进行“对话”。换了许多个模型仍然一样#1968
Open
Memtensor-AI wants to merge 1 commit into
Open
Fix #1269: fix: summarizer 模型没有进行“总结”,而是进行“对话”。换了许多个模型仍然一样#1968Memtensor-AI wants to merge 1 commit into
Memtensor-AI wants to merge 1 commit into
Conversation
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
5 tasks
Collaborator
Author
❌ Automated Test Results: FAILED
Failed tests:
Error detailsBranch: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 singleuserrole message. Weak instruction-following LLMs (qwen2.5:1.5b, phi4-mini, GLM 4.7, etc.) then continued the trailinguser: ...lines as if they were the live conversation, replying to the user's last message rather than emitting the structured JSON whosesummaryfield becomesTreeNodeTextualMemoryMetadata.backgroundand the UI summary.This change adds
build_chat_extraction_messagesinsrc/memos/mem_reader/utils.pythat splits the rendered prompt at theConversation:/对话:marker, placing instructions, examples, and the JSON schema in asystemmessage and the conversation block (plus a strict "Return ONLY the single JSON object... do not reply to or continue the conversation" trailer) in theusermessage. 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 singleusermessage so non-chat callers are unaffected.Verification:
pytest tests/mem_reader/test_simple_structure.py -q7 passed (TDD: red on the import error before the helper existed, green after); broadertests/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 checkandruff format --checkclean on all five touched files.Related Issue (Required): Fixes #1269
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Automated tests are pending.
Checklist
@MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller please review this PR.
Reviewer Checklist