Agent memory
Assistant memory settings card with reference toggles, search, category filters, inline editing and one-click forget controls.
pnpm dlx shadcn@latest add @haze/agent-memory---
import { Brain, Check, Pencil, Search, Trash2 } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface MemoryItem {
id: string;
category: "About you" | "Preferences" | "Projects" | "People";
text: string;
saved: string;
}
interface Props {
id?: string;
title?: string;
items?: MemoryItem[];
class?: string;
}
const {
id = "haze-agent-memory",
title = "Assistant memory",
items = [
{ id: "mem-1", category: "Preferences", text: "Prefers TypeScript strict mode, pnpm workspaces and concise code reviews.", saved: "2 days ago" },
{ id: "mem-2", category: "Projects", text: "Building Haze UI, an Astro-first dark component library with zero React runtime.", saved: "5 days ago" },
{ id: "mem-3", category: "About you", text: "Based in CET timezone; ships weekly changelogs on Thursdays.", saved: "1 week ago" },
{ id: "mem-4", category: "People", text: "Design reviews go to Nina; infrastructure approvals go to Marco.", saved: "2 weeks ago" },
],
class: className,
} = Astro.props;
const categories = ["All", "About you", "Preferences", "Projects", "People"] as const;
---
<section aria-labelledby={`${id}-title`} data-haze-agent-memory class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}>
<div class="mx-auto max-w-3xl rounded-2xl border border-border bg-card p-5 sm:p-6">
<div class="flex flex-wrap items-center justify-between gap-3 border-b border-border pb-4">
<div class="flex items-center gap-2.5">
<span class="grid size-8 place-items-center rounded-lg border border-frame bg-muted text-muted-foreground" aria-hidden="true">
<Brain class="size-4" />
</span>
<div>
<h2 id={`${id}-title`} class="text-base/6 font-semibold tracking-tight text-foreground">{title}</h2>
<p class="text-xs/5 text-muted-foreground">Control what the assistant remembers across sessions.</p>
</div>
</div>
<span data-mem-count class="rounded-full border border-frame bg-muted/40 px-2.5 py-0.5 text-xs font-medium text-muted-foreground tabular-nums">{items.length} saved</span>
</div>
<div class="mt-4 grid gap-3 sm:grid-cols-2">
<label class="flex cursor-pointer items-center justify-between gap-3 rounded-xl border border-border bg-muted/40 px-3.5 py-2.5">
<span class="min-w-0">
<span class="block text-xs/5 font-medium text-foreground">Reference saved memories</span>
<span class="block text-[0.6875rem]/4 text-muted-foreground">Use facts listed below in new chats</span>
</span>
<span class="relative inline-grid size-4 shrink-0 place-items-center"><input type="checkbox" checked class="peer col-start-1 row-start-1 shrink-0 focus-visible:outline-2 focus-visible:outline-ring size-4 shrink-0 cursor-pointer appearance-none rounded-sm border border-border-strong bg-field transition-[background-color,border-color,scale] duration-150 ease-snappy hover:border-foreground active:scale-90 checked:border-primary checked:bg-primary focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring forced-colors:appearance-auto" /><Check class="pointer-events-none col-start-1 row-start-1 size-3 scale-50 text-primary-foreground opacity-0 transition-[opacity,scale] duration-200 ease-spring peer-checked:scale-100 peer-checked:opacity-100 forced-colors:hidden" stroke-width={3} aria-hidden="true" /></span>
</label>
<label class="flex cursor-pointer items-center justify-between gap-3 rounded-xl border border-border bg-muted/40 px-3.5 py-2.5">
<span class="min-w-0">
<span class="block text-xs/5 font-medium text-foreground">Search chat history</span>
<span class="block text-[0.6875rem]/4 text-muted-foreground">Recall decisions from recent threads</span>
</span>
<span class="relative inline-grid size-4 shrink-0 place-items-center"><input type="checkbox" checked class="peer col-start-1 row-start-1 shrink-0 focus-visible:outline-2 focus-visible:outline-ring size-4 shrink-0 cursor-pointer appearance-none rounded-sm border border-border-strong bg-field transition-[background-color,border-color,scale] duration-150 ease-snappy hover:border-foreground active:scale-90 checked:border-primary checked:bg-primary focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring forced-colors:appearance-auto" /><Check class="pointer-events-none col-start-1 row-start-1 size-3 scale-50 text-primary-foreground opacity-0 transition-[opacity,scale] duration-200 ease-spring peer-checked:scale-100 peer-checked:opacity-100 forced-colors:hidden" stroke-width={3} aria-hidden="true" /></span>
</label>
</div>
<div class="mt-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
<div class="relative flex-1">
<Search class="pointer-events-none absolute top-1/2 left-3 size-3.5 -translate-y-1/2 text-muted-foreground" aria-hidden="true" />
<label for={`${id}-search`} class="sr-only">Search memories</label>
<input id={`${id}-search`} data-mem-search type="search" placeholder="Search saved memories…" class="h-9 w-full rounded-lg border border-frame-input bg-field pr-3 pl-8 text-xs text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden transition-[color,background-color,border-color,box-shadow] duration-150 hover:border-frame-foreground" />
</div>
<div role="group" aria-label="Memory category" class="flex flex-wrap gap-1">
{
categories.map((cat, idx) => (
<button
type="button"
data-mem-cat={cat}
aria-pressed={idx === 0 ? "true" : "false"}
class="inline-flex h-8 cursor-pointer items-center rounded-lg border border-frame bg-field px-2.5 text-xs font-medium text-muted-foreground transition-colors duration-150 hover:text-foreground aria-pressed:border-border-strong aria-pressed:bg-accent aria-pressed:text-foreground focus-visible:outline-2 focus-visible:outline-ring active:scale-[0.97] active:duration-75"
>
{cat}
</button>
))
}
</div>
</div>
<ul role="list" data-mem-list class="mt-4 divide-y divide-border rounded-xl border border-border bg-muted/40">
{
items.map((item) => (
<li data-mem-row data-category={item.category} data-text={item.text.toLowerCase()} class="flex items-start justify-between gap-3 p-3.5">
<div class="min-w-0 flex-1">
<div class="flex items-center gap-2">
<span class="rounded-md border border-border bg-card px-2 py-0.5 text-[0.6875rem]/4 font-medium text-muted-foreground">{item.category}</span>
<span class="text-[0.6875rem]/4 text-muted-foreground">{item.saved}</span>
</div>
<p data-mem-body class="mt-1.5 text-sm/6 text-pretty text-foreground">{item.text}</p>
</div>
<div class="flex shrink-0 items-center gap-1">
<button type="button" data-mem-edit aria-label={`Edit memory: ${item.text}`} class="inline-flex size-8 cursor-pointer items-center justify-center rounded-lg text-muted-foreground hover:bg-accent hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">
<Pencil class="size-3.5" aria-hidden="true" />
</button>
<button type="button" data-mem-del aria-label={`Forget memory: ${item.text}`} class="inline-flex size-8 cursor-pointer items-center justify-center rounded-lg text-muted-foreground hover:bg-destructive/14 hover:text-destructive focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">
<Trash2 class="size-3.5" aria-hidden="true" />
</button>
</div>
</li>
))
}
</ul>
<p data-mem-status role="status" class="mt-3 min-h-4 text-xs/4 text-muted-foreground"></p>
</div>
</section>
<script>
function initAgentMemories() {
document.querySelectorAll<HTMLElement>("[data-haze-agent-memory]").forEach((root) => {
if (root.hasAttribute("data-enhanced")) return;
root.setAttribute("data-enhanced", "");
const search = root.querySelector<HTMLInputElement>("[data-mem-search]");
const count = root.querySelector<HTMLElement>("[data-mem-count]");
const status = root.querySelector<HTMLElement>("[data-mem-status]");
let activeCat = "All";
const filter = () => {
const q = (search?.value ?? "").trim().toLowerCase();
let total = 0;
root.querySelectorAll<HTMLElement>("[data-mem-row]").forEach((row) => {
total++;
const okCat = activeCat === "All" || row.dataset.category === activeCat;
const okText = !q || (row.dataset.text ?? "").includes(q);
row.hidden = !(okCat && okText);
});
if (count) count.textContent = `${total} saved`;
};
search?.addEventListener("input", filter);
root.querySelectorAll<HTMLButtonElement>("[data-mem-cat]").forEach((btn) => {
btn.addEventListener("click", () => {
activeCat = btn.dataset.memCat ?? "All";
root.querySelectorAll<HTMLButtonElement>("[data-mem-cat]").forEach((b) => b.setAttribute("aria-pressed", String(b === btn)));
filter();
});
});
root.querySelector<HTMLElement>("[data-mem-list]")?.addEventListener("click", (ev) => {
const target = ev.target as HTMLElement | null;
const del = target?.closest<HTMLButtonElement>("[data-mem-del]");
if (del) {
del.closest("[data-mem-row]")?.remove();
filter();
if (status) status.textContent = "Memory forgotten.";
return;
}
const edit = target?.closest<HTMLButtonElement>("[data-mem-edit]");
if (edit) {
const row = edit.closest<HTMLElement>("[data-mem-row]");
const body = row?.querySelector<HTMLElement>("[data-mem-body]");
if (!row || !body) return;
const editable = body.getAttribute("contenteditable") === "true";
if (!editable) {
body.setAttribute("contenteditable", "true");
body.classList.add("rounded-md", "bg-card", "px-2", "py-1", "border", "border-frame-input", "focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24", "outline-hidden");
body.focus();
if (status) status.textContent = "Editing memory. Press the edit button again to save.";
} else {
body.removeAttribute("contenteditable");
body.classList.remove("rounded-md", "bg-card", "px-2", "py-1", "border", "border-frame-input", "focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24", "outline-hidden");
row.dataset.text = (body.textContent ?? "").toLowerCase();
if (status) status.textContent = "Memory updated.";
}
}
});
});
}
initAgentMemories();
document.addEventListener("astro:page-load", initAgentMemories);
</script>When to use
- Giving users transparent control over facts an assistant remembers across chats
- Building a memory management screen with category filters and inline edit/delete
When not to use
- Managing general account toggles without searchable memory records; use switch or field
Installation
Add the Haze registry to components.json once, then install Agent memory with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/agent-memorynpx shadcn@latest add @haze/agent-memoryyarn dlx shadcn@latest add @haze/agent-memorybunx --bun shadcn@latest add @haze/agent-memoryFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | "haze-agent-memory" | Unique prefix for search label and heading IDs. |
| title | string | "Assistant memory" | Card heading. |
| items | MemoryItem[] | 4 demo memories | Saved memory records grouped by category. |
| class | string | – | Extra classes on the outer section. |
Keyboard interactions
- Tab
- Move across toggles, search input, category filters, and per-row edit/forget buttons
- EnterSpace
- Toggle settings, filter by category, edit a memory inline or forget it
Accessibility
- Memory preference switches use native checkboxes with visible titles and descriptions.
- Edit and Forget buttons include the memory summary in their aria-label and announce updates via role="status".
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI block "Agent memory" with `npx shadcn@latest add @haze/agent-memory`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import AgentMemory from "@/components/haze/blocks/agent-memory.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/blocks/agent-memory.md
Customize with real content
Adapt the Haze agent-memory block for our product. Replace the demo values of these props with our real content: id, title, items, class. Keep the layout, the heading level rules and these accessibility details: Memory preference switches use native checkboxes with visible titles and descriptions. Edit and Forget buttons include the memory summary in their aria-label and announce updates via role="status". Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using agent-memory, check it fits: use it when giving users transparent control over facts an assistant remembers across chats; building a memory management screen with category filters and inline edit/delete. Avoid it when managing general account toggles without searchable memory records; use switch or field. Alternatives: @haze/switch, @haze/inbox-list.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.