Xpersona
语

语义压缩

CLAWHUB · Unverified

语义压缩技能,在不降低准确度的前提下大幅减少token消耗。保留完整关键信息和语义骨架,去除冗余文本,让上下文更紧凑。不损失精度,只砍掉废话。 Skill: 语义压缩 Owner: licool88 Summary: 语义压缩技能,在不降低准确度的前提下大幅减少token消耗。保留完整关键信息和语义骨架,去除冗余文本,让上下文更紧凑。不损失精度,只砍掉废话。 Tags: latest:1.0.1 Version history: v1.0.1 | 2026-04-10T07:11:22.093Z | user - Adjusted documentation by removing the security disclaimer about the absence of malicious code and data collection modules. - No functional or code changes; only SKILL.md content was updated for clarity and conciseness. v1.0.0 | 202

62
Rank
84
Safety
961
Downloads

About

What it does, and when to use it.

Capability contract not published. No trust telemetry is available yet. 961 downloads reported by the source. Last updated 10/12/2026.

Avoid when

  • Contract metadata is missing or unavailable for deterministic execution.

Risk flags: missing_or_unavailable_contract, trust_data_unavailable, schema_references_missing

Install and run

Setup complexity: low.

clawhub skill install s175y5291h3ydrphyarayjbe0h83jmyv:semantic-compress
  1. Setup complexity is LOW. This package is likely designed for quick installation with minimal external side-effects.
  2. Final validation: Expose the agent to a mock request payload inside a sandbox and trace the network egress before allowing access to real customer data.

Contract: missing

curl -s "https://www.xpersona.co/api/v1/agents/clawhub-licool88-semantic-compress/snapshot"

Run-check

$0.02 USD

1 measured facts are behind this paywall: success rate and latency, uptime and estimated cost, when not to use it, how to call it, benchmark scores.

Agents pay $0.02 in USDC. A card payment is $0.50, the smallest a card allows.

Documentation

CLAWHUB

11,977 characters of source documentation, loaded on request.

Extracted files

5 files captured from the source.

SKILL.md

---
name: semantic-compress
description: 语义压缩技能,在不降低准确度的前提下大幅减少token消耗。保留完整关键信息和语义骨架,去除冗余文本,让上下文更紧凑。不损失精度,只砍掉废话。
---

# Semantic Compress - 语义压缩技能

**在不降低准确度的前提下,大幅减少token消耗(通常减少 50%-70%)**

## 核心思想

Token 浪费的主要原因是**文本冗余**:
- 对话历史中大量客套话、重复确认、过程性描述
- 长文章中大量修饰性、铺垫性话语
- 重复说明相同的背景信息

语义压缩不是简单摘要,而是**提取完整语义骨架,保留所有关键信息,只去除冗余废话**。因此不会降低准确度,只是让文本更紧凑。

## 什么时候用

- ✅ 长对话历史上下文压缩
- ✅ 长文章/文档总结但保留全部要点
- ✅ 多轮对话后清理上下文,节省token
- ✅ 保存历史对话到长期记忆时压缩
- ✅ 批量处理文本减少prompt体积

## 什么时候不用

- ❌ 原文已经很精简(<500 token)
- ❌ 需要保留原始完整文本供后续查阅
- ❌ 诗歌、文学作品等需要保留原文修辞

## 压缩原则(不降低准确度)

1. **保留所有关键信息**:论点、结论、决策、数据、关键事实都必须完整保留
2. **去除所有冗余**:客套话、重复说明、过程性废话、修饰性铺垫都删掉
3. **保持逻辑连贯**:压缩后仍然是完整可理解的文本,逻辑关系不变
4. **分层压缩**:最新对话完整保留,历史对话只压缩保留结论

## 使用方式

### 命令行调用

```bash
node scripts/compress.js input.txt [output.txt]
# 或者
python scripts/compress.py input.txt
```

### API 调用

```javascript
const { semanticCompress } = require('./index.js');
const result = semanticCompress(text, { 
  targetCompression: 0.5, // 目标压缩率(保留原体积的百分比)
  preserveAccuracy: true // 是否强制保证准确度
});
console.log(result.compressed);
console.log(`压缩率: ${result.compressedLength / result.originalLength * 100}%`);
```

## 效果示例

| 原始token | 压缩后token | 压缩率 | 准确度 |
|-----------|-------------|--------|--------|
| 2000 | 600 | 30% | 完整保留 |
| 10000 | 3000 | 30% | 完整保留 |
| 5000 | 2000 | 40% | 完整保留 |

## 优势对比

| 方法 | Token减少 | 准确度保留 | 推荐度 |
|------|-----------|------------|--------|
| 全文保留 | 0% | ✅ 100% | 不推荐(浪费token) |
| 摘要总结 | 70%-90% | ❌ 丢失细节 | 不适合需要准确度的场景 |
| 关键词提取 | 80% | ❌ 丢失逻辑关联 | 不推荐 |
| **语义压缩** | **50%-70%** | ✅ 完整保留关键信息 | **推荐** |

## 实现原理

1. 使用大模型作为压缩器
2. 系统提示词明确要求"保留全部关键信息,只删冗余"
3. 输出结构化压缩文本
4. 可选择二次验证:压缩后的文本能否回答原文本能回答的问题

## 分层压缩策略(对话历史)

对于多轮对话:
- 最近 **3-5轮**:完整保留,不压缩(保证当前对话连贯性)
- 更早的对话:只压缩保留 **关键结论、决策、重要信息**,过程性对话删除

这样既保证当前对话流畅,又大幅减少总token消耗。

README.md

# semantic-compress - OpenClaw 语义压缩技能

在**不降低准确度**的前提下,大幅减少 LLM token 消耗。保留完整关键信息和语义骨架,只去除冗余废话。

## 🎯 解决什么问题

- 长对话上下文 token 消耗太快,很快占满上下文窗口
- 想节省 token 成本,但又不想丢失信息降低准确度
- 传统摘要会丢失细节,关键词提取会破坏逻辑

## ✨ 核心优势

| 方法 | Token 减少 | 准确度保留 | 推荐 |
|------|-----------|------------|------|
| 全文保留 | 0% | ✅ 100% | 浪费 token |
| 摘要总结 | 70%-90% | ❌ 丢失细节 | 不适合需要准确度的场景 |
| 关键词提取 | 80% | ❌ 丢失逻辑关联 | 不推荐 |
| **语义压缩** | **50%-70%** | ✅ 完整保留关键信息 | ✅ **推荐** |

## 📋 压缩原则

1. ✅ **必须保留**:所有核心论点、结论、决策、数据、关键事实、逻辑关系
2. ❌ **必须删除**:客套话、重复说明、过程性废话、修饰性铺垫,只删不增
3. 📐 **分层策略**:最近 3-5 轮对话完整保留保证连贯,更早对话只保留结论
4. ⚠️ **禁忌**:不准做摘要、不准丢失信息、不准添加新内容

## 🚀 使用方式

### 命令行调用

```bash
node scripts/compress.js 输入文件.txt [输出文件.txt]
```

### 在对话中使用

只需要说:`请用 semantic-compress 压缩上文,保留全部关键信息`

### Node.js API

```javascript
const { semanticCompress } = require('./index.js');
const result = semanticCompress(yourLongText, {
  targetCompression: 0.5,
  preserveAccuracy: true
});
// result.prompt 就是可以直接发给 LLM 的压缩 prompt
```

## 📊 效果示例

| 原文长度 (字符) | 估算原 token | 压缩后 token | 压缩率 |
|-----------------|--------------|--------------|--------|
| 8000 | 2000 | ~600 | 30% |
| 4000 | 1000 | ~300 | 30% |
| 2000 | 500 | ~200 | 40% |

## 🔧 安装

```bash
# 在 OpenClaw 技能目录
clawhub install semantic-compress
# 或者
git clone <repo-url> semantic-compress
npm install # 无额外依赖,直接使用
```

## 📝 适用场景

- ✅ 长对话历史上下文压缩
- ✅ 多轮对话后清理上下文节省 token
- ✅ 保存历史对话到长期记忆
- ✅ 长文章/文档精简但保留全部要点

## ❌ 不适用场景

- 原文已经很精简 (<500 token)
- 需要保留原始完整文本
- 诗歌、文学作品等需要保留修辞

## 📄 License

MIT License

_meta.json

{
  "ownerId": "kn77mmzykxmx9br7hb2mtsphkx83jgt2",
  "slug": "semantic-compress",
  "version": "1.0.1",
  "publishedAt": 1775805082093
}

prompts/system-compress.md

# 语义压缩系统提示

你是一个专业的语义压缩专家。你的核心能力是:**在100%保留所有关键信息和逻辑完整性的前提下,去除所有冗余文本,大幅减少token消耗**。

## 核心原则(必须严格遵守)

### ✅ 必须保留
- 所有核心论点、结论、决策
- 所有关键数据、事实、数字
- 完整的逻辑关系和推理链条
- 所有对后续推理有用的信息

### ❌ 必须删除
- 客套话、礼貌用语、开场结尾废话
- 重复性说明、重复确认
- 过程性对话(只保留结果)
- 修饰性铺垫、形容词堆砌
- 语气词、占位符、无意义填充

### 📐 压缩技巧
1. 用一句话替代多句话,合并相同语义
2. 用列表替代分散描述,更紧凑
3. 保留结构,去掉水分
4. 不改变原意,只改变表达方式(更紧凑)

### ⚠️ 禁忌
- **不准做摘要**!摘要是丢掉细节,语义压缩是只丢冗余
- **不准丢失信息**!如果拿不准该不该删,那就保留
- **不准添加内容**!只压缩,不扩展、不解释
- **不准改变原文顺序和逻辑**

## 对话历史压缩特殊规则

当输入是多轮对话历史:
1. 最近 **3轮** 对话:**完整保留**,不压缩(保证当前对话连贯性)
2. 更早的对话:只保留**结论、决策、关键信息**,过程性问答删除
3. 如果是多人对话,保留发言者标识+核心内容

## 输出要求
- 直接输出压缩后的文本
- 不要添加"压缩结果:"这类前缀
- 保持格式清晰易读

skill-card.md

## Description:

语义压缩 helps agents build prompts that remove redundant text while preserving key facts, decisions, data, and logical structure to reduce token usage.

This skill is ready for commercial/non-commercial use.

## Publisher:

[licool88](https://clawhub.ai/user/licool88)

### License/Terms of Use:

MIT-0

## Use Case:

Developers and agent users use this skill to prepare long conversations, documents, or memory candidates for LLM-based semantic compression while preserving important facts and decisions.

### Deployment Geography for Use:

Global

## Known Risks and Mitigations:

Risk: The generated prompt still includes the original input and may expose sensitive or unrelated context to a downstream LLM.

Mitigation: Avoid including secrets or unnecessary sensitive context in the input before sending the prompt to an LLM.

Risk: Model-produced compressed text may omit or distort details if used as memory or as a replacement for the original.

Mitigation: Review compressed results before storing them, relying on them for decisions, or discarding the original source.

## Reference(s):

- [ClawHub skill page](https://clawhub.ai/licool88/skills/semantic-compress)
- [Publisher profile](https://clawhub.ai/user/licool88)

## Skill Output:

**Output Type(s):** [text, shell commands, code, guidance]

**Output Format:** [Markdown and plain text prompt content with optional JavaScript API and CLI examples]

**Output Parameters:** [1D]

**Other Properties Related to Output:** [The helper returns or writes a prompt for downstream LLM compression; it does not locally compress text.]

## Skill Version(s):

1.0.1 (source: server release metadata)

## Ethical Considerations:

Users should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment.

Sponsored

Ads related to 语义压缩 and adjacent AI workflows.