Memory Compression

Prevent context overflow with automatic session truncation and memory preservation. Never lose important conversations again. Features: token-based trimming,...

MIT-0 · Free to use, modify, and redistribute. No attribution required.
3 · 831 · 13 current installs · 13 all-time installs
MIT-0
Security Scan
VirusTotalVirusTotal
Benign
View report →
OpenClawOpenClaw
Benign
medium confidence
Purpose & Capability
Name/description (context compression, trimming, fact extraction) match the included scripts and declared file permissions: scripts read/write ~/.openclaw/agents/main/sessions/*.jsonl and workspace memory files. Required binaries are standard shell utilities appropriate for the task.
Instruction Scope
Instructions and scripts operate on session JSONL files and MEMORY.md (as advertised). One minor inconsistency: SKILL.md claims "No external network activity from scripts," but extract-facts-enhanced.sh invokes the local `openclaw agent` CLI to perform AI extraction; depending on your OpenClaw setup that agent call may contact a remote model provider (so network/model invocation is possible). Otherwise the scripts scope is limited to session trimming, fact extraction, and preference expiry handling.
Install Mechanism
Instruction-only skill with provided shell scripts—no install spec, no external downloads, and no archive extraction. Risk from install mechanism is low.
Credentials
No credentials or unrelated environment variables are required. Scripts optionally honor WORKSPACE/SESSIONS_DIR/LOG_FILE env vars; requested file read/write permissions align with the stated purpose. No extraneous secrets or cross-service credentials are requested.
Persistence & Privilege
Skill is not always:true and does not request system-wide or other-skills configuration changes. It modifies files under ~/.openclaw/workspace and sessions as expected for its purpose; this level of local file access is proportional to functionality.
Assessment
This skill is internally coherent with its purpose, but consider these practical privacy and safety points before installing: - The scripts will read full session JSONL files and write to MEMORY.md and logs; that means the skill has access to the complete conversation content stored under ~/.openclaw — only install if you trust this code and the operator environment. - The enhanced fact extractor calls `openclaw agent ...` to perform AI extraction. Depending on your OpenClaw configuration, that agent call may send extracted content to a remote model/service. If you require strict local-only processing, verify your OpenClaw agent is configured accordingly before enabling extraction. - The truncate script may run as a background job or be scheduled by cron; test it on sample sessions and back up session files before enabling automatic trimming. - Review and, if desired, adjust configuration (.context-compression-config.json) options like skipActive, maxTokens, and preserveUserMessages to avoid surprising removals from active sessions. - Inspect logs (e.g., ~/.openclaw/logs/truncation.log) after initial runs to confirm behavior, and restrict filesystem permissions on MEMORY.md if it will contain sensitive extracted facts. If you want higher assurance, provide the OpenClaw agent network policy (whether agent calls go off-host) or run the extraction code in an isolated, offline environment and re-run this evaluation.

Like a lobster shell, security has layers — review code before you run it.

Current versionv3.10.0
Download zip
compressionvk97aygk342efd3gcamey4y8ced82rm15contextvk97aygk342efd3gcamey4y8ced82rm15latestvk97aygk342efd3gcamey4y8ced82rm15memoryvk97aygk342efd3gcamey4y8ced82rm15sessionvk97aygk342efd3gcamey4y8ced82rm15

License

MIT-0
Free to use, modify, and redistribute. No attribution required.

Runtime requirements

Binsbash, jq, sed, grep, head, tail, wc, mkdir, date, tr, cut

SKILL.md

Memory Compression

Prevent context overflow. Never lose important conversations.

The Problem

OpenClaw sessions grow indefinitely. When context exceeds the model's limit:

  • New sessions fail to load
  • Important information is lost
  • Cron tasks inherit huge context and crash

The Solution

Automatic session truncation + hierarchical memory preservation:

  1. Trim sessions before they exceed limits
  2. Extract facts (preferences, decisions, tasks) before trimming
  3. Preserve memory through layered storage (MEMORY.md, daily notes, summaries)

🚀 Quick Start

Step 1: Check Configuration

cat ~/.openclaw/workspace/.context-compression-config.json 2>/dev/null

Step 2: Configure (Interactive)

When this skill loads, it guides you through:

QuestionOptionsRecommended
Context preservation20k/40k/60k tokens40k
Truncation frequency10min/30min/1h10min
Skip active sessionsYes/NoYes
Daily summariesYes/NoNo

Step 3: Verify

ls -la ~/.openclaw/workspace/.context-compression-config.json
ls -la ~/.openclaw/workspace/skills/context-compression/scripts/truncate-sessions-safe.sh

🏗️ Architecture

┌─────────────────────────────────────────────────────────────┐
│                    Context Budget: ~80k tokens              │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  L4: MEMORY.md (~5k)      ← User preferences, key facts    │
│  L3: Daily summaries (~10k) ← Compressed older sessions    │
│  L2: Recent sessions (~25k) ← Last N session files         │
│  L1: Current session (~40k) ← Active conversation          │
│                                                             │
└─────────────────────────────────────────────────────────────┘

Key principle: L4 > L3 > L2 in priority. Always preserve MEMORY.md.


🔧 How It Works

Session Truncation

  • Runs in background (independent of agent)
  • Trims to last N tokens per session
  • Skips active sessions (.lock files)
  • Preserves JSONL line integrity

Fact Extraction

  • Detects keywords: 重要/决定/TODO/偏好, important/decision/must
  • Extracts to MEMORY.md before truncation
  • Categories: [偏好], [决策], [任务], [时间], [关系], [重要]

Preference Lifecycle

  • Short-term (1-7 days): Tag with @YYYY-MM-DD
  • Mid-term (1-4 weeks): Auto-expire via daily check
  • Long-term: Permanent in MEMORY.md

📜 Scripts

ScriptPurpose
truncate-sessions-safe.shTrim session files safely
extract-facts-enhanced.shAI-powered fact extraction
check-preferences-expiry.shRemove expired preferences
check-context-health.shReport context status

⚙️ Configuration File

~/.openclaw/workspace/.context-compression-config.json:

{
  "version": "2.3",
  "maxTokens": 40000,
  "frequencyMinutes": 10,
  "skipActive": true,
  "enableSummaries": false,
  "strategy": "priority-first",
  "priorityKeywords": [
    "重要", "决定", "记住", "TODO", "偏好",
    "important", "remember", "must", "deadline", "decision"
  ]
}

✅ Verification Checklist

  • Config file exists
  • Scripts are executable
  • MEMORY.md exists and is current
  • Truncation log shows recent runs: tail ~/.openclaw/logs/truncation.log

🔍 Troubleshooting

ProblemSolution
Context still exceededReduce maxTokens, check truncation log
Memory not persistingVerify real-time writing in AGENTS.md
Summaries not generatedCheck daily notes exist in memory/

📚 Related

Files

4 total
Select a file
Select a file to preview.

Comments

Loading comments…