Skip to content

fix(hook): resolve message extraction conflict between memory and RAG…#1435

Open
hexly666 wants to merge 3 commits into
agentscope-ai:mainfrom
hexly666:fix/hook-message-extraction-conflict-issue-1403
Open

fix(hook): resolve message extraction conflict between memory and RAG…#1435
hexly666 wants to merge 3 commits into
agentscope-ai:mainfrom
hexly666:fix/hook-message-extraction-conflict-issue-1403

Conversation

@hexly666
Copy link
Copy Markdown

… hooks

When both StaticLongTermMemoryHook and GenericRAGHook are attached to the same agent, they interfered with each other's message extraction logic. Each hook searches for "the last user message" to use as its query, but since both hooks inject their results as USER role messages at the end of the message list, one hook could pick up the other hook's injected message instead of the original user input.

Changes:

  • GenericRAGHook: Change injected message name from "user" to "retrieved_knowledge" for clear identification; skip messages with name "long_term_memory" when extracting user query
  • StaticLongTermMemoryHook: Skip messages with name "retrieved_knowledge" when extracting user query
  • Add tests to verify hook interference is resolved

Closes #1403

AgentScope-Java Version

[The version of AgentScope-Java you are working on, e.g. 1.0.12, check your pom.xml dependency version or run mvn dependency:tree | grep agentscope-parent:pom(only mac/linux)]

Description

[Please describe the background, purpose, changes made, and how to test this PR]

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

… hooks

When both StaticLongTermMemoryHook and GenericRAGHook are attached to
the same agent, they interfered with each other's message extraction
logic. Each hook searches for "the last user message" to use as its
query, but since both hooks inject their results as USER role messages
at the end of the message list, one hook could pick up the other hook's
injected message instead of the original user input.

Changes:
- GenericRAGHook: Change injected message name from "user" to
  "retrieved_knowledge" for clear identification; skip messages with
  name "long_term_memory" when extracting user query
- StaticLongTermMemoryHook: Skip messages with name "retrieved_knowledge"
  when extracting user query
- Add tests to verify hook interference is resolved

Closes agentscope-ai#1403
@hexly666 hexly666 requested a review from a team May 18, 2026 18:12
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


helm30 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

helm30 added 2 commits May 19, 2026 10:03
… logic

Use scoreThreshold=0.0 to guarantee RAG retrieval triggers in the
hook-interference test, ensuring the name-based skip branch is
actually executed. Add edge-case test for when all USER messages
are hook-injected (no genuine user query available).
…ogic

Add unit tests in agentscope-core using a mocked Knowledge interface to
cover the long_term_memory skip branch in GenericRAGHook#extractQueryFromMessages.
This addresses the 6 missing lines reported by Codecov (Patch 0.00%) since
agentscope-core coverage does not include tests from agentscope-extensions modules.
Copy link
Copy Markdown
Author

@hexly666 hexly666 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

[Bug]: Hook message extraction conflict when using long-term memory and RAG together

2 participants