Trinity Compress:优化 AI 提示词 Token 使用 - Openclaw Skills

作者:互联网

2026-04-13

AI教程

什么是 Trinity Compress?

Trinity Compress 是一款专为使用 AI 智能体进行开发的开发者设计的专业实用工具。它针对迭代开发循环中出现的提示词冗余,在将提示词文件发送给 LLM 供应商之前,去除不必要的字符和格式。通过将其集成到您的工作流中,您可以显著降低运营成本并保持在上下文限制内,同时不牺牲指令的核心逻辑。

作为 Openclaw Skills 生态系统的一部分,它提供了一个轻量级的、本地优先的 Token 管理解决方案。与基于模型的压缩器不同,Trinity Compress 完全使用 bash 脚本在您的机器上运行,确保您的数据保持私密,同时提供即时结果。

下载入口:https://github.com/openclaw/skills/tree/main/skills/trinitybotserver/compression

安装与下载

1. ClawHub CLI

从源直接安装技能的最快方式。

npx clawhub@latest install compression

2. 手动安装

将技能文件夹复制到以下位置之一

全局模式 ~/.openclaw/skills/ 工作区 /skills/

优先级:工作区 > 本地 > 内置

3. 提示词安装

将此提示词复制到 OpenClaw 即可自动安装。

请帮我使用 Clawhub 安装 compression。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。

Trinity Compress 应用场景

  • 在高频 Ralph 风格开发循环中减少 Token 消耗。
  • 在部署前优化智能体或技能目录中的海量提示词库。
  • 管理按 Token 计费的 AI 供应商的上下文窗口限制。
  • 使用 Openclaw Skills 在 CI/CD 或本地构建过程中自动化提示词清理。
Trinity Compress 工作原理
  1. 脚本读取 trinity-compress.config.json 中定义的配置,以识别目标文件和压缩规则。
  2. 它创建原始文件的 .bak 备份,确保不会永久丢失数据。
  3. 本地 bash 脚本处理文本,移除冗余空格和格式,同时保留代码块、URL 和变量等关键元素。
  4. 它输出压缩版本,供您的 AI 智能体或开发脚本读取。
  5. 用户可以使用计算出的指标验证缩减效果,或使用撤销命令立即恢复更改。

Trinity Compress 配置指南

要开始使用 Openclaw Skills 库中的这项新增功能,请按照以下步骤操作:

  1. 确保您的系统中安装了 bash 4+、jq 和 bc。
  2. 运行适用于您操作系统的安装脚本:
# 适用于 Linux/macOS
./scripts/install.sh

# 适用于 Windows
./scripts/install.ps1
  1. 在 trinity-compress.config.json 中配置您的压缩目标。
  2. 执行压缩脚本:
bash scripts/trinity-compress.sh balanced

Trinity Compress 数据架构与分类体系

Trinity Compress 通过以下文件结构组织其操作:

文件/组件 描述
trinity-compress.config.json 定义规则、排除项和目标目录的核心配置。
scripts/trinity-compress.sh 用于本地文本处理和 Token 缩减的核心执行引擎。
*.bak 在压缩生命周期中为安全起见创建的临时备份文件。
Makefile 片段 可选的集成点,用于 optimize-prompts 和 optimize-undo 等命令。

Trinity Compress (Skill)

Pre-run prompt compression for iterative AI dev loops.

Goal: reduce input tokens every iteration by compressing prompt files before your loop runs.

  • Works with Ralph-style loops, agent/skill directories, and most token-billed providers.
  • Runs as a local script (no model calls).
  • Creates .bak backups and supports instant undo.

What it installs into a repo

  • trinity-compress.config.json — rules + targets
  • scripts/trinity-compress.sh — compression script
  • Makefile snippet (optional): optimize-prompts, optimize-undo, etc.
  • .gitignore snippet: ignore *.bak
  • Installers:
    • scripts/install.ps1 (Windows)
    • scripts/install.sh (bash)

Requirements

  • bash 4+
  • jq
  • bc

Use

  1. Install into your repo (copy assets or use the included installer scripts)
  2. Run:
    • bash scripts/trinity-compress.sh balanced
    • or via Makefile target

Undo

  • Restores all *.bak backups from the last run.

Notes

  • This tool does not rewrite code blocks, URLs, file paths, or variable names.
  • Aggressive mode may reduce clarity; review before committing.

相关推荐