Repository navigation
fix(memory): keep turns outside a truncated session in InMemoryMemoryService - #8387
Open
chaitanya0305 wants to merge 3 commits into
Open
chaitanya0305 wants to merge 3 commits into
chaitanya0305 wants to merge 3 commits into
Conversation
…Service add_session_to_memory replaced everything stored for the session with the events of the session it was given. A session loaded with GetSessionConfig(num_recent_events=...) only holds its latest events, so each call dropped the memories of every older turn, for example when an after_agent_callback calls ctx.add_session_to_memory() under a RunConfig that sets get_session_config. Stored events that are not in session.events at all are now kept, as in SqliteMemoryService. Events that are in it are still replaced, so turns a rewind took back are still removed.
…lite Runs the windowed add_session_to_memory cases on both InMemoryMemoryService and SqliteMemoryService: a later turn added from a truncated session, a session loaded with num_recent_events=0, repeated full adds, and a rewind inside the window. Also checks that a memory removed with delete_memory stays removed when a truncated session is added again.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
…ne session Events added with add_events_to_memory and later windowed add_session_to_memory calls share the same per-session entry. The test checks, on InMemory and Sqlite, that a windowed add keeps the directly added event and older turns, and that adding the same events again through either method stores each of them once.
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
InMemoryMemoryService.add_session_to_memoryreplaced everything stored for a session with the events of theSessionit was given. A session loaded withGetSessionConfig(num_recent_events=N)only holds its latest events, so each call dropped the memories of every older turn, andnum_recent_events=0dropped all of them. This happens with aRunConfigthat setsget_session_configplus anafter_agent_callbackthat callsctx.add_session_to_memory().SqliteMemoryServicekeeps those entries (#7571).Solution:
Stored events whose ids are not in
session.eventsat all are kept. Events that are insession.eventsare replaced from_apply_rewinds(session.events)as before, so turns a rewind took back are still removed and repeated adds do not duplicate. This matchesSqliteMemoryService. Memories removed withdelete_memorystay removed, becausedelete_memorydrops them from the stored list and records their ids, and re-adds skip those ids.Testing Plan
Unit Tests:
New tests in
tests/unittests/memory/test_in_memory_memory_service.py. The windowed cases run on bothInMemoryMemoryServiceandSqliteMemoryServicethrough one fixture, so the two services are checked against each other:num_recent_events=0removes nothing,SqliteMemoryServicehas nodelete_memory) a deleted memory stays deleted when a truncated session is added again, with the deleted event inside and outside the window.Without the change in
in_memory_memory_service.py, 4 of the new tests fail (the[in_memory]windowed,num_recent_events=0and rewind cases, and the delete case); their[sqlite]variants pass both ways.Manual End-to-End (E2E) Tests:
The reproduction script from #8353 (two turns, then
add_session_to_memorywith a session loaded withnum_recent_events=2):Checklist
Additional context
#8141 changes
add_events_to_memoryin the same file; this PR only changesadd_session_to_memory, so the code changes do not overlap. Both PRs append tests at the end oftest_in_memory_memory_service.py, so whichever lands second may need a trivial rebase there.