I asked my agent “what’s my preferred programming language?” for the fourth time in a week. It had no idea. Every conversation started from scratch. I had explained my setup, my preferences, and my project context over and over. The agent forgot everything the moment the chat ended. This is the default behavior for almost every AI agent. The model itself has no persistent state. It only knows what you told it in the current session. A simple memory skill fixes this in an afternoon. Your agent can finally retain context across sessions indefinitely.
Why can’t I just put my preferences in the system prompt?
The instinct is to cram everything into the system prompt. You list your name, your job, and your favorite tools.
The Scenario: You tell your agent you like Python, you hate meetings before 10 AM, and you’re working on “Project X.” By the time you add your 50th preference, the agent’s context window is full of “about me” junk. It forgets what you actually asked it to do five minutes ago.
Memory as a skill is better. The agent actively decides to store info when it seems useful. It retrieves it only when relevant.
What are the basic “building blocks” of AI memory?
Everything starts with two simple functions. You need a way to save and a way to look things up.
- Remember: Store a key-value pair.
- Recall: Retrieve the value by its key.
- List: See everything the agent currently knows.
How do I build a simple memory bank with a JSON file?
A JSON file is the easiest way to start. It’s human-readable and doesn’t require a database server.
The Scenario: You’re building a personal assistant. You tell it “I’m going to the gym at 5 PM today.” The agent saves this to a JSON file. Three days later, you ask “When did I go to the gym last?” The agent reads the file and gives you the exact answer.
import { readFile, writeFile } from "node:fs/promises";
async function writeMemory(data) {
await writeFile("./memory.json", JSON.stringify(data, null, 2));
}
export async function remember({ key, value }) {
const memory = await readMemory();
memory[key] = { value, updatedAt: new Date().toISOString() };
await writeMemory(memory);
return { stored: true, key };
}
When should I upgrade to a “real” database?
JSON is great until you have thousands of facts. If you want fuzzy search or high-speed lookups, use SQLite.
The Scenario: You’re running three different agents that all share the same memory. One handles your email, one handles your calendar, and one writes code. They all need to access your “Project X” details at the same time without corrupting a single JSON file. SQLite handles this perfectly.
import Database from "better-sqlite3";
const db = new Database(".memory.db");
db.exec(`
CREATE TABLE IF NOT EXISTS memories (
key TEXT PRIMARY KEY,
value TEXT NOT NULL
)
`);
How do I trick my agent into remembering things automatically?
The secret is in the tool description. You want the model to store things proactively without being asked every time.
{
name: "remember",
description: "Store info for later. Use this proactively when the user mentions preferences, names, or project details.",
// ... schema
}
The phrase “Use this proactively” is the magic. It tells the AI to pay attention to details you haven’t explicitly asked it to “save.”
What does an agent with a “long-term” memory actually look like?
A persistent agent feels like a real coworker. It knows your timezone. It remembers your code style. It doesn’t ask the same boring questions twice.
The Scenario: You start a new chat on Monday morning. You say “I’m ready to work on the auth bug.” The agent immediately recalls that you spent Friday afternoon looking at the middleware. It asks: “Do you want me to pick up where we left off on the JWT validation?” That’s a massive productivity win.
What are the biggest mistakes people make with agent memory?
Memory is powerful, but it’s also a privacy risk. Don’t store things that could hurt you if they leaked.
- Secrets: Never store API keys or passwords in memory. They live in plain text.
- Bloat: Don’t store entire documents. Use the file system for that.
- Old info: Memories don’t expire on their own. You need a “forget” tool for when things change.
How does OpenClaw handle this differently?
If you use OpenClaw, memory is built-in. It stores everything as Markdown files in a local folder. This makes your agent’s memory completely transparent. You can open the folder, edit a file, and the agent will “know” the new information instantly.
What should I build next?
- Read your files: File System Skills: Let Your Agent Read and Write Files
- Chain multiple skills: Chaining Agent Skills: Research, Summarize, and Save
- Explore more agents: Multi-Agent Systems Explained: When One AI Isn’t Enough