Skip to content
Blog

Implementing a User Forget-Me Tool for GDPR/CCPA Compliance in ADK

Right to erasure in an agent app means deleting sessions, artifacts, user-scoped state, and any memory backend copies — with an audit trail. Here is the erase flow built on list_sessions, delete_session, artifact deletion, and honest limits of ADK's MemoryService.

Published on • December 3, 2026

AI Assistant

“Delete everything you know about me” is a request a chatbot can no longer politely deflect. Under GDPR Article 17 and the CCPA’s right to delete, a user can demand erasure of their personal data, and the deadline is measured in days, not sprints. The uncomfortable truth for most agent teams is that a conversational app scatters a single user’s data across at least four stores: session events, session and user state, artifacts, and whatever your memory backend retained — plus logs you forgot you were writing.

ADK does not ship a forget_user() call, and that is the honest starting point. What it does ship is a clean set of primitives — list_sessions, delete_session, artifact deletion, and scoped state keys — that compose into a defensible erasure flow. This post builds that flow as a callable tool, and is equally explicit about where ADK’s own interface stops and your storage layer has to take over.

Prerequisites

  • ADK installed (pip install google-adk) with a persistent SessionService (DatabaseSessionService or VertexAiSessionService) — erasing from InMemorySessionService proves nothing.
  • An ArtifactService configured on the Runner.
  • A decision on which stores hold personal data before you write the tool. You cannot delete what you have not inventoried.

1. Inventory first: where a user’s data actually lives

Erasure fails most often because the map was wrong. Walk every store your app touches:

StoreADK primitiveErasable by ADK?
Conversation events (messages, tool calls)session_service.delete_session(...)Yes — deletes the session and its history
Session-scoped stateDeleted with the sessionYes — as above
User-scoped state (user: keys)Explicit state_delta clearing each keyYes — but you must name every key
App-scoped state (app: keys)Not personal dataN/A — never store personal data here
Artifacts (files, images, reports)artifact_service.delete_artifact(...)Yes — including version history
Memory backend entriesMemoryService exposes add/search onlyBackend-side — see §4
Application logs, backups, analyticsOutside ADKYour own deletion pipeline

Two rules fall straight out of the table. Minimization: never put personal data in app: state, because it is shared across all users and cannot be deleted per-user without breaking everyone else. Purpose limitation: if a value does not need to outlive the current task, keep it in temp: (invocation-scoped, discarded automatically) rather than persisting it at all — data you never stored needs no erasure.

2. Enumerate and delete every session

The core loop is list_sessions followed by delete_session per result:

from google.adk.sessions import DatabaseSessionService

session_service = DatabaseSessionService(db_url="postgresql+asyncpg:///agent.db")

async def erase_user_sessions(app_name: str, user_id: str) -> int:
    """Delete every session belonging to one user. Returns count removed."""
    deleted = 0
    # list_sessions returns a page of sessions for this (app_name, user_id)
    page = await session_service.list_sessions(app_name=app_name, user_id=user_id)
    for session in page.sessions:
        await session_service.delete_session(
            app_name=app_name,
            user_id=user_id,
            session_id=session.id,
        )
        deleted += 1
    return deleted

Two details matter here. First, list_sessions pages — a user with hundreds of conversations will not arrive in one response, so loop until the page is empty in production code. Second, deleting the session removes its events and its session-scoped state in one operation, because both live inside the session record. A missing or already-deleted session_id raises SessionNotFoundError (a ValueError subclass); catch it and continue rather than aborting the erase mid-way, since a partially erased user is worse than an idempotent one.

3. Clear user-scoped state and artifacts

User state outlives sessions, so it survives §2. user: keys are keyed by user_id within the app, and the only sanctioned way to remove them is an explicit state_delta that clears each key — never by mutating a fetched Session object, which bypasses event tracking:

from google.adk.events import Event, EventActions

# Every personal key you ever wrote with a `user:` prefix — this list is
# the contract; add a key here the moment you introduce one elsewhere.
PERSONAL_USER_KEYS = [
    "user:full_name",
    "user:email",
    "user:shipping_address",
    "user:loyalty_number",
]

async def clear_user_state(session_service, app_name: str, user_id: str) -> None:
    session = await session_service.create_session(
        app_name=app_name, user_id=user_id,
    )
    await session_service.append_event(
        session,
        Event(
            invocation_id="gdpr_erase",
            author="system",
            actions=EventActions(
                state_delta={key: None for key in PERSONAL_USER_KEYS}
            ),
        ),
    )

Artifacts are the other long-lived store. Filenames prefixed with user: (e.g. user:profile.png) are scoped to the user across all their sessions, so enumerate and delete them too:

async def erase_user_artifacts(artifact_service, app_name: str, user_id: str) -> None:
    filenames = await artifact_service.list_artifact_keys(
        app_name=app_name, user_id=user_id
    )
    for filename in filenames:
        # delete_artifact removes the artifact and, depending on the
        # implementation, all of its versions.
        await artifact_service.delete_artifact(
            app_name=app_name, user_id=user_id, filename=filename
        )

4. Be honest about memory: erasure is backend-side

Here is the part where most compliance write-ups quietly lie. ADK’s MemoryService interface exposes ingestion and search — add_session_to_memory, add_events_to_memory, add_memory, search_memory — and it does not expose a per-entry delete. There is no delete_memory(entry_id) to call from a tool. So a “forget me” tool that only touches sessions and artifacts has still left the user’s statements sitting in your vector corpus or Memory Bank.

The defensible design is to plan erasure at the storage layer and treat the tool as the orchestrator:

  • Memory Bank (VertexAiMemoryBankService): memories are managed in Google Cloud under your Agent Runtime. Deletion happens through the Agent Platform/Memory Bank management APIs and its console, not through ADK’s Python interface. Route this through your GCP automation and record the result.
  • RAG corpus (VertexAiRagMemoryService): your user statements are indexed in a Knowledge Engine corpus. If the corpus holds personal data, erasure means managing that corpus (or its source documents) in Google Cloud — or isolating users into per-tenant corpora so one user’s erasure never touches another’s data.
  • InMemoryMemoryService: nothing survives restart, but until a restart everything is still there, and it is keyword-searchable. Treat it as a dev-only backend; shipping it in production means your erasure story is “wait for a deploy.”

The tool should therefore return an honest status per store — "sessions": "deleted", "artifacts": "deleted", "memory": "manual: gcp-console → memory-bank → delete" — rather than a single triumphant {"ok": true} that an auditor will eventually disprove.

5. The audit trail you will be asked for

Right to erasure is a process obligation as much as a technical one. Regulators and users will ask what was deleted, when, and by whom. Log a structured record per request: the user_id (or a pseudonymous request ID), a timestamp, each store touched with its outcome, the operator or service account that initiated it, and any store that requires backend-side follow-up with its status. Store that record somewhere the user’s data cannot reappear — an append-only audit log keyed by request ID, not by user profile.

Keep the request handler idempotent: a repeated erase request should return “already erased” rather than fail on SessionNotFoundError, so retries and double-submits cannot leave a partial trail that looks like tampering.

Checklist

  • A data inventory exists and names every store holding personal data, including logs and backups.
  • No personal data is written to app: state, and temp: is used for values that need not persist.
  • list_sessions is paged to exhaustion before erase is reported complete.
  • Every delete_session failure (SessionNotFoundError) is caught and logged, not silently skipped.
  • All user: state keys are enumerated in one constant and cleared via an explicit state_delta.
  • User-scoped artifacts (user:* filenames) are listed and deleted, versions included.
  • The memory backend’s erasure path is documented per implementation — and is honestly marked manual where ADK has no API.
  • An append-only audit record captures request ID, timestamp, per-store outcomes, and initiator.
  • The whole flow is idempotent and safe to re-run.
  • Minimization and purpose limits are reviewed so future data does not need erasing in the first place.

Conclusion

A forget-me tool in ADK is a short piece of code — enumerate sessions, delete them, clear user: state, delete user-scoped artifacts — wrapped in the two harder parts: an accurate inventory of where personal data hides, and an honest account of the stores ADK’s interface cannot erase for you. Build it on the real primitives, refuse to claim more than you actually deleted, and pair it with minimization so the erasure job shrinks over time instead of growing.

References