Memory is a privacy surface. Everything an agent remembers can leak through a later recall, a shared store, a backup, or an audit export. The privacy question is not whether to keep memory, it is what to keep, who may read it, and when it must go. This skill covers the policy layer that sits above capture and hygiene, meaning minimization rules, retention schedules, access scoping, deletion workflows, and erasure handling. It builds on ../memory-hygiene/SKILL.md, which covers routine cleanup, and adds the policy decisions that cleanup alone cannot make.
Quick Workflow
- Classify every capture by sensitivity before it is stored, using the sensitivity scale in section 1.
- Assign a retention schedule and a reader scope at capture time, never as an afterthought.
- Enforce TTL expiry automatically, and log every expiry run.
- Redact or delete on request, and verify the deletion by querying for the record afterwards.
- Audit access quarterly, or after any incident, and review which agents read sensitive records.
- Handle erasure requests as a tracked workflow with a completion check, not as a single delete command.
1. Sensitivity classification at capture
Classification must happen at capture, because reclassifying a large store later is unreliable and slow. Four levels are enough for most agent stores, and each level maps to concrete handling rules rather than vague caution.
# memory-privacy.yaml - sensitivity levels and their handling rules
sensitivity:
public:
examples: ["tool usage notes", "public documentation summaries"]
reader_scope: any_agent
retention_days: 365
backup: allowed
internal:
examples: ["host inventories", "scan schedules", "internal procedures"]
reader_scope: project_agents
retention_days: 180
backup: allowed_encrypted_only
sensitive:
examples: ["credentials metadata", "user identifiers", "session details"]
reader_scope: named_agents_only
retention_days: 30
backup: forbidden
prohibited:
examples: ["passwords", "private keys", "secret tokens"]
reader_scope: none
retention_days: 0
backup: forbidden
action: reject_at_capture
The prohibited level is a hard rule, not guidance. A capture pipeline that stores a secret and then flags it for later deletion has already failed, because the secret sat in the store, in backups, and possibly in recall results. Reject at capture, log the rejection without the secret value, and tell the capturing agent what to store instead, such as a reference to where the secret lives under proper control.
2. Retention schedules and TTL enforcement
A retention schedule is a table, not a feeling. Each layer and sensitivity level gets a TTL, and expiry runs on a schedule with a report. The enforcement script below is intentionally boring, because expiry must be the most reliable job in the system, not the cleverest.
"""TTL enforcement: expire due records and report what was removed."""
import sqlite3
from datetime import datetime, timezone
def enforce_retention(db_path):
now = datetime.now(timezone.utc).isoformat()
conn = sqlite3.connect(db_path)
cursor = conn.execute(
"SELECT layer, COUNT(*) FROM memory_records "
"WHERE expires IS NOT NULL AND expires < ? "
"GROUP BY layer", (now,))
due = dict(cursor.fetchall())
conn.execute(
"DELETE FROM memory_records "
"WHERE expires IS NOT NULL AND expires < ?", (now,))
conn.commit()
conn.close()
return due
if __name__ == "__main__":
removed = enforce_retention("memory.db")
print("Retention run removed records by layer:")
for layer, count in sorted(removed.items()):
print(" " + layer + ": " + str(count))
Rules for the schedule:
- TTL is set at capture from the sensitivity table, and a later edit that extends a TTL requires a named approver and a logged reason.
- Expiry deletes the record and its index entries. A delete that leaves the text searchable in an index is not a deletion.
- Backups follow the same schedule. A backup that outlives the retention period reintroduces deleted records on restore, so backup rotation must be shorter than the shortest TTL it holds.
- Legal holds pause expiry for named records only, with an expiry date on the hold itself. A hold without an end date is a retention violation waiting to happen.
3. Access scoping and audit logging
Reader scope is enforced at query time, not by trusting agents to filter their own results. A query from an agent outside a record's scope must not see the record at all, not even its id or metadata, because metadata alone can confirm that something sensitive exists. The query guard below shows the shape of that enforcement.
"""Reader scope enforcement: scope check runs before any result ships."""
def scoped_search(store, agent, scope, query, limit=10):
allowed_layers = scope.allowed_layers(agent)
rows = store.search(query=query, limit=limit * 2)
visible = []
for row in rows:
if row.layer not in allowed_layers:
continue
if row.sensitivity == "sensitive" and agent not in row.readers:
continue
visible.append(row)
if len(visible) >= limit:
break
store.audit_log(agent=agent, query=query, returned=len(visible))
return visible
Audit logging records who queried what and how many rows came back, but never the returned text itself, because the audit log would then become a second copy of the sensitive store. Review the audit log for bulk reads, off-scope attempts, and queries that look like fishing for identifiers. An off-scope attempt is a security event, not a missed recall, and it should be reported as one.
4. Erasure requests and deletion verification
An erasure request covers the record, its derived summaries, its index entries, and its appearance in backups within the rotation window. The verification harness below checks that deletion actually worked, by querying for the record and for its distinctive terms after the delete runs.
"""Deletion verification: confirm a record and its traces are gone."""
def verify_erasure(store, record_id, distinctive_terms):
checks = {}
checks["record_gone"] = store.fetch(record_id) is None
for term in distinctive_terms:
hits = store.search(query=term, limit=50)
checks["term_gone_" + term] = all(
h.id != record_id for h in hits)
checks["summaries_checked"] = store.summaries_referencing(record_id) == []
return checks
# A passing erasure has every check True. Any False value means the
# erasure is incomplete and the request stays open until it passes.
Erasure workflow rules:
- Acknowledge the request with a scope statement, meaning which stores and backups it covers, and a completion date.
- Delete derived summaries that quote the record, or rewrite them without the erased content, and log which option was chosen.
- Never confirm or deny the existence of a specific sensitive record to an unauthenticated requester. Erasure handling itself must not become an oracle for what the store holds.
- Keep a deletion receipt that records the request id, the scope, and the verification result, but not the deleted content.
Edge cases
- A record is both needed for an audit and subject to erasure. Keep the audit fact, meaning that an event happened on a date, and erase the personal content around it, with the split documented.
- A shared store serves several tenants. Scope by tenant at the storage layer, with separate encryption keys per tenant where the risk justifies it, and never rely on query filters alone.
- A user asks what the agent remembers about them. Answer from the store with a scoped export, redact other users' content from it, and log the export as an access event.
- A backup restore reintroduces expired records. Re-run retention enforcement immediately after any restore, before agents query the restored store.
- Retention law and task need conflict. The stricter rule wins, and the conflict is escalated to a human, not resolved by the agent quietly keeping the data.
Key references
- CWE-200 (Exposure of Sensitive Information to an Unauthorized Actor): why scope enforcement and audit matter.
- CWE-312 (Cleartext Storage of Sensitive Information): why prohibited content must never reach the store.
- SQLite documentation: https://sqlite.org/docs.html
- ../memory-hygiene/SKILL.md and ../memory-capture/SKILL.md in this repo.
