context-budgeting
通过分区、预压缩检查点和信息生命周期管理来管理和优化 OpenClaw 上下文窗口的使用。当会话上下文接近其限制 (>80%)、代理在压缩后经历“内存丢失”或旨在减少长时间运行任务的令牌成本和延迟时使用。
安装 / 下载方式
TotalClaw CLI推荐
totalclaw install totalclaw:totalclaw~sarielwang93-context-budgetingcURL直接下载,无需登录
curl -fsSL https://skills.taituai.com/api/skills/totalclaw%3Atotalclaw~sarielwang93-context-budgeting/file -o sarielwang93-context-budgeting.md# Context Budgeting Skill
This skill provides a systematic framework for managing the finite context window (RAM) of an OpenClaw agent.
## Core Concepts
### 1. Information Partitioning
- **Objective/Goal (10%)**: Core task instructions and active constraints.
- **Short-term History (40%)**: Recent 5-10 turns of raw dialogue.
- **Decision Logs (20%)**: Summarized outcomes of past steps ("Tried X, failed because Y").
- **Background/Knowledge (20%)**: High-relevance snippets from MEMORY.md.
### 2. Pre-compression Checkpointing (Mandatory)
Before any compaction (manual or automatic), the agent MUST:
1. **Generate Checkpoint**: Update `memory/hot/HOT_MEMORY.md` with:
- **Status**: Current task progress.
- **Key Decision**: Significant choices made.
- **Next Step**: Immediate action required.
2. **Run Automation**: Execute `scripts/gc_and_checkpoint.sh` to trigger the physical cleanup.
## Automation Tool: `gc_and_checkpoint.sh`
Located at: `skills/context-budgeting/scripts/gc_and_checkpoint.sh`
**Usage**:
- Run this script after updating `HOT_MEMORY.md` to finalize the compaction process without restarting the session.
## Integration with Heartbeat
Heartbeat (every 30m) acts as the Garbage Collector (GC):
1. Check `/status`. If Context > 80%, trigger the **Checkpointing** procedure.
2. Clear raw data (e.g., multi-megabyte JSON outputs) once the summary is extracted.
---
## 中文说明
# 上下文预算技能
本技能提供了一套系统化的框架,用于管理 OpenClaw 代理有限的上下文窗口(RAM)。
## 核心概念
### 1. 信息分区
- **目标/Goal (10%)**:核心任务指令和当前的约束条件。
- **短期历史 (40%)**:最近 5-10 轮的原始对话。
- **决策日志 (20%)**:对过往步骤结果的总结("尝试了 X,因为 Y 而失败")。
- **背景/知识 (20%)**:来自 MEMORY.md 的高相关性片段。
### 2. 压缩前检查点(强制)
在任何压缩(手动或自动)之前,代理必须:
1. **生成检查点**:更新 `memory/hot/HOT_MEMORY.md`,写入:
- **Status**:当前任务进度。
- **Key Decision**:所做出的重要选择。
- **Next Step**:需要立即执行的操作。
2. **运行自动化**:执行 `scripts/gc_and_checkpoint.sh` 以触发物理清理。
## 自动化工具:`gc_and_checkpoint.sh`
位于:`skills/context-budgeting/scripts/gc_and_checkpoint.sh`
**用法:**
- 在更新 `HOT_MEMORY.md` 后运行此脚本,可在不重启会话的情况下完成压缩流程。
## 与 Heartbeat 的集成
Heartbeat(每 30 分钟)充当垃圾回收器(GC):
1. 检查 `/status`。如果 Context > 80%,触发**检查点**流程。
2. 在提取出摘要后,清除原始数据(例如数兆字节的 JSON 输出)。