InMemoryMemoryService.add_session_to_memory deletes older turns when the session is loaded with num_recent_events
メンテナーはふだん 3 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- python
調査の方向性
Start in src/google/adk/memory/in_memory_memory_service.py, where add_session_to_memory replaces the session's bucket with _apply_rewinds(session.events) and so drops stored events absent from the truncated session. Run the reproduction, which shows InMemory returning no 'Paris' hits while SqliteMemoryService keeps them, and compare against _sqlite_memory_service.py. Done when the in-memory service keeps events whose ids are missing from session.events, rewinds still remove turns, repeated adds don't duplicate, and a regression test in tests/unittests/memory/test_in_memory_memory_service.py passes.
索引モデルが issue の本文から書いたものです。
説明
Summary
InMemoryMemoryService.add_session_to_memory replaces everything stored for a session with the events of the Session it is given. A session loaded with GetSessionConfig(num_recent_events=N) holds only its latest events, so each call silently deletes the memories of every older turn in that session. With num_recent_events=0 it deletes all of them.
This hits the setup the docstrings show: a RunConfig with get_session_config=GetSessionConfig(num_recent_events=...) plus an after_agent_callback that calls ctx.add_session_to_memory(). After a few turns, search_memory / preload_memory no longer find facts the user gave earlier.
SqliteMemoryService and FirestoreMemoryService keep those entries. #7571 (commit 2591397b) made that the intended behaviour ("Entries for events that are not in session.events at all, such as turns outside a session loaded with num_recent_events, are kept"), but the in-memory service was not changed.
Reproduction
Run on current main (3e322e9a):
import asyncio, os, tempfile
from google.adk.events.event import Event
from google.adk.memory.in_memory_memory_service import InMemoryMemoryService
from google.adk.memory._sqlite_memory_service import SqliteMemoryService
from google.adk.sessions.in_memory_session_service import InMemorySessionService
from google.adk.sessions.base_session_service import GetSessionConfig
from google.genai import types
def ev(inv, author, text):
return Event(invocation_id=inv, author=author,
content=types.Content(role='user' if author == 'user' else 'model',
parts=[types.Part(text=text)]))
async def run(mem, label):
ss = InMemorySessionService()
s = await ss.create_session(app_name='app', user_id='u')
await ss.append_event(s, ev('i1', 'user', 'My favourite city is Paris'))
await ss.append_event(s, ev('i1', 'agent', 'Noted Paris'))
await mem.add_session_to_memory(
await ss.get_session(app_name='app', user_id='u', session_id=s.id))
await ss.append_event(s, ev('i2', 'user', 'I also like London'))
await ss.append_event(s, ev('i2', 'agent', 'Noted London'))
recent = await ss.get_session(app_name='app', user_id='u', session_id=s.id,
config=GetSessionConfig(num_recent_events=2))
await mem.add_session_to_memory(recent)
r = await mem.search_memory(app_name='app', user_id='u', query='Paris')
print(label, "search 'Paris':", [m.content.parts[0].text for m in r.memories])
async def main():
await run(InMemoryMemoryService(), 'InMemory')
await run(SqliteMemoryService(db_path=os.path.join(tempfile.mkdtemp(), 'm.db')), 'Sqlite')
asyncio.run(main())
Actual
InMemory search 'Paris': []
Sqlite search 'Paris': ['Noted Paris', 'My favourite city is Paris']
Expected
InMemory search 'Paris': ['My favourite city is Paris', 'Noted Paris']
That is, the same result as SqliteMemoryService: the turn-1 memories survive.
Cause
In src/google/adk/memory/in_memory_memory_service.py, add_session_to_memory sets the session's bucket to _apply_rewinds(session.events). Stored events that are not in session.events (turns outside the truncated window) are dropped.
Proposed fix
Keep stored events for the session whose ids are not in session.events at all, and replace the rest from _apply_rewinds(session.events) as now. Turns removed by a rewind are still removed, and repeated adds don't duplicate. This matches the Sqlite and Firestore behaviour. The change is about 10 lines, plus a regression test in tests/unittests/memory/test_in_memory_memory_service.py.
I used an AI coding assistant (Claude) to find and analyse this; I reproduced it and checked the fix myself.
I've tested a fix with a regression test: https://github.com/chaitanya0305/adk-python/compare/main...chaitanya0305:adk-python:fix/in-memory-memory-truncated-session. If this is accepted, I'll open the PR straight away.
- 主要言語
- Python
- スター
- 22.3k
- フォーク
- 4.4k
- 平均マージ
- 1日 2時間
- マージ済み PR(30日)
- 6
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
google/adk-python のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
google/adk-python#8360 ·
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
google/adk-python#8359 ·
メンテナーはふだん 3 日以内に返信
-
Can pin to litellm version be changed?対応中かも @llalitkumarrr が 10 日前に担当しました。 オープンmodels
難易度 1/5 1時間未満 初心者へのやさしさ 65/100
google/adk-python#8129 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 3 日以内に返信
-
OpenAPI tools ignore operation- and path-level server overrides対応中かも @sanketpatil06 が 14 日前に担当しました。 オープンtools
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
google/adk-python#8064 · コメント 4 件 · 担当者 1 名 ·
メンテナーはふだん 3 日以内に返信
-
Two docstrings in openapi_tool document parameters the signatures do not accept対応中かも @surajksharma07 が 17 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
google/adk-python#8024 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 3 日以内に返信
google/adk-python の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
vllm-project/vllm#70030 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
TigreGotico/tugaphone#408 ·
メンテナーはふだん 1 日以内に返信
-
needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
gke-labs/kube-agents#7308 ·
メンテナーはふだん 1 日以内に返信
-
t: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 3 日以内に返信
-
chore
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
lugassawan/swe-workbench#841 ·