context-budget-guard
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseContext Budget Guard
上下文预算防护
State file:
~/.openclaw/skill-state/context-budget-guard/state.yamlDon't wait for the model to go incoherent. Act at 70%, not 95%.
状态文件:
~/.openclaw/skill-state/context-budget-guard/state.yaml不要等到模型输出变得语无伦次再处理,在用量达到70%时就行动,而非等到95%。
When to Use
适用场景
- At the start of any long-running session (>30 min expected)
- Before each major task step in a multi-hour workflow
- When advances to a new stage
long-running-task-management
- 任何预计运行时长超过30分钟的长会话开始时
- 数小时工作流中每个主要任务步骤执行前
- 当推进到新阶段时
long-running-task-management
The Process
操作流程
Step 1: Initialize (Session Start)
步骤1:初始化(会话开始)
Write to state: timestamp, , , .
session_startcompaction_count: 0status: monitoringthreshold_pct: 70向状态文件写入: 时间戳、、、。
session_startcompaction_count: 0status: monitoringthreshold_pct: 70Step 2: Check Budget (Before Each Major Step)
步骤2:检查预算(每个主要步骤执行前)
Estimate current context usage as a rough percentage:
- Low (<50%) — continue normally
- Medium (50–70%) — note in state, proceed with caution (avoid loading large files)
- High (>70%) — trigger NOW, before continuing
context-window-management
To estimate: count approximate tokens from recent messages, loaded file contents, and active task context.
估算当前上下文使用量的大致占比:
- 低(<50%) — 正常继续操作
- 中(50–70%) — 在状态中标记,谨慎推进(避免加载大文件)
- 高(>70%) — 立即触发,再继续后续操作
context-window-management
估算方法:统计近期消息、已加载文件内容、活跃任务上下文的大致token数量。
Step 3: After Compaction
步骤3:上下文压缩后
- Increment in state
compaction_count - Write ,
last_compacted_at(passed fromstrategy_used)context-window-management - Reset mental estimate to ~20% (post-compaction baseline)
- 状态中的计数+1
compaction_count - 写入、
last_compacted_at(从strategy_used传入)context-window-management - 将预估用量重置为约20%(压缩后基线值)
Step 4: Session End
步骤4:会话结束
Update state: , timestamp.
status: idlesession_end更新状态:、 时间戳。
status: idlesession_endKey Principles
核心原则
- The 70% threshold is the trigger — earlier is always better than later
- Check budget BEFORE loading large files or running subagents, not after
- If in doubt: compact. A clean context costs less than a confused one.
- Works best paired with — check budget at every checkpoint
long-running-task-management
- 70%为固定触发阈值,提前行动永远优于延后处理
- 请在加载大文件或运行subagent前检查预算,而非操作完成后再检查
- 存疑时直接压缩:干净上下文的成本远低于混乱上下文带来的损失
- 与搭配使用效果最佳,在每个检查点都需检查预算
long-running-task-management