Memory DAG Compactor

SkillDocs & knowledge

Builds hierarchical summary DAGs from MEMORY.md with depth-aware prompts, leaf summaries preserve detail, higher depths condense to durable arcs, preventing information loss during compaction.

Instructions available. Your AI can read the instructions. Execution depends on the setup they require.

Add ahel to your AI once: Claude, ChatGPT, Cursor, Claude Code or Codex. Then ask it to use this.

Then ask your AI: use the Memory DAG Compactor skill

What this skill tells your AI

The instructions your AI receives, as published by archieindian/openclaw-superpowers in skills/openclaw-native/memory-dag-compactor/SKILL.md and read by ahel’s review.

What it does

Standard memory compaction is lossy — older entries get truncated and details disappear forever. Memory DAG Compactor replaces flat compaction with a directed acyclic graph (DAG) of hierarchical summaries inspired by lossless-claw's Lossless Context Management approach.

Each depth in the DAG uses a purpose-built prompt tuned for that abstraction level:

DepthNameWhat it preservesTimeline granularity
d0LeafFile operations, timestamps, specific actions, errorsHours
d1CondensedWhat changed vs. previous context, decisions madeSessions
d2ArcGoal → outcome → carries forwardDays
d3+DurableLong-term context that survives weeks of inactivityDate ranges

The raw MEMORY.md entries are never deleted — only organized into a searchable, multi-level summary hierarchy.

When to invoke

  • Automatically nightly at 11pm (cron) — compacts the day's memory entries
  • When MEMORY.md grows beyond a configurable threshold (default: 200 entries)
  • Before a long-running task — ensures memory is compact and searchable
  • When the agent reports "I don't remember" for something that should be in memory

How to use

python3 compact.py --compact                      # Run leaf + condensation passes
python3 compact.py --compact --depth 0            # Only leaf summaries (d0)
python3 compact.py --compact --depth 2            # Condense up to d2 arcs
python3 compact.py --status                       # Show DAG stats and health
python3 compact.py --tree                         # Print the summary DAG as a tree
python3 compact.py --search "deployment issue"    # Search across all depths
python3 compact.py --inspect <summary-id>         # Show a summary with its children
python3 compact.py --dissolve <summary-id>        # Reverse a condensation
python3 compact.py --format json                  # Machine-readable output

Procedure

Step 1 — Run compaction

python3 compact.py --compact

The compactor:

  1. Reads all entries from MEMORY.md
  2. Groups entries into chunks (default: 20 entries per leaf)
  3. Generates d0 leaf summaries preserving operational detail
  4. When leaf count exceeds fanout (default: 5), condenses into d1 summaries
  5. Repeats condensation at each depth until DAG is within budget
  6. Writes the summary DAG to state

Step 2 — Search memory across depths

python3 compact.py --search "API migration"

Searches raw entries and all summary depths. Results ranked by relevance and depth — deeper summaries (d0) are more detailed, shallower (d3+) give the big picture.

Step 3 — Inspect and repair

python3 compact.py --tree             # Visualize the full DAG
python3 compact.py --inspect s-003    # Show summary with lineage
python3 compact.py --dissolve s-007   # Reverse a bad condensation

Depth-aware prompt design

d0 (Leaf) — Operational detail

Preserves: timestamps, file paths, commands run, error messages, specific values. Drops: conversational filler, repeated attempts, verbose tool output.

d1 (Condensed) — Session context

Preserves: what changed vs. previous state, decisions made and why, blockers encountered. Drops: per-file details, exact timestamps, intermediate steps.

d2 (Arc) — Goal-to-outcome arcs

Preserves: goal definition, final outcome, what carries forward, open questions. Drops: session-level detail, individual decisions, specific tools used.

d3+ (Durable) — Long-term context

Preserves: project identity, architectural decisions, user preferences, recurring patterns. Drops: anything that wouldn't matter after 2 weeks of inactivity.

Configuration

ParameterDefaultDescription
chunk_size20Entries per leaf summary
fanout5Max children before condensation triggers
max_depth4Maximum DAG depth
token_budget8000Target token count for assembled context

State

DAG structure, summary content, and lineage stored in ~/.openclaw/skill-state/memory-dag-compactor/state.yaml.

Fields: last_compact_at, dag_nodes, dag_edges, entry_count, compact_history.

Notes

  • Never modifies or deletes MEMORY.md — the DAG is an overlay
  • Each summary includes a [Expand for details about: ...] footer listing what was compressed
  • Dissolve reverses a condensation, restoring child summaries to the active set
  • Inspired by lossless-claw's DAG-based summarization hierarchy and depth-aware prompt system

Signals

GitHub stars
72
Forks
14
Last commit
May 2026
Advanced
Item type
skill
Key
memory-dag-compactor
Source
github.com/archieindian/openclaw-superpowers