Skip to content

Example: per-user memory for a support agent, with one user erased #702

Closed

Description

@zlareb1

Company or project name

No response

Component

Python SDK

Use case

App builders ask for long-term memory per end user that survives conversations and can be erased on request. sdk/python/examples/agent_memory.py already shows per-user memory for one user (user_id on each call); no example shows two users kept apart, a fact revised, and one user's data erased and checked gone.

Describe the solution you'd like

Goal. sdk/python/examples/support_agent_memory.py, next to agent_memory.py and built on its layout.

Files to start from

  • sdk/python/examples/agent_memory.py: the layout, the per-call user_id and the cleanup.
  • docs/reference/operations/erasure.md: erasure.request (scope_type, scope_value, requester) and erasure.status.
  • docs/guides/tokens-and-grants.md: the org_admin role.

Acceptance criteria

  • Writes facts for two user_ids; a memory.search narrowed to each user returns only that user's facts.
  • Updates one fact (memory.update_by_id) and shows the new value.
  • Erases one throwaway user with erasure.request (scope_type: "user_id") and polls erasure.status until the saga is completed with residue_count 0; then that user's search returns nothing and the other user's facts are still there. Say beside the call that a user_id scope covers every namespace in the org, so the script must use a user id that exists only in its own run.
  • user_id erasure needs an org admin. On a server with auth on, loom mint-token --roles takes viewer, writer or admin only, so the README says how to get a token that may erase (for example loom mint-token --platform-admin --subject sa:<name> --org <org> --ttl-days 1 on a local server).
  • Exits 0 only when every check passes.
  • tests/unit/test_sdk_example_support_agent_memory.py, modelled on tests/unit/test_sdk_example_agent_memory.py: it loads the script by path and runs it against an httpx.MockTransport server that answers each op. It checks that the script's cleanup deletes the memories it wrote when a step in the middle fails (for example memory.update_by_id answering 422), and that the script exits non-zero when a check fails (the erased user's search still returns a fact) and 0 when every check passes.
  • Listed in sdk/python/examples/README.md with a real run's output, and under "Examples" in docs/reference/python-sdk.md.

How to test

  • Against a local Loom: python sdk/python/examples/support_agent_memory.py.
  • make format-check lint, the example's unit test, and the docs checks:
.venv/bin/python -m pytest tests/unit/test_sdk_example_support_agent_memory.py -q
.venv/bin/python -m pytest tests/unit/test_doc_links.py tests/unit/test_public_copy.py -q
.venv/bin/python -m scripts.codegen.docs_reference --check

Describe alternatives you've considered

agent_memory.py covers one user and deletes its memories by key; it does not show isolation between users or erasure.

Where the need comes from

The need is mine, an AI tool helped shape the proposal

Additional context

Start after #696 merges, or rebase onto it: it edits docs/reference/python-sdk.md.

Size: M (a day or two). Read CONTRIBUTING.md first (signed-off commits), and comment here to say you are working on it.

Activity

  1. added
    enhancement
    help wanted
    on Nov 16, 2026
  2. rahulsjha commented on Nov 16, 2026

    @rahulsjha
    Contributor

    Hi @zlareb1, I'd like to pick this up. Plan: add sdk/python/examples/support_agent_memory.py on the agent_memory.py layout that writes facts for two user_ids and checks a memory.search narrowed to each user returns only that user's facts, revises one with memory.update_by_id, then erases a run-unique user with erasure.request (scope_type: "user_id", with a note that this scope covers every namespace in the org), polls erasure.status until completed with residue_count 0, and confirms that user's search is empty while the other user's facts remain; it exits 0 only when every check passes. tests/unit/test_sdk_example_support_agent_memory.py runs it on an httpx.MockTransport and asserts cleanup when memory.update_by_id answers 422, a non-zero exit when the erased user still has a fact, and 0 on success. The examples README gets a real run and the loom mint-token --platform-admin steps for a token that may erase, plus the entry in docs/reference/python-sdk.md, rebased onto #696 and with signed-off commits. Could you assign it to me?

  3. added
    up-for-grabs
    on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementhelp wantedup-for-grabs

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions