Session Compression Skill
This skill compresses long conversation histories by summarizing older messages while preserving key information.
When to Use
- •Session is approaching token limits
- •Conversation has gone on for many turns
- •You want to maintain context without hitting limits
- •Before complex multi-step tasks
How It Works
- •Recent messages (last 5-10) stay intact
- •Older messages are summarized into a condensed form
- •Key information preserved: decisions, facts, preferences, task state
- •Token reduction: typically 60-80% compression
Usage
Manual Compression
bash
# Compress current session scripts/compress_session.sh # Compress with custom keep count KEEP_LAST=10 scripts/compress_session.sh
Triggered by Token Count
The session monitors token count and can auto-trigger compression when approaching limits.
Implementation
The skill:
- •Reads session transcript from
~/.openclaw/sessions/<session>/transcript.jsonl - •Identifies messages to compress (excludes recent ones)
- •Calls LLM with summarization prompt
- •Replaces older messages with summary
- •Updates token count
Configuration
config.json
json
{
"keepRecent": 10,
"summaryModel": "minimax/MiniMax-M2.5",
"maxTokens": 4000
}
- •
keepRecent: Number of recent messages to keep intact - •
summaryModel: Model to use for summarization - •
maxTokens: Target token count after compression
Integration
This skill can be called by agents when:
- •Token count exceeds threshold
- •Before spawning subagents
- •After completing major milestones