Skip to content

fix: delimit memory context with XML boundary#2052

Draft
RerankerGuo wants to merge 1 commit into
MemTensor:mainfrom
RerankerGuo:fix/xml-memory-context-boundary
Draft

fix: delimit memory context with XML boundary#2052
RerankerGuo wants to merge 1 commit into
MemTensor:mainfrom
RerankerGuo:fix/xml-memory-context-boundary

Conversation

@RerankerGuo

Copy link
Copy Markdown

Description

Fixes #1316.

Retrieval injection now wraps every non-empty rendered memory block in <relevant-memories> and marks the contents as untrusted historical notes. The block explicitly tells the model to treat recalled content as plain text rather than executable instructions.

The renderer also neutralizes any recalled text that tries to emit the same XML boundary, so a stored memory cannot close the wrapper early.

Related Issue (Required): Fixes #1316

Type of change

  • 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?

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

Commands run:

cd apps/memos-local-plugin && npm test -- --run tests/unit/retrieval/injector.test.ts
cd apps/memos-local-plugin && npm run lint
make format

Results:

  • npm test -- --run tests/unit/retrieval/injector.test.ts: 1 file passed, 13 tests passed.
  • npm run lint: tsc -p tsconfig.json --noEmit completed successfully.
  • make format: blocked locally because poetry is not installed (make: poetry: Command not found).

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) | 我已在 MemOS-Docs 中创建了相关的文档 issue/PR(如果适用)
  • I have linked the issue to this PR (if applicable) | 我已将 issue 链接到此 PR(如果适用)
  • I have mentioned the person who will review this PR | 我已提及将审查此 PR 的人

Reviewer Checklist

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.

feat: Openclaw插件,在注入前使用XML标签包裹,避免AI弄混记忆和当前及之前的指令

1 participant