adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

No way to delete memories from a MemoryService

Open Chenjigaram opened this issue 3 months ago • 6 comments

Is your feature request related to a specific problem?

BaseSessionService has delete_session and BaseArtifactService has delete_artifact, but BaseMemoryService only has add_session_to_memory, add_events_to_memory, add_memory and search_memory. Once something is written to memory there is no way to remove it through ADK.

This comes up when a user asks for their data to be deleted. Sessions and artifacts I can handle. Whatever was extracted into long-term memory I cannot, so I end up going around ADK and deleting straight from the backing store.

Most of the pieces are already there. MemoryEntry has an id field, and the Vertex API has projects.locations.reasoningEngines.memories.delete. VertexAiMemoryBankService just doesn't wrap it. It only uses memories.create, memories.generate and memories.ingest_events.

Describe the Solution You'd Like

Two methods on BaseMemoryService:

async def delete_memory(self, *, app_name: str, user_id: str, memory_id: str) -> None
async def delete_memories(self, *, app_name: str, user_id: str) -> None

First one deletes a single entry, second one everything stored for a user.

For VertexAiMemoryBankService both map onto memories.delete. InMemoryMemoryService keeps a dict so it's easy. Implementations that can't support it could raise NotImplementedError.

Impact on your work

I'm building agents for users in the EU, where a deletion request has to be answered within a month. Right now the memory part of that is a manual step outside ADK, and it's the part I can't show was actually done.

Willingness to contribute

Yes, happy to open a PR if you're OK with the method names and signatures.

Describe Alternatives You've Considered

Deleting from the backing store directly. It works but it's different for every implementation and bypasses ADK completely. The other option is not using MemoryService at all.

Version

google-adk 2.8.0

Chenjigaram avatar Aug 30 '26 04:08 Chenjigaram

I'd like to work on this.

Plan: add delete_memory (and a matching search-by-id if needed) on BaseMemoryService, implement it for the in-memory/sqlite services and wrap Vertex memories.delete on VertexAiMemoryBankService. Tests for delete-missing, delete-then-search, and the Vertex client call.

Please confirm the method signatures before I open a PR, per CONTRIBUTING.

SabreKeyZ avatar Aug 31 '26 04:08 SabreKeyZ

Hi @Chenjigaram , Thank you for your feature request. It is currently under review, and we will let you know if we need any further information. We appreciate your understanding.

sanketpatil06 avatar Aug 31 '26 06:08 sanketpatil06

There's a complete implementation in #6961 (CLA signed, checks green) if it's useful while this is under review. Happy to adjust the API to whatever the team prefers.

SabreKeyZ avatar Aug 31 '26 07:08 SabreKeyZ

Is your feature request related to a specific problem?

BaseSessionService has delete_session and BaseArtifactService has delete_artifact, but BaseMemoryService only has add_session_to_memory, add_events_to_memory, add_memory and search_memory. Once something is written to memory there is no way to remove it through ADK.

This comes up when a user asks for their data to be deleted. Sessions and artifacts I can handle. Whatever was extracted into long-term memory I cannot, so I end up going around ADK and deleting straight from the backing store.

Most of the pieces are already there. MemoryEntry has an id field, and the Vertex API has projects.locations.reasoningEngines.memories.delete. VertexAiMemoryBankService just doesn't wrap it. It only uses memories.create, memories.generate and memories.ingest_events.

Describe the Solution You'd Like

Two methods on BaseMemoryService:

async def delete_memory(self, *, app_name: str, user_id: str, memory_id: str) -> None async def delete_memories(self, *, app_name: str, user_id: str) -> None First one deletes a single entry, second one everything stored for a user.

For VertexAiMemoryBankService both map onto memories.delete. InMemoryMemoryService keeps a dict so it's easy. Implementations that can't support it could raise NotImplementedError.

Impact on your work

I'm building agents for users in the EU, where a deletion request has to be answered within a month. Right now the memory part of that is a manual step outside ADK, and it's the part I can't show was actually done.

Willingness to contribute

Yes, happy to open a PR if you're OK with the method names and signatures.

Describe Alternatives You've Considered

Deleting from the backing store directly. It works but it's different for every implementation and bypasses ADK completely. The other option is not using MemoryService at all.

Version

google-adk 2.8.0

+1. If extracted memory can't be removed through the same API, you end up with a second, unofficial delete path that's hard to audit. Until delete_memory exists, recording session_id in MemoryEntry ids at write time at least makes backing-store cleanup provable. (I work on Breeth, a memory API with retraction and hard delete built in, in case you need it before ADK ships this.)

uvsohith2004 avatar Oct 03 '26 09:10 uvsohith2004

Cross-referencing #7109 (closed as a duplicate of this issue), which includes a detailed design discussion on MemoryEntry.id round-tripping across memory backends (InMemoryMemoryService, FirestoreMemoryService, VertexAiMemoryBankService, and VertexAiRagMemoryService) as well as open PR #7175 alongside PR #6961.

DeanChensj avatar Oct 07 '26 23:10 DeanChensj

Independent recheck on 2026-10-15 (pinned versions; not a claim about the latest release):

  • Environment: Python 3.11+, google-adk==2.8.0 and 2.9.0, InMemorySessionService + InMemoryMemoryService; no external model/Vertex API calls.
  • Steps: create a session with a unique marker → add_session_to_memory() → search_memory() finds the marker → delete_session() → check session and memory again.
  • Both versions: session_exists_after_delete=false, memory_found_before_delete=true, memory_found_after_delete=true, and the callable BaseMemoryService delete-method list is empty. The existing assertion-based version matrix passed again today.
  • Scope: confirms the separation of session and copied memory in the tested in-memory implementations. This does not establish behavior in newer versions or every hosted backend.

For the proposed #6961 / #7175 implementations, useful regression cases would be delete-then-search, missing IDs, user namespace isolation, and MemoryEntry.id round-tripping across supported backends.

Independent repro + version matrix: https://github.com/xbstack/google-adk-memory-delete-session-repro

Test evidence and data-deletion boundary: https://www.xbstack.com/en/ai/google-adk-delete-session-memory-retained/?utm_source=github&utm_medium=referral&utm_campaign=google_adk_memory_delete&utm_content=issue_comment

Small source-reference correction: the related memory report is #7109 (closed duplicate of this issue); #7110 concerns duplicate agent names and is unrelated.

1320800521 avatar Oct 15 '26 08:10 1320800521