Skip to Content
Kokonut UI

AI-26AINew, October 21, 2026

AI Memory

An assistant that saves what it learns about you into a memory list. New facts replace the ones they contradict, and you can edit or forget any of them.

Install with
lucide-react, motion

Usage

Pass your saved memories as initialMemories and a remember that asks your model. It gets the message and the memories in the panel, and returns the reply plus, when there's something worth keeping, a memory to save (with replaces set to an older memory's id to update it). Return it as a Promise and the assistant shows it thinking until it resolves; throw and the reply shows the error's message. onSave, onEdit and onForget tell you what to persist; a forget only fires once its Undo has passed.

"use client";

import AIMemory, { type MemoryChange, type MemoryItem } from "@/components/kokonutui/ai-memory";

export function Assistant({ memories }: { memories: MemoryItem[] }) {
  return (
    <AIMemory
      greeting="Hi. What's new?"
      initialMemories={memories}
      onEdit={(memory) => fetch(`/api/memories/${memory.id}`, { method: "PUT", body: JSON.stringify(memory) })}
      onForget={(memory) => fetch(`/api/memories/${memory.id}`, { method: "DELETE" })}
      onSave={(memory, replaced) =>
        fetch("/api/memories", { method: "POST", body: JSON.stringify({ memory, replaces: replaced?.id }) })
      }
      remember={async (text, memories) => {
        const res = await fetch("/api/remember", {
          method: "POST",
          body: JSON.stringify({ text, memories }),
        });
        if (!res.ok) {
          throw new Error("Couldn't reach the model. Nothing was saved.");
        }
        return (await res.json()) as MemoryChange;
      }}
      suggestions={[]}
    />
  );
}
// app/api/remember/route.ts
import { anthropic } from "@ai-sdk/anthropic";
import { generateObject } from "ai";
import { z } from "zod";

export async function POST(req: Request) {
  const { text, memories } = await req.json();
  const { object } = await generateObject({
    model: anthropic("claude-sonnet-5-5"),
    schema: z.object({
      reply: z.string(),
      memory: z
        .object({ text: z.string(), group: z.string(), replaces: z.string().optional() })
        .optional(),
    }),
    system: `Reply briefly. Save a memory only for lasting facts about the user. Known: ${JSON.stringify(memories)}`,
    prompt: text,
  });
  return Response.json(object);
}

PROSlash Command Menu and more like it are in Kokonut UI Pro

Installation

AI Memory is a free, open-source React component in the Kokonut UI AI collection. Add it with the shadcn CLI, which copies the source into components/kokonutui/ai-memory.tsx, so the code is yours to change.

npx shadcn@latest add @kokonutui/ai-memory

Or add it by hand: install its packages, then copy the source from Copy code above into components/kokonutui/ai-memory.tsx.

npm install lucide-react motion

Props

title
stringDefault "Assistant"
greeting
stringDefault "Hi Samantha. What's new? Tell me anything and …

What the assistant opens with.

initialMemories
MemoryItem[]Default demo data

Your saved memories, read once on mount.

suggestions
string[]Default Object.keys(DEMO_REPLIES)

Messages offered as one-tap replies.

remember
(text: string, memories: MemoryItem[]) => MemoryChange | Promise<MemoryChange>Default demo data

Answers a message and decides what to remember, from the memories in the panel. Return the change or a Promise of it; the assistant shows it thinking until it resolves. Throw and the reply shows the error's message. Demo when omitted.

onSave
(memory: MemoryItem, replaced?: MemoryItem) => void

A memory was saved. With replaced, it took that one's place.

onEdit
(memory: MemoryItem) => void

A memory was edited by hand.

onForget
(memory: MemoryItem) => void

A memory was forgotten, once its Undo has passed.

className
string

Extra classes for the root element.

MemoryItem

idrequired
string
textrequired
string
grouprequired
string
savedrequired
string

When it was saved, in words, e.g. "Today" or "Sep 12".

MemoryChange

replyrequired
string
memory
{ text: string; group: string; replaces?: string }

A fact to save. With replaces, it takes the place of an older one.

Dependencies

NeedsVersionComes from
lucide-react^0.556.0npm, installed by the CLI
motion^12.23.25npm, installed by the CLI
cn from lib/utils.tsshadcn init
React19Your app
Tailwind CSS4Your app

No provider, font or global CSS to set up: the file works as soon as it lands.