Archive note: this post is a cleaned-up version of a WeChat Official Account (公众号) post from February 2026, preserving the original train of thought at the time. The early numbers in the original piece — token savings, retrieval accuracy, etc. — lack reproducible benchmarks and shouldn't be treated as verified conclusions. The current version of my personal site defers to the public repo, project pages, and the latest fact-check notes. View the original WeChat post

The original opening of this piece included a set of performance comparisons I used at the time to express the product vision, plus some exaggerated praise from a chatbot. None of that has reliable reproducible experiments behind it, so this cleaned-up version on my personal site drops it and keeps the main text starting from the real problem and the design process.

I. Why would a medical student build an AI memory system?

Background

I'm a third-year clinical medicine undergrad. I have no computer science background, and the implementation at the time was heavily AI-assisted — but I wanted to bring the logical thinking from my medical training into this problem. After all, the core of medical training is differential diagnosis: teasing apart a pile of symptoms to find the most likely cause.

Where the pain point came from

I'd been using OpenClaw as my AI assistant for the past few days. After a while, I noticed a fatal problem:

It can't remember things.

More precisely, it "remembers too much" while also "remembering it all wrong":

Which got me thinking: how does the human brain solve this problem?

II. Borrowing from neuroscience: three secrets of human memory

I dug through some neuroscience textbooks and papers (this part cost me roughly $30) and found a few key properties of the human memory system:

Secret 1: Layered storage

The human brain doesn't put all memories in one place:

Takeaway: AI memory should also be layered — you shouldn't cram everything into the prompt.

Secret 2: Memory consolidation

During sleep, the brain does something remarkable: it "tidies up" the day's short-term memories into long-term memory. This process is called consolidation.

Specifically:

Takeaway: AI also needs a "sleep tidy-up" mechanism to periodically sort through memory.

Secret 3: The forgetting curve

Ebbinghaus's forgetting curve tells us: memory decays over time, but at different rates.

Takeaway: AI memory should also carry "decay weights," so old, unimportant memories automatically lose priority.

III. Architecture design: three memory layers + automatic decay

Based on these neuroscience principles, I designed a three-layer memory architecture:

┌─────────────────────────────────────────────────────┐
│                 Layer 1: Working memory              │
│         (injected into every conversation,           │
│                  < 2000 tokens)                       │
│  ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐   │
│  │ Identity│ │  Owner  │ │Top Facts│ │ Recent  │   │
│  └─────────┘ └─────────┘ └─────────┘ └─────────┘   │
└─────────────────────────────────────────────────────┘
                          ▲
                          │ Retrieved on demand
                          ▼
┌─────────────────────────────────────────────────────┐
│            Layer 2: Structured long-term memory       │
│          (JSONL format, supports precise queries)     │
│  ┌──────────────┐ ┌──────────────┐ ┌────────────┐  │
│  │ facts.jsonl  │ │beliefs.jsonl │ │summaries.  │  │
│  │(confirmed    │ │(inferred     │ │   jsonl    │  │
│  │  facts)      │ │  beliefs)    │ │            │  │
│  └──────────────┘ └──────────────┘ └────────────┘  │
│                                                     │
│  ┌──────────────┐ ┌──────────────┐                 │
│  │   active/    │ │   archive/   │  ← Split into    │
│  │  (active     │ │  (archive    │    pools         │
│  │    pool)     │ │    pool)     │                 │
│  └──────────────┘ └──────────────┘                 │
└─────────────────────────────────────────────────────┘
                          ▲
                          │ Extracted via consolidation
                          ▼
┌─────────────────────────────────────────────────────┐
│              Layer 3: Raw event log                  │
│      (dual format: MD for humans + JSONL for          │
│                  machines)                            │
│  ┌────────────────────────────────────────────────┐ │
│  │ 2026-02-03.md / 2026-02-03.jsonl              │ │
│  │ 2026-02-04.md / 2026-02-04.jsonl              │ │
│  │ ...                                           │ │
│  └────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────┘

Core design decisions

Decision 1: Layer 1 strictly capped at 2000 tokens

Why 2000?

Decision 2: Distinguish Fact from Belief

This is one of the most important design decisions in the whole system.

Why does this matter?

The problem with traditional agents is that they treat their own "guesses" as "facts," which leads to hallucinations and mistakes.

With the Fact/Belief distinction, the agent can now say:

This is what Crabby called "metacognition" — the AI knowing what it "knows" versus what it's "unsure of."

Decision 3: Automatic decay mechanism

Different types of memory decay at different rates:

Decay formula:

New weight = Old weight × e^(-decay rate × days)

Which means:

IV. Consolidation: The AI's "sleep tidy-up"

This is the most complex and most valuable part of the whole system.

When does it trigger?

Cool-down period: 20 minutes with no messages + off-peak hours + no active conversation

Just like a person tidying up memories during sleep, the AI tidies up memory during "idle" time, without disrupting normal conversation.

The tidy-up process (7 phases)

Phase 1: Collect ──→ Phase 2: Filter ──→ Phase 3: Extract
    │                                      │
    │         ┌────────────────────────────┘
    │         ▼
    │    Phase 4: Classify
    │    ├─ 4a: Fact processing
    │    ├─ 4b: Belief verification
    │    └─ 4c: Summary generation
    │              │
    │              ▼
    │    Phase 5: Decay calculation
    │              │
    │              ▼
    │    Phase 6: Archive
    │              │
    │              ▼
    └───→ Phase 7: Snapshot generation ──→ Update Layer 1

Key phases, in detail

Phase 2: Filter (LLM judges value)

Not every conversation deserves to be remembered. At this stage, an LLM judges:

Input:
"The weather is nice today"
Output: {
"dominated":
true,
"reason":
"Small talk, no long-term value"
 }
Input:
"I have an important exam next Wednesday"
Output: {
"dominated":
false,
"reason":
"Time-sensitive event, needs to be remembered"
 }

Phase 4b: Belief verification

This is the core of "metacognition." For each Belief, the system:

Phase 7: Snapshot generation

Finally generates the Layer 1 snapshot, capped at 2000 tokens:

# Layer 1 Snapshot
## Identity
-
Name: Tkao
-
Role: Digital companion
## Owner
-
Name: Ktao
-
Context: Third-year clinical medicine undergrad
## Top Rankings (by importance)
1.
[Fact] User is developing an AI project (0.95)
2.
[Fact] User is interested in neuroscience (0.88)
3.
[Belief] User may be preparing for grad school entrance exams (0.65)
## Recent (last 24h)
-
Finished the Memory System v1.0 design
-
Discussed writing an open-source article

V. Technical implementation: a complete skill

In the end, I packaged this whole system into an OpenClaw Skill:

File structure

memory-system-skill/
├── SKILL.md
# Usage docs
├── scripts/
│   └── memory.py
# Core CLI (500+ lines of Python)
├── prompts/
│   ├── filter.md
# Phase 2 filter prompt
│   ├── extract.md
# Phase 3 extraction prompt
│   ├── verify_belief.md
# Phase 4b verification prompt
│   └── snapshot.md
# Phase 7 snapshot prompt
└── templates/
    └── config.json
# Default config

Core commands

# Initialize the memory system
python memory.py init
# Add a memory entry
python memory.py capture --
type
 fact --content
"User is a medical student"
 --confidence 0.95
# Run consolidation
python memory.py consolidate
# Check status
python memory.py status
# Generate a Layer 1 snapshot
python memory.py snapshot

VI. Cost retrospective: where did the $200 go?

Time breakdown across the 48 hours:

VII. Closing thoughts

What this project taught me

Open-source repo

GitHub: https://github.com/ktao732084-arch/openclaw_memory_supersystem-v1.0

Future plans

If you're also using OpenClaw, or you're interested in AI agent memory systems, feel free to reach out. And if you end up using this skill yourself — how would you adjust the forgetting rate and weight calculations for your own personal assistant?

I'm Ktao, someone trying to understand AI through a medical student's mindset.

Portrait of Zhang Yukui

Zhang Yukui / Ktao

Clinical medicine undergraduate. Medical student by day; the rest of the time I turn a real company's customer service, content, data and reporting into automation that runs every day.

Comments

0 / 200
Comments

Loading…