An experiment in giving an AI agent a sleep cycle: a periodic consolidation pass that turns noisy, day-to-day working memory into a small set of durable, evidence-backed knowledge — instead of just letting raw logs accumulate forever.
I was digging into the memory layer of agentic AI systems — how an agent is supposed to retain, structure, and reuse what it learns across sessions — and kept running into the same failure mode: memory is either nothing (context resets every session) or it's a pile of raw logs and observations that grows without bound and gets harder to reason over the longer the agent runs.
Somewhere in there I stumbled on a question that felt obvious in hindsight: humans deal with exactly this problem every night. Sleep doesn't just pause the brain — it consolidates a day of noisy experience into something more useful (patterns, lessons, beliefs) and discards the rest. What if an agent could do something equivalent — replicate a sleep cycle to gain something useful about its own memory, instead of just accumulating it?
I wanted to run some actual demonstrations of that idea rather than just think about it. What I've arrived at so far is plain Markdown files — no vector DB, no graph DB, that's a later optimization and not a prerequisite — organized by memory type, transformed by a small pipeline of deterministic stages that periodically compresses raw observations into durable knowledge. It's a first working pass, judged against one invariant:
Every sleep cycle must leave the agent with less information but more usable knowledge.
.
├── memory/ the memory store itself — current state
│ ├── AGENTS.md what each folder below means, for any agent reading it
│ ├── working/ fast, disposable, drained every sleep cycle
│ ├── episodic/ one narrative file per day/session
│ ├── semantic/ durable beliefs, lessons, policies, reference facts
│ ├── predictions/ forward-looking claims + their track record
│ ├── archived/ cold storage — raw material, nothing deleted
│ └── sleep_logs/ an audit trail of every consolidation pass
└── sleep/ the consolidation pipeline itself, as skill files
├── AGENTS.md index + run order + concurrency notes
├── run_sleep_cycle.md the orchestrator — start here to run a cycle
└── clean_memory.md, cluster_events.md, extract_lessons.md,
verify_beliefs.md, merge_duplicates.md, summarize_episode.md,
evaluate_predictions.md, update_world_model.md, archive.md
Each file in sleep/ is one pipeline stage — input files, a transform,
a validation checklist, output files — designed to be small and
deterministic rather than one big open-ended prompt:
Load → Clean → Cluster → Extract → Verify → Consolidate → Predict → Archive
To exercise the pipeline against something concrete rather than testing it in the abstract, I modeled the memory of an AI agent acting as the COO of a logistics company — a day of realistic operational activity (driver shortages, port congestion, fleet decisions, client escalations) fed through the full cycle as mock observations.
-
26 files scaffolded across
memory/(15 files, 6 memory-type folders) andsleep/(11 files: 9 pipeline stages + 1 orchestrator + 1 index). -
One full sleep cycle run end to end (
sleep_001), against a day of mock COO-of-a-logistics-company observations, with every stage actually exercised — not just described:Stage Result Raw observations logged 23 lines After cleaning (dedup) 21 lines (2 near-duplicate pairs merged) After clustering 9 themes Lessons extracted 3 Beliefs seeded 1 ( mem_0001, confidence 0.55 — deliberately modest, single day of evidence)Policies promoted 0 (evidence cleared the bar, confidence didn't — correctly withheld) Working memory after archive 0 lines (fully drained) Full blow-by-blow in
memory/sleep_logs/sleep_001.md. The before/after row (23 raw lines → 0, whilesemantic/went from empty to 3 lessons + 1 belief) is the concrete evidence the core invariant held — not an assumption. -
A second day staged and ready to run (2026-07-29): 14 new observations, 2 active predictions (one due this run, one not — to test that unresolved predictions are correctly left alone), and 5 open tasks (most resolvable this run, one that should correctly stay open) — set up specifically to exercise the two stages cycle 1 didn't touch:
evaluate_predictions.mdand the task-draining half ofarchive.md.
Append what happened to memory/working/observations.md
(- [YYYY-MM-DD HH:MM] text per line), keep memory/working/active_tasks.md
current, and record anything forward-looking in
memory/predictions/active_predictions.md. This is the only file
maintenance the system requires day to day — everything else is produced
by the sleep cycle itself.
Point a coding agent (Claude Code or otherwise) at sleep/run_sleep_cycle.md
and have it follow that file. It's a self-contained runbook rather than a
registered tool or script: the agent reads it, then executes the 9 pipeline
stages in sleep/ in order, reading and writing the real files under
memory/ exactly as each stage specifies.
Each run produces a new memory/sleep_logs/sleep_NNN.md. A healthy cycle
shows working memory shrinking while semantic/, episodic/, and
predictions/ gain real content — the concrete check on the core invariant
above. A cycle that doesn't move those numbers should say so in the log,
not read as a success anyway.