上下文窗口优化器

v1.0.0

上下文窗口优化器 - 原创技能。智能管理AI上下文窗口,自动压缩历史、去除冗余、保留关键信息,节省token提升效率。适用于长会话、多文件、大项目等场景。

0· 18·0 current·0 all-time

Install

OpenClaw Prompt Flow

Install with OpenClaw

Best for remote or guided setup. Copy the exact prompt, then paste it into OpenClaw for 534422530/laosi-context-opt.

Previewing Install & Setup.
Prompt PreviewInstall & Setup
Install the skill "上下文窗口优化器" (534422530/laosi-context-opt) from ClawHub.
Skill page: https://clawhub.ai/534422530/laosi-context-opt
Keep the work scoped to this skill only.
After install, inspect the skill metadata and help me finish setup.
Use only the metadata you can verify from ClawHub; do not invent missing requirements.
Ask before making any broader environment changes.

Command Line

CLI Commands

Use the direct CLI path if you want to install manually and keep every step visible.

OpenClaw CLI

Bare skill slug

openclaw skills install laosi-context-opt

ClawHub CLI

Package manager switcher

npx clawhub@latest install laosi-context-opt
Security Scan
VirusTotalVirusTotal
Benign
View report →
OpenClawOpenClaw
Benign
high confidence
Purpose & Capability
Name/description (context optimization) align with the SKILL.md content: algorithms, triggers, and retention policies. There are no unrelated required binaries, credentials, or config paths.
Instruction Scope
SKILL.md contains pseudocode and policies for compressing chat history, monitoring tokens/messages, and replacing history with compressed summaries. It does not instruct the agent to read arbitrary system files, access secrets, or transmit data to external endpoints. The only potentially impactful action is 'replace original content' (i.e., pruning history), which is coherent with the stated purpose.
Install Mechanism
Instruction-only skill with no install spec and no code files; nothing is written to disk or downloaded during install. Lowest-risk install profile.
Credentials
No environment variables, credentials, or config paths are requested. The SKILL.md does not reference hidden env vars or external tokens. Required access is proportional to purpose.
Persistence & Privilege
Skill is not always-enabled and does not request system-wide modifications. It can be invoked autonomously by the agent (default behavior), which is expected for skills of this type and is not combined with other red flags here.
Assessment
This skill is internally consistent and does not request secrets or installs. Before enabling it in a production agent, test it on non-critical conversations so you can verify the pruning behavior and ensure no important data is lost. Mark any irreplacable data (credentials, legal text, critical decisions) as L1/‘must keep’ so the optimizer won't remove it. Also review interactions with other skills or memory stores you use (the SKILL.md suggests integrations) — those other skills may have their own permissions and risks. Finally, because this is instruction-only, the actual effect depends on the agent runtime implementing these instructions correctly; prefer running it in a controlled environment first.

Like a lobster shell, security has layers — review code before you run it.

contextvk97b97zy5kdddnm46838pn1sms85p44elatestvk97b97zy5kdddnm46838pn1sms85p44eoptimizationvk97b97zy5kdddnm46838pn1sms85p44etoken-savingvk97b97zy5kdddnm46838pn1sms85p44e
18downloads
0stars
1versions
Updated 5h ago
v1.0.0
MIT-0

⚠️ 发布规则

所有发布到ClawHub的技能必须严格测试,确定没有问题再发布


技能测试验证清单

  • frontmatter格式正确
  • 优化策略完整
  • 优先级明确
  • 压缩算法清晰
  • 无语法错误

Context Window Optimizer - 上下文窗口优化器

原创技能 | 激活词: 优化上下文 / 精简历史 / 节省token

核心问题

AI会话中的上下文会不断增长:

  • 对话历史越来越长
  • token消耗越来越多
  • 早期信息被稀释
  • 响应质量下降

优化策略

策略1: 关键信息提取

原始对话 (500 tokens):
用户: "我想用React写一个按钮组件"
AI: 好的,我来创建...
用户: "按钮需要支持loading状态"
AI: 好的,添加loading...
用户: "还要支持disabled状态"
AI: 好的,添加disabled...
[... 继续50轮...]

优化后 (50 tokens):
用户意图: 创建React按钮组件
关键需求: loading状态, disabled状态
当前进度: 组件已创建
待办: 添加loading/disabled支持

策略2: 语义压缩

def compress_context(messages: list[Message]) -> list[Message]:
    compressed = []
    
    for msg in messages:
        # 保留决策点
        if is_decision_point(msg):
            compressed.append(msg)
        
        # 保留结果/输出
        elif is_result(msg):
            compressed.append(msg)
        
        # 压缩重复过程
        elif is_redundant(msg):
            summary = summarize(msg)
            compressed.append(summary)
        
        # 丢弃中间步骤
        else:
            pass  # 不保留
    
    return compressed

策略3: 分层保留

层级内容保留策略
L1 核心决策、结论、配置永远保留
L2 重要当前任务相关信息保留最近
L3 一般过程、对话可压缩
L4 垃圾重复、废话丢弃

策略4: 时间衰减

def time_decay(messages: list[Message], current_time: datetime) -> list[Message]:
    for msg in messages:
        age = current_time - msg.timestamp
        
        if age < 1 hour:
            weight = 1.0
        elif age < 1 day:
            weight = 0.8
        elif age < 1 week:
            weight = 0.5
        else:
            weight = 0.2
        
        msg.priority *= weight
    
    return filter_by_priority(messages)

优化触发条件

TRIGGERS = {
    'token_threshold': 50_000,      # token超过此值
    'message_threshold': 100,       # 消息超过100条
    'repetition_rate': 0.3,         # 重复率超过30%
    'quality_drop': 0.2,            # 质量下降20%
}

优化流程

1. 监控 → 跟踪token和消息数量
      ↓
2. 判断 → 是否达到触发条件
      ↓
3. 分析 → 识别各层级内容
      ↓
4. 压缩 → 执行压缩策略
      ↓
5. 验证 → 确保关键信息不丢失
      ↓
6. 替换 → 用压缩版本替换原内容

输出格式

## 上下文优化报告

### 优化前
- Token: 52,341
- 消息数: 127条
- 质量评分: 0.65

### 优化后
- Token: 18,234 (减少 65%)
- 消息数: 31条
- 质量评分: 0.92

### 保留内容
✅ 核心决策: 3条
✅ 关键配置: 2条
✅ 当前任务状态: 完整
✅ 用户偏好: 保留

### 丢弃内容
❌ 中间过程: 89条
❌ 重复对话: 7条
❌ 废话消息: 4条

### 优化建议
1. 建议定期优化,每50条消息触发一次
2. 重要信息标记为L1可防止被优化

优先级队列

必须保留 (L1)

L1_MUST_KEEP = [
    "用户偏好设置",
    "项目配置信息",
    "核心架构决策",
    "已完成的重要工作",
    "待办事项清单",
]

尽量保留 (L2)

L2_TRY_KEEP = [
    "当前任务进度",
    "最近10条有效对话",
    "关键文件路径",
    "错误解决方案",
]

可优化 (L3)

L3_COMPRESSIBLE = [
    "中间调试过程",
    "重复的确认对话",
    "详细的日志输出",
    "试错过程",
]

丢弃 (L4)

L4_DISCARD = [
    "无意义的闲聊",
    "重复的错误尝试",
    "过期的临时信息",
    "明显的废话",
]

集成建议

配合其他技能使用:

配合技能效果
entropy-manager熵值高时触发优化
context-memory-ball优化后的上下文保存为球
mempalace-assistant重要信息存入记忆库

性能指标

指标优化前优化后
Token使用52K18K
响应质量65%92%
上下文清晰度
信息密度

原创性声明

本技能为原创,融合了:

  • 文本压缩算法
  • 信息检索优先级
  • 时间衰减模型
  • 分层缓存策略

作者: laosi 创建日期: 2026-04-28

Comments

Loading comments...