AgentSkillsCN

session-compress

通过总结旧消息,压缩会话对话历史。当会话上下文逐渐冗长,而你希望在减少令牌数量的同时保留关键信息时使用此功能。它会保留最近的消息,同时将较早的消息浓缩成简洁的摘要。

SKILL.md
--- frontmatter
name: session-compress
description: "Compress session conversation history by summarizing older messages. Use when session context is getting long and you want to preserve key information while reducing token count. Keeps recent messages intact, summarizes older ones into a concise summary."
version: "1.0.0"
author: "Skunkworks NZ"
tags: ["memory", "compression", "tokens", "optimization"]

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

  1. Recent messages (last 5-10) stay intact
  2. Older messages are summarized into a condensed form
  3. Key information preserved: decisions, facts, preferences, task state
  4. 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:

  1. Reads session transcript from ~/.openclaw/sessions/<session>/transcript.jsonl
  2. Identifies messages to compress (excludes recent ones)
  3. Calls LLM with summarization prompt
  4. Replaces older messages with summary
  5. 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