Long-term memory makes agents feel smart until someone asks “why does it know my divorce?” Memory without consent, TTL, and a user-visible editor is just surveillance with embeddings.
⚡ TL;DR: Store memories as explicit, typed records with subject, source, consent, and expiry. Show them in UI. Default to session scratch + retrieval over silent profiles. Delete on request and on TTL.
Memory tiers (revisit Day 13 with ethics)
| Tier | Lifetime | Consent | Example |
|---|---|---|---|
| Scratchpad | Request | Implicit | Current plan |
| Session | Hours | Implicit | Thread decisions |
| Project | Weeks | Team | Repo conventions |
| Personal long-term | Months | Explicit opt-in | “Prefers pytest” |
# ✅ Typed memory row — never a free-text void
from dataclasses import dataclass
from datetime import datetime
@dataclass
class Memory:
id: str
subject_id: str # user or team
kind: str # preference | fact | procedure
text: str
source: str # "user_asserted" | "inferred"
consent: bool
expires_at: datetime
visible_to_user: bool = True
def write_memory(m: Memory, store) -> None:
if m.source == "inferred" and not m.consent:
raise PermissionError("inferred memory requires consent")
if not m.visible_to_user:
raise PermissionError("hidden memories forbidden")
store.put(m)
❌ Silent inference of sensitive attributes from tickets or email into a vector profile.
User-visible controls
- List / edit / delete memories in settings.
- “Forget this project” wipes project-scoped rows.
- Export for DSAR.
Failure modes
“Helpful” inferred memories about health, finance, or HR topics. Block sensitive categories entirely. Embeddings of memory text can still leak via nearest-neighbor — encrypt vectors at rest and isolate per subject.
Closing checklist
- [ ] Consent flag and TTL on every long-term row
- [ ] UI to inspect and delete
- [ ] Inferred vs user-asserted distinguished
- [ ] No hidden memories
- [ ] Legal review of retention
Series navigation
Day 80: Project: Platform AI Gateway · Day 82: Voice and Realtime Agents
Last updated September 11, 2026
Discover more from CheatCoders
Subscribe to get the latest posts sent to your email.
