n8n ai agent memory 9 scenes — slots, long-term
Memory is a budget: window slots decay at alpha 0.72 and only turns hitting the promotion threshold reach long-term memory.
The rest of this page works the nine scenes in the order you would actually touch memory: routing turns by session key, pinning the node settings, diffing one write, then the lifetime questions — decay, promotion, dedupe, compression — and the clear-and-restore pair that closes the loop.
01 session-timeline-routes
02 memory-node-settings
03 turn-write-diff
04 slot-window-decay
05 promote-longterm
06 dedupe-levenshtein
07 summary-compress-budget
08 clear-session-switch
09 restore-session-resume
- 01 The Conversation Timeline: Turns Split by Session Key into Memory
- 02 The Memory Node Panel: Session ID, Window Size, Context Length
- 03 The JSON Diff of a Memory Read and Write
- 04 Slot Fill and Slide: Window Size and Exponential Decay
- 05 Long-Term Promotion: Recurrence Threshold and the Promotion Arrow
- 06 Dedupe: Merging Same Questions by Levenshtein Distance
- 07 Summary Compression: Budget Overflow and the Compression Ratio
- 08 Clearing Memory: Session Switch and What Remains
- 09 Session Restore: Returning to the Earlier Conversation and Continuing
What n8n AI agent memory is: conversation context keyed by session ID
One engine layer drives all nine scenes
None of the nine scenes invents its own clock. They stand on one shared core — a two-second, 24-frame WAAPI cycle with pause, rebuild and reduced-motion branches inherited from the previous ai-agent episode, plus a seedHash function that turns a seed into fixed random values so every replay rebuilds the identical run, with no Math.random anywhere. Above that core sit this episode's lead calculations, and every one of them is plain arithmetic: memDecay shrinks old turn heights once the total crosses a budget; jac scores token overlap between two turns; levDist counts edit steps between two questions; keyHash folds a key string's character codes into a normalized gauge fill; and a compression ratio with a fixed summary overhead decides how many turns fold into one summary bar. Every act in these scenes — filling, decaying, promoting, deduplicating, compressing — falls out of these functions, so the whole episode runs with zero external LLM calls.
// MEM_DECAY — shrink oldest turn heights by alpha^k once the total crosses the
// budget. Scene 04's lead calculation
function memDecay(heights, budget, alpha) {
let total = 0;
for (let i = 0; i < heights.length; i += 1) { total += heights[i]; }
const out = heights.slice();
let k = 0;
let idx = 0;
while (total > budget && idx < out.length) {
out[idx] = heights[idx] * Math.pow(alpha, k + 1);
total = 0;
for (let i = 0; i < out.length; i += 1) { total += out[i]; }
k += 1;
idx += 1;
}
return out;
}
jac divides shared tokens by the union of both token lists, levDist walks a two-row dynamic program charging one step per insert, delete or replace, and keyHash folds character codes as h = h × 31 + code, mod 997, normalized to 0–1. Each of these is checked line by line in its scene below.
// LEV_DIST — edit distance between two questions (insert, delete, replace each
// cost 1). Scene 06's merge judgment uses it
function levDist(a, b) {
const m = a.length;
const n = b.length;
if (m === 0) { return n; }
if (n === 0) { return m; }
let prev = [];
for (let j = 0; j <= n; j += 1) { prev.push(j); }
for (let i = 1; i <= m; i += 1) {
const cur = [i];
for (let j = 1; j <= n; j += 1) {
const cost = a.charCodeAt(i - 1) === b.charCodeAt(j - 1) ? 0 : 1;
cur.push(Math.min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + cost));
}
prev = cur;
}
return prev[n];
}
The demo is an educational rule approximation, not an n8n execution
Draw the boundary first, because the whole page stands on it: the memory fills, decays, promotions, dedupe verdicts and compressions in these scenes are not measured from a running n8n instance. They are an injected demonstration — deterministic rule math written to imitate the memory behavior that n8n's official documentation describes, for teaching. What is real: the AI Agent node holds its conversation context in a Memory sub-node, and the agent reads and writes that memory every turn. Window Buffer Memory keeps only the last N turns as context; Simple Memory is the default sub-node and separates conversations by Session ID. PostgreSQL, MongoDB, Supabase and Redis also ship as chat-memory backends — search suggestions like n8n ai agent memory postgresql were measured as real query strings. The node names used throughout — AI Agent, Simple Memory, Window Buffer Memory, Postgres Chat Memory, MongoDB Chat Memory, Redis Chat Memory — are real n8n nodes. What is ours: the decay alpha, the Jaccard threshold, the Levenshtein threshold and the compression ratio. In a live n8n workflow the memory backend and any summarization are decided by the connected chat model and the sub-node implementation, and Window Buffer Memory's context length is exactly its setting value — there is no automatic decay curve inside it. The scene values can differ from any real run, in both directions.
Where model values end and measured values begin
Every number in this article is one of two kinds. Model values are computed or hand-checked from the source constants: budget 360, decay alpha 0.72, promotion threshold 3 with Jaccard 0.34, dedupe threshold 6, compression keep 0.55 with a 12-token summary overhead, clear segment 340ms, and restore at 4 turns × 300ms = 1,200ms. Measured values come from the renderer leaving twenty-four stills of each two-second cycle and comparing adjacent pairs — twenty-three diffs per scene. Cumulative area is the share of pixels that changed at least once inside the cycle window, and intensity is the mean brightness-and-color difference of changed pixels on a 0–255 scale, which jitters about ±0.1 with render noise.
The measured answer sheet
One injected-demonstration cycle was rendered for each of the nine scenes; a background sweep that carries the progress value left-to-right across the scene backdrop supplies most of the area, and no scene held a still frame anywhere in the window.
| Scene | Cumulative area | Frames moved | Mean intensity |
|---|---|---|---|
| 01 session timeline routes | 36.5% | 23/23 | 90.3 |
| 02 memory node settings | 35.7% | 23/23 | 99.5 |
| 03 turn write diff | 35.9% | 23/23 | 106.3 |
| 04 slot window decay | 35.4% | 23/23 | 106.8 |
| 05 promote long-term | 32.5% | 23/23 | 122.8 |
| 06 dedupe levenshtein | 28.4% | 23/23 | 126.9 |
| 07 summary compress budget | 34.1% | 23/23 | 108.0 |
| 08 clear session switch | 33.4% | 23/23 | 105.5 |
| 09 restore session resume | 32.8% | 23/23 | 83.6 |
The widest area is scene 01 at 36.5% and the narrowest is scene 06 at 28.4% — the dedupe heatmap is the most compact canvas of the set, because its cells sit in one corner block while other scenes spread bars across the full width. Intensity peaks in the same scene 06 at 126.9, where each cell swap flips a whole heatmap cell in one cut, and bottoms in scene 09 at 83.6, whose restore travel is the gentlest motion of the set — four slots sliding home plus one new turn stacking on top. All twenty-three frame pairs moved in every scene; a frozen memory scene would be a broken one. Canvas overflow, 320px-width overflow and per-locale string overflow all came back zero on the nine scenes, and the React builds cleared nine TypeScript compiles and nine standalone SCSS compiles.
Why these nine scenes in this order
The order follows the way you actually work agent memory. You see the conversation flow and how a session key routes each turn (01), open the memory node and pin its settings (02), check in the data what one turn's write changed (03), then watch the window fill and old turns slide (04) — and then the lifetime questions: which turns earn a promotion to long-term memory (05), which questions merge as duplicates (06), and what happens when the budget forces a summary (07). Clearing on session switch (08) and restoring by session ID (09) close the loop. Where the previous episode on this column, the n8n ai agent node tool loop, opened the inside of the agent's loop, this episode opens the drawer it reads from and writes to every turn — with the same node-graph grammar.
01How the conversation timeline splits by session key into memory
Turn bubbles on the left chat timeline split by session key (sess-A/sess-B) and flow into two memory boxes on the right, each bubble riding its route path and stacking in arrival order, with a badge marking which session the flowing turn belongs to — this routing view is the material for watching two conversations interleave, and judging what a turn changed is scene 03's diff job.

<main class="stage">
<div class="ez is-demo" id="ez">
<div class="ez__in" data-role="inner">
<div class="ez__pad" data-role="pad" tabindex="0" role="application" aria-label="Demo stage — Space or Enter to pause, R to restart, left/right arrows for other values">
<div class="ez__scene" data-role="scene" role="img" aria-label="Turn bubbles split by session key flowing into memory boxes"></div>
<div class="ez__probe" data-role="probe" aria-hidden="true"></div>
<div class="ez__chart" data-role="chart" aria-hidden="true"></div>
<p class="ez__status" data-role="status" aria-live="off">Scene ready</p>
<p class="ez__reada" data-role="reada" aria-hidden="true"></p>
<p class="ez__readb" data-role="readb" aria-hidden="true"></p>
<div class="ez__ctrl">
<button class="ez__pause" data-role="pause" type="button" aria-pressed="false">Pause</button>
… (총 18줄 — 아래 「전체 코드」에서 원문 전체)// 533 공통 — n8n AI 에이전트 메모리 (532 base.scss 계승: 노드 그래프 요소에 메모리 슬롯·세션 배지·히트맵 셀을 얹는다)
@use "../../../../site/static/demo-tokens" as *;
@include stage($subject-cream);
$panel: mix($subject-cream, $subject-ink, 88%);
$dim: #6d675f; // mix(cream,ink,45%)#7f7a76 은 크림 위 3.98:1 로 미달 — 한 단계 내려 5.25:1
// 파스텔 액센트 — vivid 토큰 대신 (BD26)
$stroke-blue: #d5daea;
$stroke-rose: #ebd6db;
$stroke-mint: #8fd8bd;
$stroke-lilac: #c9b8f2;
… (총 623줄 — 아래 「전체 코드」에서 원문 전체)html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #fff7e6;
… (총 809줄 — 아래 「전체 코드」에서 원문 전체)(function () {
const rootEl = document.getElementById("ez");
if (!rootEl) return;
main(rootEl);
function cx(s) { return s; }
function main(root) {
// ── 533 공통 엔진 — 532 run() 시계 계승 (WAAPI 시계읽기·pause·rebuild·reduced 분기)
const W = 480;
const CX0 = 8;
const CW = 432;
function clamp(v, lo, hi) { return v < lo ? lo : (v > hi ? hi : v); }
function lerp(a, b, k) { return a + (b - a) * k; }
… (총 348줄 — 아래 「전체 코드」에서 원문 전체)// SessionTimelineRoutes - 같은 항목 vanilla index.html 의 React 판. 같은 계산을 useEffect 안에서 돌린다
import { useEffect, useRef } from "react";
import styles from "./SessionTimelineRoutes.module.scss";
const cx = (s: string): string => s.split(" ").map((n) => (styles as Record<string, string>)[n] ?? n).join(" ");
function main(root: HTMLElement): (() => void) | undefined {
// ── 533 공통 엔진 — 532 run() 시계 계승 (WAAPI 시계읽기·pause·rebuild·reduced 분기)
const W = 480;
const CX0 = 8;
const CW = 432;
function clamp(v: number, lo: number, hi: number): number { return v < lo ? lo : (v > hi ? hi : v); }
… (총 375줄 — 아래 「전체 코드」에서 원문 전체)01 · The Conversation Timeline: Turns Split by Session Key into Memory — Measured area 36.505% · moving frames 23/23Original by GODRICH · SCSS and React ship in the zip · See the password
The badge follows the arithmetic, not the eye
The turn list is a fixed script whose first field is the session key, and the frame reads that key, picks the route, and never consults anything else — the same claim Simple Memory makes on the real canvas (same Session ID continues the conversation, different ID starts a separate one), with the badge updating from the very key that chose the route at 340ms turn spacing and 240ms travel, one source of truth twice displayed. To adapt a copy, swap the TURNS01 array for your own turn list and the graph becomes a picture of your own chat with the same grammar as the n8n webhook episode.
// TURNS01 — each turn names its session; the frame routes on that field alone
const TURNS01 = [
['A', 'Draft the weekly report'],
['A', 'calculate the cost'],
['B', 'Different topic: translate this'],
['A', 'Continue the report'],
['B', 'Retune the translation tone']
];
02What the memory node panel pins down: session ID, window size, context length
Four settings — Session ID Key, Session ID Value, Context Window Length, Session Time to Live — fill circular gauges while a focus ring walks among them, the session-ID gauge folding the key string's character codes into a normalized 0–1 fill so the key reads as the drawer address of memory, computed rather than drawn — this is the panel for seeing which setting rules memory behavior, and watching turns arrive was scene 01's job.

<main class="stage">
<div class="ez is-demo" id="ez">
<div class="ez__in" data-role="inner">
<div class="ez__pad" data-role="pad" tabindex="0" role="application" aria-label="Demo stage — Space or Enter to pause, R to restart, left/right arrows for other values">
<div class="ez__scene" data-role="scene" role="img" aria-label="Panel gauges filling while a focus ring cycles between settings"></div>
<div class="ez__probe" data-role="probe" aria-hidden="true"></div>
<div class="ez__chart" data-role="chart" aria-hidden="true"></div>
<p class="ez__status" data-role="status" aria-live="off">Scene ready</p>
<p class="ez__reada" data-role="reada" aria-hidden="true"></p>
<p class="ez__readb" data-role="readb" aria-hidden="true"></p>
<div class="ez__ctrl">
<button class="ez__pause" data-role="pause" type="button" aria-pressed="false">Pause</button>
… (총 18줄 — 아래 「전체 코드」에서 원문 전체)// 533 공통 — n8n AI 에이전트 메모리 (532 base.scss 계승: 노드 그래프 요소에 메모리 슬롯·세션 배지·히트맵 셀을 얹는다)
@use "../../../../site/static/demo-tokens" as *;
@include stage($subject-cream);
$panel: mix($subject-cream, $subject-ink, 88%);
$dim: #6d675f; // mix(cream,ink,45%)#7f7a76 은 크림 위 3.98:1 로 미달 — 한 단계 내려 5.25:1
// 파스텔 액센트 — vivid 토큰 대신 (BD26)
$stroke-blue: #d5daea;
$stroke-rose: #ebd6db;
$stroke-mint: #8fd8bd;
$stroke-lilac: #c9b8f2;
… (총 623줄 — 아래 「전체 코드」에서 원문 전체)html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #fff7e6;
… (총 809줄 — 아래 「전체 코드」에서 원문 전체)(function () {
const rootEl = document.getElementById("ez");
if (!rootEl) return;
main(rootEl);
function cx(s) { return s; }
function main(root) {
// ── 533 공통 엔진 — 532 run() 시계 계승 (WAAPI 시계읽기·pause·rebuild·reduced 분기)
const W = 480;
const CX0 = 8;
const CW = 432;
function clamp(v, lo, hi) { return v < lo ? lo : (v > hi ? hi : v); }
function lerp(a, b, k) { return a + (b - a) * k; }
… (총 311줄 — 아래 「전체 코드」에서 원문 전체)// MemoryNodeSettings - 같은 항목 vanilla index.html 의 React 판. 같은 계산을 useEffect 안에서 돌린다
import { useEffect, useRef } from "react";
import styles from "./MemoryNodeSettings.module.scss";
const cx = (s: string): string => s.split(" ").map((n) => (styles as Record<string, string>)[n] ?? n).join(" ");
function main(root: HTMLElement): (() => void) | undefined {
// ── 533 공통 엔진 — 532 run() 시계 계승 (WAAPI 시계읽기·pause·rebuild·reduced 분기)
const W = 480;
const CX0 = 8;
const CW = 432;
function clamp(v: number, lo: number, hi: number): number { return v < lo ? lo : (v > hi ? hi : v); }
… (총 338줄 — 아래 「전체 코드」에서 원문 전체)02 · The Memory Node Panel: Session ID, Window Size, Context Length — Measured area 35.699% · moving frames 23/23Original by GODRICH · SCSS and React ship in the zip · See the password
A hash instead of an embedding
The panel's one genuinely odd move is filling a gauge from the key itself with no embedding and no model — the classic string fold, whose output lands in the gauge band so two different keys give two stably different fills, while the last two gauges are honest fractions: 5 / 8 for a window of five out of eight turns, and 0.72 echoing scene 04's decay alpha. On the real node, the Context Window Length setting on Window Buffer Memory plays exactly the role the third gauge counts — it fixes how many recent turns survive into the prompt, as a plain setting value with no curve behind it.
// keyHash — fold character codes into a 0-1 gauge fill (string -> address)
function keyHash(s) {
let h = 0;
for (let c = 0; c < s.length; c += 1) { h = (h * 31 + s.charCodeAt(c)) % 997; }
return h / 997;
}
const vals = [keyHash('sessionId') * 0.6 + 0.4, keyHash('user-42') * 0.5 + 0.45, 5 / 8, 0.72];
03The JSON diff of a memory read and a write
Before and after panels of the serialized memory (a messages array) scroll while changed lines light up with the diff class, a shallow comparison computes added and modified lines, and a changed-n badge totals them — one turn appends a line to the array while a read returns the whole array as context, and that write/read asymmetry is what this scene makes visible in data.

<main class="stage">
<div class="ez is-demo" id="ez">
<div class="ez__in" data-role="inner">
<div class="ez__pad" data-role="pad" tabindex="0" role="application" aria-label="Demo stage — Space or Enter to pause, R to restart, left/right arrows for other values">
<div class="ez__scene" data-role="scene" role="img" aria-label="One turn appending a line to the messages array versus a read returning the whole array"></div>
<div class="ez__probe" data-role="probe" aria-hidden="true"></div>
<div class="ez__chart" data-role="chart" aria-hidden="true"></div>
<p class="ez__status" data-role="status" aria-live="off">Scene ready</p>
<p class="ez__reada" data-role="reada" aria-hidden="true"></p>
<p class="ez__readb" data-role="readb" aria-hidden="true"></p>
<div class="ez__ctrl">
<button class="ez__pause" data-role="pause" type="button" aria-pressed="false">Pause</button>
… (총 18줄 — 아래 「전체 코드」에서 원문 전체)// 533 공통 — n8n AI 에이전트 메모리 (532 base.scss 계승: 노드 그래프 요소에 메모리 슬롯·세션 배지·히트맵 셀을 얹는다)
@use "../../../../site/static/demo-tokens" as *;
@include stage($subject-cream);
$panel: mix($subject-cream, $subject-ink, 88%);
$dim: #6d675f; // mix(cream,ink,45%)#7f7a76 은 크림 위 3.98:1 로 미달 — 한 단계 내려 5.25:1
// 파스텔 액센트 — vivid 토큰 대신 (BD26)
$stroke-blue: #d5daea;
$stroke-rose: #ebd6db;
$stroke-mint: #8fd8bd;
$stroke-lilac: #c9b8f2;
… (총 623줄 — 아래 「전체 코드」에서 원문 전체)html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #fff7e6;
… (총 809줄 — 아래 「전체 코드」에서 원문 전체)(function () {
const rootEl = document.getElementById("ez");
if (!rootEl) return;
main(rootEl);
function cx(s) { return s; }
function main(root) {
// ── 533 공통 엔진 — 532 run() 시계 계승 (WAAPI 시계읽기·pause·rebuild·reduced 분기)
const W = 480;
const CX0 = 8;
const CW = 432;
function clamp(v, lo, hi) { return v < lo ? lo : (v > hi ? hi : v); }
function lerp(a, b, k) { return a + (b - a) * k; }
… (총 325줄 — 아래 「전체 코드」에서 원문 전체)// TurnWriteDiff - 같은 항목 vanilla index.html 의 React 판. 같은 계산을 useEffect 안에서 돌린다
import { useEffect, useRef } from "react";
import styles from "./TurnWriteDiff.module.scss";
const cx = (s: string): string => s.split(" ").map((n) => (styles as Record<string, string>)[n] ?? n).join(" ");
function main(root: HTMLElement): (() => void) | undefined {
// ── 533 공통 엔진 — 532 run() 시계 계승 (WAAPI 시계읽기·pause·rebuild·reduced 분기)
const W = 480;
const CX0 = 8;
const CW = 432;
function clamp(v: number, lo: number, hi: number): number { return v < lo ? lo : (v > hi ? hi : v); }
… (총 352줄 — 아래 「전체 코드」에서 원문 전체)03 · The JSON Diff of a Memory Read and Write — Measured area 35.94% · moving frames 23/23Original by GODRICH · SCSS and React ship in the zip · See the password
One write is one line; one read is the whole array
The serializer builds both panels from the same message list with the one extra line the write added as their only difference, and one write moves one line with the badge counting it — the diff class lights the appended line and the changed badge reads that same counter, the write small and the read the whole array, which is the arithmetic reason a memory window exists at all. When you debug a real agent this is the panel to recreate — serialize the memory sub-node's payload before and after a turn, and the diff tells you whether the agent wrote or only read.
// shallowLines — serialize the messages array; `extra` is the one new line
function shallowLines(arr, extra) {
const out = ['{', ' "messages": ['];
for (let k = 0; k < arr.length; k += 1) {
out.push(' "' + arr[k][0].slice(0, 20) + '"');
out.push(' "' + arr[k][1].slice(0, 20) + '"');
}
if (extra) { out.push(' "' + extra.slice(0, 20) + '"'); }
out.push(' ]');
out.push('}');
return out;
}
04How memory slots fill and slide: window size and exponential decay
Six vertical slots fill by each turn's token height, and once the total crosses the budget the oldest slots decay as height × DECAY_ALPHA(0.72)^k, evicted slots dropping to zero fill with a dashed outline left behind — the recomputed total never crosses the budget line, showing how window memory fills and pushes old turns out, with numbers you can re-derive.

<main class="stage">
<div class="ez is-demo" id="ez">
<div class="ez__in" data-role="inner">
<div class="ez__pad" data-role="pad" tabindex="0" role="application" aria-label="Demo stage — Space or Enter to pause, R to restart, left/right arrows for other values">
<div class="ez__scene" data-role="scene" role="img" aria-label="Six slots filling with turn tokens, oldest slots decaying past the budget"></div>
<div class="ez__probe" data-role="probe" aria-hidden="true"></div>
<div class="ez__chart" data-role="chart" aria-hidden="true"></div>
<p class="ez__status" data-role="status" aria-live="off">Scene ready</p>
<p class="ez__reada" data-role="reada" aria-hidden="true"></p>
<p class="ez__readb" data-role="readb" aria-hidden="true"></p>
<div class="ez__ctrl">
<button class="ez__pause" data-role="pause" type="button" aria-pressed="false">Pause</button>
… (총 18줄 — 아래 「전체 코드」에서 원문 전체)// 533 공통 — n8n AI 에이전트 메모리 (532 base.scss 계승: 노드 그래프 요소에 메모리 슬롯·세션 배지·히트맵 셀을 얹는다)
@use "../../../../site/static/demo-tokens" as *;
@include stage($subject-cream);
$panel: mix($subject-cream, $subject-ink, 88%);
$dim: #6d675f; // mix(cream,ink,45%)#7f7a76 은 크림 위 3.98:1 로 미달 — 한 단계 내려 5.25:1
// 파스텔 액센트 — vivid 토큰 대신 (BD26)
$stroke-blue: #d5daea;
$stroke-rose: #ebd6db;
$stroke-mint: #8fd8bd;
$stroke-lilac: #c9b8f2;
… (총 623줄 — 아래 「전체 코드」에서 원문 전체)html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #fff7e6;
… (총 809줄 — 아래 「전체 코드」에서 원문 전체)(function () {
const rootEl = document.getElementById("ez");
if (!rootEl) return;
main(rootEl);
function cx(s) { return s; }
function main(root) {
// ── 533 공통 엔진 — 532 run() 시계 계승 (WAAPI 시계읽기·pause·rebuild·reduced 분기)
const W = 480;
const CX0 = 8;
const CW = 432;
function clamp(v, lo, hi) { return v < lo ? lo : (v > hi ? hi : v); }
function lerp(a, b, k) { return a + (b - a) * k; }
… (총 314줄 — 아래 「전체 코드」에서 원문 전체)// SlotWindowDecay - 같은 항목 vanilla index.html 의 React 판. 같은 계산을 useEffect 안에서 돌린다
import { useEffect, useRef } from "react";
import styles from "./SlotWindowDecay.module.scss";
const cx = (s: string): string => s.split(" ").map((n) => (styles as Record<string, string>)[n] ?? n).join(" ");
function main(root: HTMLElement): (() => void) | undefined {
// ── 533 공통 엔진 — 532 run() 시계 계승 (WAAPI 시계읽기·pause·rebuild·reduced 분기)
const W = 480;
const CX0 = 8;
const CW = 432;
function clamp(v: number, lo: number, hi: number): number { return v < lo ? lo : (v > hi ? hi : v); }
… (총 341줄 — 아래 「전체 코드」에서 원문 전체)04 · Slot Fill and Slide: Window Size and Exponential Decay — Measured area 35.412% · moving frames 23/23Original by GODRICH · SCSS and React ship in the zip · See the password
The decay arithmetic, checked turn by turn
The turn heights [64, 56, 72, 68, 76, 70] total 406 against a budget of 360, and the loop in memDecay decays the oldest turn first, then the next, until the total fits — turn 1 becomes 64 × 0.72 = 46.1 (total 388.1), turn 2 becomes 56 × 0.72 = 40.3 (total 361.1), turn 3 becomes 72 × 0.72 = 51.8 (total 316.0 ≤ 360), stop, three turns decayed, exactly the values the bars below the budget line show. Two things the scene refuses to fake — the total is recomputed after every decay step rather than estimated, and the budget line sits at a pixel height drawn from the same 360 the loop guard reads — while n8n's Window Buffer Memory keeps the last N turns by count rather than by a curve, this scene's alpha arithmetic being an educational approximation of the same pressure, old context yielding to new, expressed as budget math instead of a count cut.
const DECAY_ALPHA = 0.72;
const H04 = [64, 56, 72, 68, 76, 70]; // turn token heights (total 406 — decay fires when turn 4's 68 crosses the 360 budget)
let k = 0;
let idx = 0;
while (total > budget && idx < out.length) {
out[idx] = heights[idx] * Math.pow(alpha, k + 1);
total = 0;
for (let i = 0; i < out.length; i += 1) { total += out[i]; }
k += 1;
idx += 1;
}
05Which turns get promoted to long-term memory: recurrence and the threshold
Each topic turn's recurrence climbs a vertical gauge, and only turns reaching PROMOTE_N(3) fire a promotion arrow into the long-term area while sub-threshold turns vanish under window decay and promoted turns persist without it — recurrence is decided by token overlap, Jaccard 0.34 or more counting as the same topic returning, so the promotion rule is two constants and one fraction.

<main class="stage">
<div class="ez is-demo" id="ez">
<div class="ez__in" data-role="inner">
<div class="ez__pad" data-role="pad" tabindex="0" role="application" aria-label="Demo stage — Space or Enter to pause, R to restart, left/right arrows for other values">
<div class="ez__scene" data-role="scene" role="img" aria-label="Recurrence gauges rising; only topics reaching the threshold are promoted to long-term memory"></div>
<div class="ez__probe" data-role="probe" aria-hidden="true"></div>
<div class="ez__chart" data-role="chart" aria-hidden="true"></div>
<p class="ez__status" data-role="status" aria-live="off">Scene ready</p>
<p class="ez__reada" data-role="reada" aria-hidden="true"></p>
<p class="ez__readb" data-role="readb" aria-hidden="true"></p>
<div class="ez__ctrl">
<button class="ez__pause" data-role="pause" type="button" aria-pressed="false">Pause</button>
… (총 18줄 — 아래 「전체 코드」에서 원문 전체)// 533 공통 — n8n AI 에이전트 메모리 (532 base.scss 계승: 노드 그래프 요소에 메모리 슬롯·세션 배지·히트맵 셀을 얹는다)
@use "../../../../site/static/demo-tokens" as *;
@include stage($subject-cream);
$panel: mix($subject-cream, $subject-ink, 88%);
$dim: #6d675f; // mix(cream,ink,45%)#7f7a76 은 크림 위 3.98:1 로 미달 — 한 단계 내려 5.25:1
// 파스텔 액센트 — vivid 토큰 대신 (BD26)
$stroke-blue: #d5daea;
$stroke-rose: #ebd6db;
$stroke-mint: #8fd8bd;
$stroke-lilac: #c9b8f2;
… (총 623줄 — 아래 「전체 코드」에서 원문 전체)html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #fff7e6;
… (총 809줄 — 아래 「전체 코드」에서 원문 전체)(function () {
const rootEl = document.getElementById("ez");
if (!rootEl) return;
main(rootEl);
function cx(s) { return s; }
function main(root) {
// ── 533 공통 엔진 — 532 run() 시계 계승 (WAAPI 시계읽기·pause·rebuild·reduced 분기)
const W = 480;
const CX0 = 8;
const CW = 432;
function clamp(v, lo, hi) { return v < lo ? lo : (v > hi ? hi : v); }
function lerp(a, b, k) { return a + (b - a) * k; }
… (총 331줄 — 아래 「전체 코드」에서 원문 전체)// PromoteLongterm - 같은 항목 vanilla index.html 의 React 판. 같은 계산을 useEffect 안에서 돌린다
import { useEffect, useRef } from "react";
import styles from "./PromoteLongterm.module.scss";
const cx = (s: string): string => s.split(" ").map((n) => (styles as Record<string, string>)[n] ?? n).join(" ");
function main(root: HTMLElement): (() => void) | undefined {
// ── 533 공통 엔진 — 532 run() 시계 계승 (WAAPI 시계읽기·pause·rebuild·reduced 분기)
const W = 480;
const CX0 = 8;
const CW = 432;
function clamp(v: number, lo: number, hi: number): number { return v < lo ? lo : (v > hi ? hi : v); }
… (총 358줄 — 아래 「전체 코드」에서 원문 전체)05 · Long-Term Promotion: Recurrence Threshold and the Promotion Arrow — Measured area 32.451% · moving frames 23/23Original by GODRICH · SCSS and React ship in the zip · See the password
Three topics, one threshold, one arrow
The scene tracks three topics with seen counts 3, 2 and 1, and only the first reaches the threshold, so only it fires the arrow — a single comparison, with the gauge text seen n/3 displaying the same counter the comparison reads, while the recurrence judgment behind the counts is the jac function from the engine layer (intersection tokens over union tokens, 0.34 as the same-topic line), a topic crossing it three times surviving in the long-term area while its sub-threshold neighbors decay away in scene 04, one system seen from the window side and the lifetime side. Since n8n ships no promote-after-recurrence setting on its memory sub-nodes, that production behavior lives in your own layer between the agent and the memory node, this scene being the blueprint for its arithmetic — the arrow, the threshold and the counter all reproducible in a dozen lines.
// Recurrence gauges — only seen >= PROMOTE_N fires the promotion arrow
const PROMOTE_N = 3;
const TOPICS05 = [
['report draft structure', ['report', 'draft', 'structure']],
['cost calculation', ['cost', 'calc']],
['translation tone tuning', ['translate', 'tone']]
];
// ...
const promoted = now >= PROMOTE_N;
ltm05[k].style.height = promoted ? '18px' : '0px';
06How dedupe merges same questions by Levenshtein distance
Levenshtein distance between an incoming question and stored ones decides sameness at a threshold of six or less, the distance matrix renders as a heatmap, merged pairs get a connector, and only the slot count rises while rows stop growing — memory saving proven by the math rather than asserted. This is the judgment for a chat that repeats itself; it is not a topic similarity engine, which is scene 05's Jaccard job.

<main class="stage">
<div class="ez is-demo" id="ez">
<div class="ez__in" data-role="inner">
<div class="ez__pad" data-role="pad" tabindex="0" role="application" aria-label="Demo stage — Space or Enter to pause, R to restart, left/right arrows for other values">
<div class="ez__scene" data-role="scene" role="img" aria-label="An edit-distance heatmap drawing; questions within the threshold merge into one"></div>
<div class="ez__probe" data-role="probe" aria-hidden="true"></div>
<div class="ez__chart" data-role="chart" aria-hidden="true"></div>
<p class="ez__status" data-role="status" aria-live="off">Scene ready</p>
<p class="ez__reada" data-role="reada" aria-hidden="true"></p>
<p class="ez__readb" data-role="readb" aria-hidden="true"></p>
<div class="ez__ctrl">
<button class="ez__pause" data-role="pause" type="button" aria-pressed="false">Pause</button>
… (총 18줄 — 아래 「전체 코드」에서 원문 전체)// 533 공통 — n8n AI 에이전트 메모리 (532 base.scss 계승: 노드 그래프 요소에 메모리 슬롯·세션 배지·히트맵 셀을 얹는다)
@use "../../../../site/static/demo-tokens" as *;
@include stage($subject-cream);
$panel: mix($subject-cream, $subject-ink, 88%);
$dim: #6d675f; // mix(cream,ink,45%)#7f7a76 은 크림 위 3.98:1 로 미달 — 한 단계 내려 5.25:1
// 파스텔 액센트 — vivid 토큰 대신 (BD26)
$stroke-blue: #d5daea;
$stroke-rose: #ebd6db;
$stroke-mint: #8fd8bd;
$stroke-lilac: #c9b8f2;
… (총 623줄 — 아래 「전체 코드」에서 원문 전체)html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #fff7e6;
… (총 809줄 — 아래 「전체 코드」에서 원문 전체)(function () {
const rootEl = document.getElementById("ez");
if (!rootEl) return;
main(rootEl);
function cx(s) { return s; }
function main(root) {
// ── 533 공통 엔진 — 532 run() 시계 계승 (WAAPI 시계읽기·pause·rebuild·reduced 분기)
const W = 480;
const CX0 = 8;
const CW = 432;
function clamp(v, lo, hi) { return v < lo ? lo : (v > hi ? hi : v); }
function lerp(a, b, k) { return a + (b - a) * k; }
… (총 329줄 — 아래 「전체 코드」에서 원문 전체)// DedupeLevenshtein - 같은 항목 vanilla index.html 의 React 판. 같은 계산을 useEffect 안에서 돌린다
import { useEffect, useRef } from "react";
import styles from "./DedupeLevenshtein.module.scss";
const cx = (s: string): string => s.split(" ").map((n) => (styles as Record<string, string>)[n] ?? n).join(" ");
function main(root: HTMLElement): (() => void) | undefined {
// ── 533 공통 엔진 — 532 run() 시계 계승 (WAAPI 시계읽기·pause·rebuild·reduced 분기)
const W = 480;
const CX0 = 8;
const CW = 432;
function clamp(v: number, lo: number, hi: number): number { return v < lo ? lo : (v > hi ? hi : v); }
… (총 356줄 — 아래 「전체 코드」에서 원문 전체)06 · Dedupe: Merging Same Questions by Levenshtein Distance — Measured area 28.4% · moving frames 23/23Original by GODRICH · SCSS and React ship in the zip · See the password
Three pairs, three distances, three verdicts
The stored variants arrive as constants with the verdicts computed by levDist at run time, and the fact sheet's full checks read: inserting one particle ("비용 계산해 줘" vs "비용을 계산해 줘") is distance 1, swapping one verb ("보고 초안 잡아 줘" vs "보고 초안 만들어 줘") is three edits, and rewording a request ("번역 톤 맞춰 줘" vs "번역해 줘") is five — all at or under the threshold 6, so all three merge, with the heatmap color encoding the distance while the number outside each cell states it, the connector line on a merged pair the visual receipt of that arithmetic, and the row count staying flat across presets the memory the merge saved.
// DEDUPE_T — edit distance at or under 6 counts as the same question
const DEDUPE_T = 6;
const Q06 = [
['draft the report', 'make a report draft', 2],
['calculate the cost', 'calculate the cost', 1],
['translate this', 'summarize this', 2]
];
07When summary compression kicks in: budget overflow and the ratio
When stacked turn-token bars cross the budget (360), the oldest group folds into one summary bar whose surviving height COMPRESS_KEEP(0.55) sets — the folded tokens keep 55 percent, the recomputed total adds a 12-token summary overhead, and the overflow decides how many turns fold, with the overhead token being the detail most summaries hide.

<main class="stage">
<div class="ez is-demo" id="ez">
<div class="ez__in" data-role="inner">
<div class="ez__pad" data-role="pad" tabindex="0" role="application" aria-label="Demo stage — Space or Enter to pause, R to restart, left/right arrows for other values">
<div class="ez__scene" data-role="scene" role="img" aria-label="Over-budget turn bars folding into one summary bar while the total recomputes"></div>
<div class="ez__probe" data-role="probe" aria-hidden="true"></div>
<div class="ez__chart" data-role="chart" aria-hidden="true"></div>
<p class="ez__status" data-role="status" aria-live="off">Scene ready</p>
<p class="ez__reada" data-role="reada" aria-hidden="true"></p>
<p class="ez__readb" data-role="readb" aria-hidden="true"></p>
<div class="ez__ctrl">
<button class="ez__pause" data-role="pause" type="button" aria-pressed="false">Pause</button>
… (총 18줄 — 아래 「전체 코드」에서 원문 전체)// 533 공통 — n8n AI 에이전트 메모리 (532 base.scss 계승: 노드 그래프 요소에 메모리 슬롯·세션 배지·히트맵 셀을 얹는다)
@use "../../../../site/static/demo-tokens" as *;
@include stage($subject-cream);
$panel: mix($subject-cream, $subject-ink, 88%);
$dim: #6d675f; // mix(cream,ink,45%)#7f7a76 은 크림 위 3.98:1 로 미달 — 한 단계 내려 5.25:1
// 파스텔 액센트 — vivid 토큰 대신 (BD26)
$stroke-blue: #d5daea;
$stroke-rose: #ebd6db;
$stroke-mint: #8fd8bd;
$stroke-lilac: #c9b8f2;
… (총 623줄 — 아래 「전체 코드」에서 원문 전체)html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #fff7e6;
… (총 809줄 — 아래 「전체 코드」에서 원문 전체)(function () {
const rootEl = document.getElementById("ez");
if (!rootEl) return;
main(rootEl);
function cx(s) { return s; }
function main(root) {
// ── 533 공통 엔진 — 532 run() 시계 계승 (WAAPI 시계읽기·pause·rebuild·reduced 분기)
const W = 480;
const CX0 = 8;
const CW = 432;
function clamp(v, lo, hi) { return v < lo ? lo : (v > hi ? hi : v); }
function lerp(a, b, k) { return a + (b - a) * k; }
… (총 344줄 — 아래 「전체 코드」에서 원문 전체)// SummaryCompressBudget - 같은 항목 vanilla index.html 의 React 판. 같은 계산을 useEffect 안에서 돌린다
import { useEffect, useRef } from "react";
import styles from "./SummaryCompressBudget.module.scss";
const cx = (s: string): string => s.split(" ").map((n) => (styles as Record<string, string>)[n] ?? n).join(" ");
function main(root: HTMLElement): (() => void) | undefined {
// ── 533 공통 엔진 — 532 run() 시계 계승 (WAAPI 시계읽기·pause·rebuild·reduced 분기)
const W = 480;
const CX0 = 8;
const CW = 432;
function clamp(v: number, lo: number, hi: number): number { return v < lo ? lo : (v > hi ? hi : v); }
… (총 371줄 — 아래 「전체 코드」에서 원문 전체)07 · Summary Compression: Budget Overflow and the Compression Ratio — Measured area 34.085% · moving frames 23/23Original by GODRICH · SCSS and React ship in the zip · See the password
The fold arithmetic, two steps and a stop
The turn tokens [64, 48, 72, 58, 66, 88] total 396 against the 360 budget, and folding runs the same recurrence as the source loop — fold the first turn, 396 − 64 + 64 × 0.55 + 12 = 379.2, still over; fold the second, 396 − 112 + 112 × 0.55 + 12 = 357.6 ≤ 360, stop, two turns summarized with one summary overhead of 12 tokens paid once. The ghosted bars at 0.45 opacity with the single summary bar rising in their place show the kept 55 percent plus that overhead at the pixel scale of scene 04's budget line — keeping 0.55 means discarding 0.45, the +12 overhead means a summary is not free, and the arithmetic admits both.
// Fold oldest turns into a summary until the rest fits the budget
let rest = raw;
let k = 0;
while (rest > 360 && k < shown - 1) {
folded += TURNS07[k];
rest = raw - folded + folded * COMPRESS_KEEP + 12;
k += 1;
}
total = rest;
08What clearing memory erases: the session switch boundary
A session-switch event wipes window slots top-down, each cell erasing on a computed 340ms segment, while long-term slots stay and a new session-ID badge takes the cleared place with the TTL counter resetting — one frame sorting what survives a clear from what does not, and the scene for what a clear actually touches (the write path belongs to scene 03).

<main class="stage">
<div class="ez is-demo" id="ez">
<div class="ez__in" data-role="inner">
<div class="ez__pad" data-role="pad" tabindex="0" role="application" aria-label="Demo stage — Space or Enter to pause, R to restart, left/right arrows for other values">
<div class="ez__scene" data-role="scene" role="img" aria-label="A session-switch event wiping window slots in order while long-term memory stays"></div>
<div class="ez__probe" data-role="probe" aria-hidden="true"></div>
<div class="ez__chart" data-role="chart" aria-hidden="true"></div>
<p class="ez__status" data-role="status" aria-live="off">Scene ready</p>
<p class="ez__reada" data-role="reada" aria-hidden="true"></p>
<p class="ez__readb" data-role="readb" aria-hidden="true"></p>
<div class="ez__ctrl">
<button class="ez__pause" data-role="pause" type="button" aria-pressed="false">Pause</button>
… (총 18줄 — 아래 「전체 코드」에서 원문 전체)// 533 공통 — n8n AI 에이전트 메모리 (532 base.scss 계승: 노드 그래프 요소에 메모리 슬롯·세션 배지·히트맵 셀을 얹는다)
@use "../../../../site/static/demo-tokens" as *;
@include stage($subject-cream);
$panel: mix($subject-cream, $subject-ink, 88%);
$dim: #6d675f; // mix(cream,ink,45%)#7f7a76 은 크림 위 3.98:1 로 미달 — 한 단계 내려 5.25:1
// 파스텔 액센트 — vivid 토큰 대신 (BD26)
$stroke-blue: #d5daea;
$stroke-rose: #ebd6db;
$stroke-mint: #8fd8bd;
$stroke-lilac: #c9b8f2;
… (총 623줄 — 아래 「전체 코드」에서 원문 전체)html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #fff7e6;
… (총 809줄 — 아래 「전체 코드」에서 원문 전체)(function () {
const rootEl = document.getElementById("ez");
if (!rootEl) return;
main(rootEl);
function cx(s) { return s; }
function main(root) {
// ── 533 공통 엔진 — 532 run() 시계 계승 (WAAPI 시계읽기·pause·rebuild·reduced 분기)
const W = 480;
const CX0 = 8;
const CW = 432;
function clamp(v, lo, hi) { return v < lo ? lo : (v > hi ? hi : v); }
function lerp(a, b, k) { return a + (b - a) * k; }
… (총 334줄 — 아래 「전체 코드」에서 원문 전체)// ClearSessionSwitch - 같은 항목 vanilla index.html 의 React 판. 같은 계산을 useEffect 안에서 돌린다
import { useEffect, useRef } from "react";
import styles from "./ClearSessionSwitch.module.scss";
const cx = (s: string): string => s.split(" ").map((n) => (styles as Record<string, string>)[n] ?? n).join(" ");
function main(root: HTMLElement): (() => void) | undefined {
// ── 533 공통 엔진 — 532 run() 시계 계승 (WAAPI 시계읽기·pause·rebuild·reduced 분기)
const W = 480;
const CX0 = 8;
const CW = 432;
function clamp(v: number, lo: number, hi: number): number { return v < lo ? lo : (v > hi ? hi : v); }
… (총 361줄 — 아래 「전체 코드」에서 원문 전체)08 · Clearing Memory: Session Switch and What Remains — Measured area 33.428% · moving frames 23/23Original by GODRICH · SCSS and React ship in the zip · See the password
Five cells, 340ms each, long-term untouched
The whole wipe is arithmetic from two constants — five window slots and one 340ms clear segment, so the full erase pass takes 1,700ms with the timeline marking both spans, the long-term slots to the right sitting outside the loop entirely while the label states the rule the code enforces: the session badge rewrites from sess-A to the next session and the TTL bar resets to full in the same frame, drawing the boundary the fact sheet warns about — a clear is keyed to the session, takes the window with it, and leaves the long-term area standing, exactly as in production where clearing a session's chat memory in n8n removes that session's buffered turns while anything your own layer promoted or stored outside the memory sub-node stays wherever you put it.
// Window slots 5 (wiped top to bottom); long-term slots survive the clear
// A new session badge appears and the TTL counter resets
const CELL_MS = 340 / 2000; // 340ms per cell, as a fraction of the cycle
// Window slots 5 (wiped top to bottom); long-term slots survive the clear
for (let k = 0; k < 5; k += 1) {
const sl = make('i', 'mslot', scWrap);
put(sl, 20 + k * 26, 30, 0, 0);
}
09When does a session restore — resume computed from turn count
Re-selecting the earlier session badge slides backed-up slots back to their places, the next new turn stacks on top of the restored slots, and restore travel is computed as restored turns × TURN_MS — 4 × 300 = 1,200ms — with a restored-n-turns badge leaving the receipt, the closing argument of the collection: the key that split conversations in scene 01 is the same key that brings this one back.

<main class="stage">
<div class="ez is-demo" id="ez">
<div class="ez__in" data-role="inner">
<div class="ez__pad" data-role="pad" tabindex="0" role="application" aria-label="Demo stage — Space or Enter to pause, R to restart, left/right arrows for other values">
<div class="ez__scene" data-role="scene" role="img" aria-label="Backed-up slots sliding back into place while a new turn stacks on top"></div>
<div class="ez__probe" data-role="probe" aria-hidden="true"></div>
<div class="ez__chart" data-role="chart" aria-hidden="true"></div>
<p class="ez__status" data-role="status" aria-live="off">Scene ready</p>
<p class="ez__reada" data-role="reada" aria-hidden="true"></p>
<p class="ez__readb" data-role="readb" aria-hidden="true"></p>
<div class="ez__ctrl">
<button class="ez__pause" data-role="pause" type="button" aria-pressed="false">Pause</button>
… (총 18줄 — 아래 「전체 코드」에서 원문 전체)// 533 공통 — n8n AI 에이전트 메모리 (532 base.scss 계승: 노드 그래프 요소에 메모리 슬롯·세션 배지·히트맵 셀을 얹는다)
@use "../../../../site/static/demo-tokens" as *;
@include stage($subject-cream);
$panel: mix($subject-cream, $subject-ink, 88%);
$dim: #6d675f; // mix(cream,ink,45%)#7f7a76 은 크림 위 3.98:1 로 미달 — 한 단계 내려 5.25:1
// 파스텔 액센트 — vivid 토큰 대신 (BD26)
$stroke-blue: #d5daea;
$stroke-rose: #ebd6db;
$stroke-mint: #8fd8bd;
$stroke-lilac: #c9b8f2;
… (총 623줄 — 아래 「전체 코드」에서 원문 전체)html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #fff7e6;
… (총 809줄 — 아래 「전체 코드」에서 원문 전체)(function () {
const rootEl = document.getElementById("ez");
if (!rootEl) return;
main(rootEl);
function cx(s) { return s; }
function main(root) {
// ── 533 공통 엔진 — 532 run() 시계 계승 (WAAPI 시계읽기·pause·rebuild·reduced 분기)
const W = 480;
const CX0 = 8;
const CW = 432;
function clamp(v, lo, hi) { return v < lo ? lo : (v > hi ? hi : v); }
function lerp(a, b, k) { return a + (b - a) * k; }
… (총 340줄 — 아래 「전체 코드」에서 원문 전체)// RestoreSessionResume - 같은 항목 vanilla index.html 의 React 판. 같은 계산을 useEffect 안에서 돌린다
import { useEffect, useRef } from "react";
import styles from "./RestoreSessionResume.module.scss";
const cx = (s: string): string => s.split(" ").map((n) => (styles as Record<string, string>)[n] ?? n).join(" ");
function main(root: HTMLElement): (() => void) | undefined {
// ── 533 공통 엔진 — 532 run() 시계 계승 (WAAPI 시계읽기·pause·rebuild·reduced 분기)
const W = 480;
const CX0 = 8;
const CW = 432;
function clamp(v: number, lo: number, hi: number): number { return v < lo ? lo : (v > hi ? hi : v); }
… (총 367줄 — 아래 「전체 코드」에서 원문 전체)09 · Session Restore: Returning to the Earlier Conversation and Continuing — Measured area 32.847% · moving frames 23/23Original by GODRICH · SCSS and React ship in the zip · See the password
The restore is a computed time, not a fade
Nothing in the scene fades in on a designer's whim — the four backup slots start in a 2×2 block on the right, travel to their ghost outlines on the left inside the computed window, and the badge counts them up as they land, the restored 4 turns badge at the end of the pass being the artifact proof the restore happened in the same way the changed-n badge proved the write in scene 03. Simple Memory's real-world counterpart is the same statement in fewer words: point the workflow back at the same Session ID and the conversation continues from where it left off, the key being the resume device with no other state required.
// RESTORE_N — four turns come back; resume = turns x TURN_MS
const TURN_MS = 300;
const RESTORE_N = 4;
// backup slots start in a 2x2 block and travel home inside the window
for (let k = 0; k < RESTORE_N; k += 1) {
const sl = make('i', 'rslot', scWrap);
put(sl, 0, 0, 40, 20);
sl.style.left = (300 + (k % 2) * 48) + 'px';
sl.style.top = (26 + Math.floor(k / 2) * 26) + 'px';
}
Where memory demos break: assumed permanence, unbounded slots, lossy summaries
The permanence assumption breaks on the budget
Window memory is not storage. In scene 04's no-decay arithmetic the total 406 stays 406 and every new turn pushes cost up linearly from there — the assumption that an agent remembers the whole conversation is the first trap, and the budget line crossing is the moment it breaks. The defense in a real system is the same one n8n's Window Buffer Memory ships: bound what reaches the prompt.
Unbounded slots turn repeats into a stack
Without the dedupe judgment, the same question asked again adds another row — scene 06's threshold is what stops the row count from growing while the counter climbs. The Levenshtein check at 6 is the border; loosen it to 10 and near-miss questions start merging, tighten it to 2 and true repeats slip through as new rows.
Summaries are lossy by ratio, and the overhead is real
Keeping 0.55 means losing 0.45 — numbers, names and qualifications live exactly in the part a summary drops, and the +12 overhead means even the kept part is not free. In scene 07's harder variant the keep drops to 0.3 and the same overflow still folds in two turns — 329.6 against 357.6 — but nearly half of what the 0.55 pass retained is gone. The password that unlocks this zip is ngj9cq4g, and inside are all nine scenes' index.html, style.scss and style.css plus the React builds, unchanged. One more time, the boundary from the top of this article: the node names and the Session ID mechanics follow the official documentation, but the decay alpha, the Jaccard and Levenshtein thresholds and the compression ratio are this demo's own arithmetic — an educational rule approximation of n8n ai agent memory, not an n8n execution.
The screens that need a memory view: agent dashboards, debuggers, teaching material
Three places these nine scenes genuinely belong. First, agent operations dashboards: scene 01's split routes plus scene 08's clear boundary put which session a turn belongs to and what a session switch erased on one screen. Second, debuggers: scene 03's before/after diff answers what one turn wrote, scene 06's heatmap catches the repeat-question pile-up at a glance, and scene 04's budget line tells you why old answers stopped being cited. Third, teaching material: scene 05's promotion arrow and scene 07's fold explain agent memory before any code is shown — the two lifetime questions people ask first. A team wiring real memory with a backend — the way n8n ai agent simple memory maps to Postgres Chat Memory or MongoDB Chat Memory on the canvas — can lift scene 02's panel as the settings checklist and scene 09 as the resume flow. The data plumbing starts at 9 n8n workflow examples, and the loop that consumes this memory is in the tool loop episode.
Moving into production means replacing string constants with real values: scene 01's turn script becomes your chat log, scene 03's serialized array becomes the memory sub-node's actual payload, scene 04's heights become your token counts — the calculation skeleton stays, the data turns real. If you lift a diagram for n8n ai agent documentation of your own, the first edit is fitting scene 04's heights and budget to your model's real context window, because 360 is a teaching number chosen to make the decay visible in six bars. Session state is verifiable in place — Space pauses, R rewinds, the arrow keys flip presets — so the scene doubles as a state check before anything goes on a real canvas.
Turn three values and the memory changes character
Three single-constant swaps — the math stays, and only the decay, the threshold, or the ratio moves.
| Name | Value swapped | What changes |
|---|---|---|
| Slower decay | s04 DECAY_ALPHA 0.72 → 0.88 | Old turn heights fall as e^(−0.12k) instead of e^(−0.28k) — the slide takes visibly longer, more turns survive the same 360 budget, and scene 07's compression fires later because the overflow arrives later |
| Lower threshold | s05 PROMOTE_N 3 → 2 | The second recurrence promotes straight to long-term — the arrow fires about twice as often and the long-term slots fill at the new speed, changing the first frame of the scene |
| Harder ratio | s07 COMPRESS_KEEP 0.55 → 0.3 | The kept share falls from 55% to 30% — the same overflow still folds in two turns (396 − 64 + 64 × 0.3 + 12 = 363.2, then 329.6 ≤ 360) but what survives the fold is nearly half of the 0.55 pass |
The first value governs the window's memory, the second the lifetime boundary, the third what a summary keeps. Move them together and you can no longer tell which change caused what, so when hunting a behavior, move one at a time. Every swap location is marked with a comment in the source itself.
Screen readers and reduced motion: the accessibility of memory
Slot state is never carried by color alone. Filled, decayed, evicted and promoted are distinguished by label and fill height as well — the seen n/3 counter, the dashed outline, the restored-n-turns badge — and aria-live stays off so a screen reader is not fed the whole slot list on every slide; only events like promotion and clearing are announced, through status roles. Pause is a real button operable from the keyboard, and Space, R and the arrow keys genuinely work.
@media (prefers-reduced-motion: reduce) {
.ez * { animation: none !important; transition: none !important; }
.ez__pause { transition: none !important; }
}
Under reduced motion the cycle is switched off and one finished frame remains — the decayed slot heights and the restored badge sit in the still, so the reader who opted out of motion loses no state. prefers-reduced-motion dates back to Chrome 74, Firefox 63 and Safari 10.1, so it drops in without compatibility worry. The palette is a pastel set over a cream ground, and the two session-badge colors measured for this episode — a deep blue on cream at 5.98:1 and a pastel lilac ink at 5.88:1 — both clear the 4.5:1 normal-text threshold, with the dim tone at 5.25:1.
Questions to settle before wiring agent memory
Does n8n ai agent memory session id behavior match this demo's routing?
The routing logic matches — same Session ID continues, different Session ID separates, exactly as scene 01 and scene 09 draw it, and that is Simple Memory's documented behavior. The numbers do not: the turn script, the 340ms spacing and the badge timing are this demo's own injected demonstration, and a live workflow's timing depends on your chat model and backend. Treat the routing as real and the clock as teaching material.
Is there a real n8n ai agent clear memory button for sessions?
The scenes model clearing as a session-switch event that wipes the window and spares the long-term area — that boundary is the demo's own rule approximation, drawn to teach what a clear should touch. In n8n the memory lives in the Memory sub-node you attached, and what a clear removes depends on that backend; scene 08 is the blueprint for asking the question of your own setup, not a recording of a specific button.
Are the decay, thresholds, and compression the same as real n8n?
No. Window Buffer Memory keeps the last N turns at its Context Window Length setting, as a plain count with no automatic decay curve; the alpha-0.72 decay, the Jaccard 0.34 recurrence line, the Levenshtein 6 dedupe threshold and the 0.55 compression ratio are this demo's educational arithmetic. The pressures they model are real — bounded context, repeated questions, lossy summaries — but the implementations live in the memory sub-node and the connected chat model, and their values will differ from these.
The next steps on the ai agent column run backward and forward from here: the loop that reads this memory every turn is the tool loop episode, the chat surface it serves started at ai chat streaming, and the data plumbing under all of it starts at 9 n8n workflow examples.









