Repository navigation
fix(memory): keep thought parts out of Memory Bank events - #7851
Closed
hyeonsang010716 wants to merge 2 commits into
Closed
hyeonsang010716 wants to merge 2 commits into
hyeonsang010716 wants to merge 2 commits into
Conversation
VertexAiMemoryBankService passed event.content to ingest_events and memories.generate unchanged, so the model's thought parts were treated as conversation and could be extracted into memories. Events whose only text was a thought were sent as well. Drop thought parts from the content of each event, and skip events that have nothing left, as the other memory services already do. Fixes google#7850
Build the thought events per test so one test cannot change them for another, check the events are unchanged on the generate path as well, and cover a thought-only event on the ingest path.
Collaborator
|
Thank you @hyeonsang010716 for your contribution! 🎉 Your changes have been successfully imported and merged via Copybara in commit 4fae7b7. Closing this PR as the changes are now in the main branch. |
7 of 9 tasks
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.
Link to Issue or Description of Change
Problem:
VertexAiMemoryBankServicepassesevent.contenttoingest_eventsandmemories.generateunchanged, so the model's thought parts(
Part.thought=True) reach Memory Bank as conversation content. Memories canthen be extracted from the model's private reasoning. An event whose only text
is a thought is sent too, because
_is_empty_contentcounts anypart.text.InMemoryMemoryService,VertexAiRagMemoryService(#7473) andSqliteMemoryService(#7691) already exclude thoughts.Solution:
Add
_without_thoughts, which returns a copy of the content without thoughtparts, and use it in both direct-contents paths.
_should_filter_out_eventchecks the filtered content, so an event with nothing left is skipped. The
session's own events are not modified, and content without thoughts is passed
through as before.
add_memoryis unchanged: it takesMemoryEntrycontent from the callerrather than session events.
Testing Plan
Unit Tests:
Added to
test_vertex_ai_memory_bank_service.py, covering both paths:add_session_to_memory): thought parts are dropped, athought-only event is skipped, and the session's events are unchanged.
add_events_to_memory): a thought-only event alone sends noevents.
unchanged.
All 4 new tests fail without the source change and pass with it. Changing the
event content in place instead of copying it fails the "unchanged" checks on
both paths.
pre-commit runpasses on the changed files, and mypy reports no issues invertex_ai_memory_bank_service.py.Manual End-to-End (E2E) Tests:
I don't have a Memory Bank instance, so I ran the reproduction script from
#7850 against the mocked
agentplatform.Client. Onmainboth events are sentwith their thought parts; with this change only
Here is the answer.is sent.Checklist