Token导航 LogoToken导航TokenDH.com
效率需要联网clawhub未标认证来源可访问clear审计提醒

context-compactor上下文压缩器

Agent Skill

context-compactor 用于补充效率相关能力,适合在 OpenClaw 中需要让 Agent 承接效率相关任务时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

55,344

周安装

2,306

GitHub Stars

公开资料未说明

下载量

18,448
OpenClaw

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

MIT-0

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:context-compactor(上下文压缩器)
来源仓库:https://github.com/emberdesire/context-compactor
安装命令:
openclaw skills install context-compactor
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 OpenClaw 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

ClawHubOpenClaw
openclaw skills install context-compactor

简介

针对不报告上下文限制的本地模型(MLX、llama.cpp、Ollama)的基于令牌的上下文压缩。

SKILL.md

name
context-compactor
version
0.3.8
description
Token-based context compaction for local models (MLX, llama.cpp, Ollama) that don't report context limits.

Context Compactor

Automatic context compaction for OpenClaw when using local models that don't properly report token limits or context overflow errors.

The Problem

Cloud APIs (Anthropic, OpenAI) report context overflow errors, allowing OpenClaw's built-in compaction to trigger. Local models (MLX, llama.cpp, Ollama) often:

  • Silently truncate context
  • Return garbage when context is exceeded
  • Don't report accurate token counts

This leaves you with broken conversations when context gets too long.

The Solution

Context Compactor estimates tokens client-side and proactively summarizes older messages before hitting the model's limit.

How It Works

┌─────────────────────────────────────────────────────────────┐
│  1. Message arrives                                         │
│  2. before_agent_start hook fires                           │
│  3. Plugin estimates total context tokens                   │
│  4. If over maxTokens:                                      │
│     a. Split into "old" and "recent" messages              │
│     b. Summarize old messages (LLM or fallback)            │
│     c. Inject summary as compacted context                 │
│  5. Agent sees: summary + recent + new message             │
└─────────────────────────────────────────────────────────────┘

Installation

# One command setup (recommended)
npx jasper-context-compactor setup

# Restart gateway
openclaw gateway restart

The setup command automatically:

  • Copies plugin files to ~/.openclaw/extensions/context-compactor/
  • Adds plugin config to openclaw.json with sensible defaults

Configuration

Add to openclaw.json:

{
  "plugins": {
    "entries": {
      "context-compactor": {
        "enabled": true,
        "config": {
          "maxTokens": 8000,
          "keepRecentTokens": 2000,
          "summaryMaxTokens": 1000,
          "charsPerToken": 4
        }
      }
    }
  }
}

Options

OptionDefaultDescription
enabledtrueEnable/disable the plugin
maxTokens8000Max context tokens before compaction
keepRecentTokens2000Tokens to preserve from recent messages
summaryMaxTokens1000Max tokens for the summary
charsPerToken4Token estimation ratio
summaryModel(session model)Model to use for summarization

Tuning for Your Model

MLX (8K context models):

{
  "maxTokens": 6000,
  "keepRecentTokens": 1500,
  "charsPerToken": 4
}

Larger context (32K models):

{
  "maxTokens": 28000,
  "keepRecentTokens": 4000,
  "charsPerToken": 4
}

Small context (4K models):

{
  "maxTokens": 3000,
  "keepRecentTokens": 800,
  "charsPerToken": 4
}

Commands

/compact-now

Force clear the summary cache and trigger fresh compaction on next message.

/compact-now

/context-stats

Show current context token usage and whether compaction would trigger.

/context-stats

Output:

📊 Context Stats

Messages: 47 total
- User: 23
- Assistant: 24
- System: 0

Estimated Tokens: ~6,234
Limit: 8,000
Usage: 77.9%

✅ Within limits

How Summarization Works

When compaction triggers:

  1. Split messages into "old" (to summarize) and "recent" (to keep)
  2. Generate summary using the session model (or configured summaryModel)
  3. Cache the summary to avoid regenerating for the same content
  4. Inject context with the summary prepended

If the LLM runtime isn't available (e.g., during startup), a fallback truncation-based summary is used.

Differences from Built-in Compaction

FeatureBuilt-inContext Compactor
TriggerModel reports overflowToken estimate threshold
Works with local models❌ (need overflow error)
Persists to transcript❌ (session-only)
SummarizationPi runtimePlugin LLM call

Context Compactor is complementary — it catches cases before they hit the model's hard limit.

Troubleshooting

Summary quality is poor:

  • Try a better summaryModel
  • Increase summaryMaxTokens
  • The fallback truncation is used if LLM runtime isn't available

Compaction triggers too often:

  • Increase maxTokens
  • Decrease keepRecentTokens (keeps less, summarizes earlier)

Not compacting when expected:

  • Check /context-stats to see current usage
  • Verify enabled: true in config
  • Check logs for [context-compactor] messages

Characters per token wrong:

  • Default of 4 works for English
  • Try 3 for CJK languages
  • Try 5 for highly technical content

Logs

Enable debug logging:

{
  "plugins": {
    "entries": {
      "context-compactor": {
        "config": {
          "logLevel": "debug"
        }
      }
    }
  }
}

Look for:

  • [context-compactor] Current context: ~XXXX tokens
  • [context-compactor] Compacted X messages → summary

Links

  • GitHub: https://github.com/E-x-O-Entertainment-Studios-Inc/openclaw-context-compactor
  • OpenClaw Docs: https://docs.openclaw.ai/concepts/compaction

适合场景

01

OpenClaw 用户查找和安装 Skill 时

02

用户想查找某类 Agent Skill 时

03

需要根据任务场景推荐可安装能力包时

04

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

OpenClaw

89.77%
按下载量换算16,561

安全审计

VirusTotal

可疑

ClawScan

通过

Static analysis

未展示

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills