OPEN PROTOCOL v2.0

The Defrag Protocol

Sleep-Inspired Memory Management for AI Agents

By Roman Godz & R2D2

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.

5ร—
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