Memory Forgetting
Memory forgetting allows memories that are no longer needed to exit search results while preserving data for future recovery. This helps manage the memory lifecycle safely and reversibly when users request to forget information or when the memory store grows over time.
Problems addressed
Without memory forgetting, memory lifecycle management may cause the following issues:
-
Hard deletion is irreversible. Accidental deletions cannot be recovered.
-
Stale memories that have been idle for a long time continue to appear in search results, which interferes with the agent's understanding of the user's current state.
-
The number of memories keeps growing without a unified cleanup mechanism.
Capabilities
|
Capability |
Description |
|
Archive removes from search |
Archived memories no longer appear in search results. The agent is no longer influenced by them. |
|
Reversible |
Archiving does not delete data. Restore individual memories or all memories for a user at any time. Restored memories immediately return to normal search behavior. |
|
Automatic forgetting |
When enabled, the system automatically archives memories that have had no activity for a prolonged period. The memory store stays lean. |
|
Management visibility |
Archived memories remain queryable through the management endpoint for review before further action. |
|
Permanent deletion |
When you confirm that archived memories are no longer needed, permanently delete all archived memories for a user to reclaim storage space. |
Use cases
-
A user explicitly requests to forget something and the information must immediately exit the agent's awareness.
-
Compliance scenarios require certain information to stop being used while retaining the necessary audit trail.
-
After prolonged use, the memory store accumulates stale memories that need automated cleanup.
-
Batch memory management by user, such as data processing during account deregistration.
Usage
|
Operation |
Endpoint |
Description |
|
Archive a memory |
POST /memories/{memory_id}/archive |
Idempotent. Repeated archiving does not return an error. |
|
Query archived memories |
POST /memories/archived |
Paginated. Filter by user. |
|
Restore a memory |
POST /memories/{memory_id}/restore |
The memory becomes searchable immediately after restoration. |
|
Batch restore by user |
POST /memories/restore?user_id=xxx |
Restore all archived memories for the specified user. |
|
Permanent deletion by user |
DELETE /memories/archived?user_id=xxx |
Irreversible. Deletes all archived memories for the specified user. |
When querying archived memories, specify the user and pagination in the request body:
curl -sS -X POST "${MEMORY_URL}/memories/archived" \
-H "Authorization: Token ${MEMORY_API_KEY}" \
-H "Content-Type: application/json" \
-d '{"filters": {"user_id": "demo-user-001"}, "page": 1, "page_size": 100}'
filters must include at least one of user_id, agent_id, or run_id. Otherwise, a 400 error is returned. The page_size range is 1 to 200. In the response, count is the total number of archived memories, next and previous are the URLs for the next and previous pages (null if none), and results is the memory list.
Enable automatic forgetting
Automatic forgetting is disabled by default. Enable it through the configuration endpoint:
curl -sS -X POST "${MEMORY_URL}/configure" \
-H "Authorization: Token ${MEMORY_API_KEY}" \
-H "Content-Type: application/json" \
-d '{"enable_memory_forget": true}'
After it is enabled, the system automatically archives memories that have had no activity (no writes, updates, or search hits) in the last 3 months. Frequently used memories are not affected.
Archiving only removes memories from search results. It does not reclaim storage space. Only permanent deletion reclaims space. Updating an archived memory automatically restores it.
Example
The following example demonstrates the complete workflow: archive a memory, confirm it exits search, and then restore it.
Pass the API key through environment variables. Do not hardcode it in code or public documentation.
Step 1: Configure the endpoint and credentials
export MEMORY_URL="https://api-longmemory-cn-beijing.opentrust.net"
export MEMORY_API_KEY="<Replace with your API Key>"
export USER_ID="demo-user-001"
Step 2: Write a memory and archive it
curl -sS -X POST "${MEMORY_URL}/memories" \
-H "Authorization: Token ${MEMORY_API_KEY}" \
-H "Content-Type: application/json" \
-d '{"messages":[{"role":"user","content":"I am allergic to peanuts"}],"user_id":"'${USER_ID}'","async_mode":false}'
Note the id from the response (referred to as MEMORY_ID), then archive it:
curl -sS -X POST "${MEMORY_URL}/memories/${MEMORY_ID}/archive" \
-H "Authorization: Token ${MEMORY_API_KEY}"
Response:
{"message": "Memory archived successfully", "memory_id": "xxxxxxxx"}
Step 3: Confirm the memory exits search
curl -sS -X POST "${MEMORY_URL}/search" \
-H "Authorization: Token ${MEMORY_API_KEY}" \
-H "Content-Type: application/json" \
-d '{"query":"What allergies does the user have","user_id":"'${USER_ID}'"}'
The search results no longer include the peanut allergy memory.
Step 4: Restore the memory
curl -sS -X POST "${MEMORY_URL}/memories/${MEMORY_ID}/restore" \
-H "Authorization: Token ${MEMORY_API_KEY}"
Response:
{"message": "Memory restored successfully!", "memory": {"id": "xxxxxxxx", "memory": "The user is allergic to peanuts"}}
After restoration, the memory participates in search again.
Best practices
-
Prefer archiving over permanent deletion. Archiving is reversible. Permanent deletion is not. Query the archived memory list to review before you perform permanent deletion.
-
Use archiving for compliance "stop using" requirements. Archiving satisfies the requirement to stop using information. Enable trace configuration if you need an audit trail.
-
Perform batch operations by user. Both restore and permanent deletion support user_id-scoped operations. No need to maintain individual memory ID lists.
-
Test before enabling automatic forgetting. Manually archive a few memories first and verify that the recall behavior meets your expectations before enabling automatic mode.
-
Updates trigger restoration. If you want a memory to remain archived, do not perform update operations on it.