360 Secure SkillHub
360 安全技能中心

Snip Compressor

核心功能:基于语义分析对对话分段评分,按决策>数据>工具结果>寒暄的优先级保留/压缩内容,保障语义连贯而非简单截断。典型场景:对话占上下文窗口超60%、用户询问对话进度、会话交接前等。输入为JSON格式的消息数组,输出含总览、关键决策等的Markdown文档,支持多种调用方式。

chen6896qqwee
chen6896qqwee
热度 8.59
最近更新 2026-07-10 09:34:43
分类:效率依赖:代码执行应用场景:摘要总结

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add snip-compressor
Metadata
name
snip-compressor
description
Semantic conversation compressor — intelligently summarize long chat history while preserving key decisions, facts, and context.
metadata
{"openclaw":{"requires":{"bins":["python3"]}}}

Snip Compressor

Distilled from Claude Code's Snip compression engine. Analyzes conversation history and generates a compressed summary that preserves semantic continuity — not a simple truncation.

When to use

  • Conversation exceeds 60% of context window
  • User says "continue" / "刚才说到哪了" / "where were we"
  • Before compaction to preserve key context
  • Session handoff between agents

How it works

  1. Parse — Split conversation into segments (user messages, assistant replies, tool calls, tool results)
  2. Score — Each segment gets a retention score based on:
    • Contains decision/agreement (high)
    • Contains factual data/numbers (high)
    • Contains tool results (medium, summarized)
    • Contains greetings/small talk (low)
  3. Compress — Low-score segments get dropped or condensed; high-score segments preserved verbatim or lightly summarized
  4. Rebuild — Output a compressed transcript that reads naturally

Usage

# Compress a conversation file
python3 {baseDir}/compressor.py --input conversation.json --output compressed.md

# Compress with custom token budget
python3 {baseDir}/compressor.py --input conversation.json --budget 2000

# Compress from stdin
cat conversation.json | python3 {baseDir}/compressor.py --budget 1500

Input format

JSON array of message objects:

[
  {
    "role": "user",
    "content": "帮我分析一下这个股票"
  },
  {
    "role": "assistant",
    "content": "好的,我来看看...",
    "tool_calls": [
      {"name": "exec", "result": "{...}"}
    ]
  }
]

Output

Markdown with sections:

  • Summary: 1-2 paragraph overview
  • Key Decisions: bullet list of decisions made
  • Active Context: what's currently in progress
  • Compressed Transcript: compressed conversation (token-optimized)

Algorithm reference

Based on Claude Code's src/services/snip/ module:

  • Semantic boundary detection: topic shift → new segment
  • Importance scoring: decision > data > tool_result > greeting
  • Token-aware truncation: respects model-specific limits
  • Cross-segment reference preservation: if segment B references segment A, both are retained