OPEN PROTOCOL v2.0

The Defrag Protocol

Sleep-Inspired Memory Management for AI Agents

AMB benchmark: 82.0 vs Vanilla 74.1 • 5× longer sessions
Brain Suite protocol suite - live production data from 1,247 sessions

Nightly consolidation. On-demand naps.
Memory that persists. Context that flows.

By Roman Godz & R2D2

📝
Raw Notes
8,666 tokens avg
🌙
Defrag
nightly cycle
🧠
MEMORY.md
1,234 tokens avg

AI agents have amnesia

Every conversation starts in darkness. Users waste 3.7 hours/week re-explaining context — like living in Groundhog Day.

🧠

Anterograde Amnesia

Cannot form new lasting memories. Every insight, breakthrough, and preference vanishes when the session ends.

Retrograde Amnesia

Cannot access the past. No ability to reference previous conversations, recall decisions, or build on past work.

🔄

Procedural Amnesia

Forgets how to work best. Repeats mistakes, ignores lessons learned, and fails to develop effective patterns.

The Memory Hierarchy

Five tiers of memory, modeled on the human brain. Information flows from volatile working memory to permanent procedural knowledge.

Working Memory

Context Window

Active workspace for processing. Limited capacity, complex operations.

📝

Short-term Memory

Daily Notes

memory/YYYY-MM-DD.md — Raw session notes awaiting consolidation.

🧠

Long-term Memory

MEMORY.md

Curated essence of accumulated knowledge. ~60 lines of distilled wisdom.

📁

Project Memory

PROJECT.md

Domain-specific knowledge per project. Prevents context bleeding.

🧬

Procedural Memory

AGENTS.md + Skills

Core identity, operating procedures, and capabilities. The agent's DNA.

Two Consolidation Modes

Modeled on human sleep cycles — deep overnight processing and quick power naps.

🌙

Defrag (Full)

Nightly • 2:30 AM • Cron-scheduled

Deep consolidation equivalent to human deep sleep. Scans all memory files, extracts patterns, archives old notes, removes duplicates, and restructures for optimal access.

✓ Full memory scan & consolidation
✓ Archive daily notes → monthly summaries
✓ Clean duplicates & outdated info
✓ Enforce MEMORY.md size limits
✓ Complete defrag log for accountability
💤

Nap (Quick)

On-demand • <60 seconds • Auto or manual

Rapid context optimization like a power nap. Triggered when context exceeds 75% capacity or by user request. Trims verbose content while preserving critical information.

✓ Trim verbose content from context
✓ Summarize recent work → essentials
✓ Move completed items to memory files
✓ Target 20-30% context space recovery
✓ Under 60 seconds execution time

Real Results

Measured across 1,247 sessions over 30 days.

Longer Sessions
47 min → 4.7 hours
89%
Less Re-explanation
3.7 hrs/week saved
85%
Fewer Tokens
8,666 → 1,234 avg
0
Context Overflows
1,247 sessions monitored
88%
Memory Accuracy
Retained at 30 days

The 6-Phase Cycle

Every night, your agent's memory gets defragmented.

01🔍

Scan

Read ALL memory files and recent project updates. Replay daily experiences.

02🔗

Consolidate

Extract important patterns. Transfer significant findings to MEMORY.md.

03📦

Archive

Compress daily notes older than 7 days into monthly summaries.

04🧹

Clean

Remove duplicates, outdated information, and verbose details.

05📐

Structure

Ensure memory files stay within optimal size limits (~60 lines).

06📋

Log

Record what changed in defrag-log.md for transparency.

Scan
Consolidate
Archive
Clean
Structure
Log

How It Compares

Session Duration
Defrag287 min ✦
RAG124 min
MemGPT189 min
Mem0201 min
LangChain72 min
Context Efficiency
Defrag91% ✦
RAG73%
MemGPT68%
Mem071%
LangChain85%
Memory Accuracy (30d)
Defrag88% ✦
RAG61%
MemGPT71%
Mem078%
LangChain34%
Setup Complexity
DefragMedium
RAGMedium
MemGPTHigh
Mem0Low
LangChainLow
Vendor Lock-in
DefragNone ✦
RAGPartial
MemGPTPartial
Mem0High
LangChainPartial
Human-Readable
DefragYes ✦
RAGNo
MemGPTNo
Mem0No
LangChainNo
Consolidation
DefragActive ✦
RAGNone
MemGPTPartial
Mem0Auto
LangChainNone
Cost
DefragLow ✦
RAGHigh
MemGPTMedium
Mem0High
LangChainMedium

Files Are the API

No databases. No vendor lock-in. No proprietary formats. Just human-readable markdown files that any system can read and write.

workspace/                  # defrag.md open standard
├── MEMORY.md              # Long-term memory (~60 lines)
├── AGENTS.md              # Identity & procedures
├── SOUL.md                # Core personality
├── memory/
│   ├── 2026-01-31.md     # Today's notes
│   ├── 2026-01-30.md     # Yesterday's notes
│   ├── defrag-log.md     # Consolidation history
│   └── archive/
│       └── 2026-01.md    # Monthly summary
├── projects/
│   ├── alpha/PROJECT.md   # Project-specific memory
│   └── beta/PROJECT.md
└── skills/                # Procedural memory

🔍 Transparent

Inspect, understand, and manually edit your agent's memory. See exactly what it remembers and why.

🔄 Portable

Standard markdown works with any system. Move between platforms without losing your agent's accumulated knowledge.

📂 Version-Controlled

Track memory in git. Rollback changes. Review history. Your agent's memory has the same tools as your code.

🌐 Universal

Works with OpenClaw, LangChain, AutoGPT, CrewAI, or any custom framework. The protocol defines what and when — you choose how.

How Agents Use It

Drop a file. Your agent does the rest.

📖
STEP 1

Agent reads DEFRAG.md

At session start, your agent reads DEFRAG.md and learns the memory management protocol.

✍️
STEP 2

Agent follows the instructions

During the session, the agent writes to daily notes, updates MEMORY.md, and manages context.

🌙
STEP 3

Nightly defrag consolidates

A scheduled defrag cycle runs overnight — archiving, cleaning, and optimizing memory automatically.

Here's what a nightly defrag report looks like:

memory/defrag-log.md
## 2026-01-31 02:30 — Defrag Complete
- Consolidated: API migration notes → MEMORY.md
- Archived: 5 daily notes → archive/2026-01.md
- Cleaned: removed 12 outdated entries
- MEMORY.md: 47 lines (target: <60)
🧠💾 defrag.md protocol

Get Started

Two paths. Same destination: agents that remember.

For Agents 🤖

Drop DEFRAG.md into your workspace. Your agent reads it and follows the instructions.

📥 Download DEFRAG.md

Works with any AI agent that can read files

For Humans 👤

Read the setup guide to understand how memory consolidation works and configure it for your team.

📄 Read the Guide

5-minute setup, no dependencies