Memory and multi-agent systems in TypeScript · Chapter 7 of 16
Forgetting
By the end of this chapter you can keep what must never be stored out of memory, let a tentative fact expire, and delete what a person asks you to delete from every place memory lives, including the places that are easy to forget. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: Memory
- 5 tasks
- TypeScript
- In the all labs plan
The first 2 chapters of Memory and multi-agent systems in TypeScript are free. This one comes with the all labs plan.
Why you need this
Chapters 2 to 6 were about remembering more, and remembering it right. This one is about the opposite, and Pooja says it is the one that decides whether families trust Baraat Bliss at all. Rekha's threads hold things nobody should keep:
- Rajesh Sharma sent his PAN "for the GST invoice". Zainab Qureshi sent a card number "for the advance". Rekha told her not to; it was already in the thread.
- Ananya told Rekha about her grandfather's surgery and his medicines, "but please don't write that down anywhere, just the wheelchair".
- In September, Ananya's sister Kavya asked: "please delete my phone number from your records".
The September team meeting decided: never store health details, PAN or card numbers, and delete what was stored. /workspace/data/policy.md sections 3 to 5 say how. Everything built so far stores whatever it reads, in more and more places: a fact store, a history, summaries, a vector index. An assistant built that way breaks every one of those rules by default, and the more memory it has, the harder a deletion gets.
What you build: 5 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
redact.ts: redact what is never stored
Write and export redact(text) in redact.ts. It returns the text with these replaced, and nothing else changed: a card number (16 digits, together or in four groups of 4 split by single spaces or by hyphens) by [card]; an Aadhaar number (12 digits, the same way in three groups) by [aadhaar]; a PAN (five capital letters, four digits, one capital letter) by [pan]; a phone number (10 digits starting with 6 to 9, maybe split 5 and 5 by a space or a hyphen, maybe after +91 and a space or a hyphen) by [phone]. None counts with a letter, digit or hyphen just before or after it.
Inside if (import.meta.main), go through every wedding's thread in the order of weddings() and print each message redact changes as its id, a colon, a space and the redacted text. The check tries its own texts too, and calls redact many times in a row: amounts, dates, ids and PIN codes stay as they are.
- Task 2
screen.ts: screen a message before it is stored
Write and export an async function shouldStore(message) in screen.ts for a thread message. If redact (task 1) changes its text, resolve to false without asking the model. Otherwise ask lab-chat at temperature 0 to classify the message as one of: sensitive, safe, sending it as a user message (its sender, a colon, a space and its text); a reply of sensitive (any case, a full stop allowed) means false, anything else true.
Inside if (import.meta.main), screen every message of every wedding in the order of weddings() and print two lines: refused: and the refused ids joined with a comma and a space; then agree with the labels: N of M, where a message agrees when it was refused exactly when its sensitive label is not empty.
- Task 3
ttl.ts: options that expire
Write and export the class TTLStore in ttl.ts. new TTLStore(path) creates, if missing, the SQLite table facts(wedding_id, key, value, said_at, expires_at), one row per wedding and key, value as JSON. put(weddingId, key, value, saidAt, tentative = false) keeps saidAt's day (its first 10 characters): a decision has no expires_at (NULL) and replaces whatever was there; an option's expires_at is the day 30 days later, and an option never replaces a decision. sweep(today) deletes the rows whose expires_at is before today and returns them as an array of [weddingId, key, value], sorted by wedding id then key.
Inside if (import.meta.main), use new TTLStore(':memory:') and replay every message of every wedding sorted by at: for each, sweep on its day and print each swept fact like 2026-03-01: swept WD1000 caterer = Some Caterers, then put its facts (tentative from the message). After the last message, sweep on 2026-10-22 too.
- Task 4
delete.ts: delete everywhere memory lives
memory.ts (given) keeps a wedding's memory in four tables: facts, history, summaries and memories (each message with its vector). Write and export an async function forgetText(memory, weddingId, text) in delete.ts: in that wedding only, delete the facts and history rows whose key or value holds the text and the memories whose text holds it, then rebuild with memory.resummarise the summary of every session that lost a message or whose summary holds the text.
Write and export an async function forgetPerson(memory, weddingId, name): in that wedding only, delete the facts and history rows whose key ends with a colon and the name, and the memories the person sent or whose text names them, then rebuild the summaries of those sessions.
Inside if (import.meta.main), start a new memory.db, remember WD1042's session 8, and for 9829012345 and then ABCPS1234K print the text, before: and memory.where for it, forget it, and print the text, after: and where again; last, print the first result of searching How can we reach Kavya?
- Task 5 · interview question
Interview: fix-me.ts, a deletion that search still finds
Recall in fix-me.ts keeps messages and their vectors in SQLite and loads the vectors into an array for search. Run it: after forget deletes Kavya's phone number, search still returns it.
Fix Recall so that after forget, search never returns a forgotten message, while every other message is still found, and a new Recall on the same file agrees. Keep the class's name, its methods, their parameters and the export. The check uses other weddings and texts.
What you will learn
- What never to store, and how to keep it out: patterns first, then a model.
- Regular expressions in TypeScript: the g flag, replaceAll, and the lastIndex a g regex carries between calls.
- Time to live: a tentative fact expires unless it is confirmed.
- Deleting on request from facts, history, summaries and vectors.
- Why deletion fails in practice: copies you forgot you had.
More in Memory
Build "Forgetting" yourself
Baraat Bliss, a Jaipur wedding planner, must remember months of family decisions across many agents. You build its assistant in TypeScript. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.
The first 2 chapters of Memory and multi-agent systems in TypeScript are free. This one comes with the all labs plan.