How to Add Persistent Memory to Your AI Agent


I spent a week wiring persistent memory into three different agents (Claude Code, a custom Python bot, and a Cursor setup). Here’s what I learned and the actual code that worked.

The problem

Every agent I’ve built hits the same wall: it forgets. You tell it “I use pnpm, not npm” on Monday, and by Wednesday it’s running npm install again. The usual fixes — stuffing a MEMORY.md into the system prompt, or growing a JSON file — work until they don’t. The file gets big, grep can’t find anything by meaning, and you’re burning tokens loading context you don’t need.

What I wanted: store facts, recall them by meaning (not keywords), and have it work across sessions without me managing any infrastructure.

Option 1: CLI (fastest)

If your agent can run shell commands, this is the simplest path.

npm install -g memoclaw
memoclaw init

That creates a config file and generates a wallet (or uses your existing one). Now your agent can do:

# Store something
memoclaw store "Ana prefers Railway for deployments, never Vercel"

# Later, in a different session entirely
memoclaw recall "where should I deploy this?"
# → "Ana prefers Railway for deployments, never Vercel" (score: 0.91)

The recall is semantic. It matched “where should I deploy” to a memory about Railway even though the words barely overlap. That’s the whole point — grep would have missed this.

Option 2: Python SDK

For custom agents where you want memory in your code:

pip install memoclaw
from memoclaw import MemoClaw

mc = MemoClaw()

# After your agent learns something important
mc.store(
    "User's production database is Postgres on Neon, staging is SQLite",
    tags=["infrastructure"],
    importance=0.8
)

# When your agent needs context
results = mc.recall("what database are we using?", limit=3)
for r in results:
    print(f"{r.text} (score: {r.score:.2f})")

I also use ingest() for processing bigger chunks. Say your agent just finished a meeting transcript — instead of manually picking out facts:

mc.ingest("""
Meeting notes Feb 10:
- Moving to Postgres on Neon for prod
- Ana handles the migration by Feb 20
- Budget approved for $500/mo on infrastructure
- Don't touch the legacy API until March
""")

This extracts each fact, deduplicates against what’s already stored, and creates connections between related memories. One call instead of parsing the text yourself.

Option 3: MCP (for Claude Desktop / Cursor / Windsurf)

npm install -g memoclaw-mcp

Add to your MCP config:

{
  "mcpServers": {
    "memoclaw": {
      "command": "memoclaw-mcp",
      "env": {
        "MEMOCLAW_PRIVATE_KEY": "your-wallet-private-key"
      }
    }
  }
}

Now your AI assistant has memoclaw_store, memoclaw_recall, memoclaw_ingest, and other tools available. It’ll use them when it makes sense — store when it learns something new, recall when it needs context.

What I actually store

After a week of using this across projects, here’s what ended up being worth storing:

  • Tool preferences (“uses pnpm”, “prefers Postgres”)
  • Project decisions (“chose Railway because of preview environments”)
  • Corrections (“NEVER use sudo for npm install on this machine”)
  • User context (“timezone UTC”, “works on memoclaw and openclaw repos”)
  • Session summaries (ingested at end of long sessions)

What wasn’t worth storing: transient debugging context, one-off questions, anything that changes daily.

Cost

Every wallet gets 100 free calls. After that, a store or recall costs $0.005. If you’re doing 50 stores and 50 recalls a day (which is a lot), that’s $0.50/day. The 17 non-embedding endpoints (list, delete, update, tags, etc.) are free forever.

If you want to try it: memoclaw init and you’re done. No signup, no email, no API key.