Session Rotate 80
Overview
Trigger a standard
[NEW_SESSION] message when context usage reaches 80%.
This skill is memory-system-agnostic and works in plain default OpenClaw setups.
Workflow
- 1. Read current context usage from runtime status.
- Run
scripts/context_guard.py <used_tokens> <max_tokens>. - If threshold reached, output the new-session trigger and handoff hint.
- Keep old session only for short handoff, then continue in new session.
Command
CODEBLOCK0
Example:
CODEBLOCK1
Expected Output
At or above threshold:
- - INLINECODE2
- INLINECODE3
- INLINECODE4
Below threshold:
Integration Hint (Heartbeat)
In heartbeat flow, after reading context usage:
- 1. Call
context_guard.py. - If
[ROTATE_NEEDED], emit [NEW_SESSION]... directly. - Stop handling new tasks in old session except handoff confirmation.
scripts/
- -
scripts/context_guard.py: threshold detector and trigger emitter (no memory dependency).
技能名称: session-rotate-80
详细描述:
会话轮转 80
概述
当上下文使用率达到80%时,触发标准的[NEW_SESSION]消息。
该技能与记忆系统无关,适用于普通的默认OpenClaw配置。
工作流程
- 1. 从运行时状态读取当前上下文使用量。
- 运行scripts/context_guard.py <已用令牌数> <最大令牌数>。
- 如果达到阈值,输出新会话触发器和交接提示。
- 仅保留旧会话用于简短交接,然后在新会话中继续。
命令
bash
python scripts/context_guard.py <已用令牌数> <最大令牌数> --threshold 0.8 --channel boss
示例:
bash
python scripts/context_guard.py 220000 272000 --threshold 0.8 --channel boss
预期输出
达到或超过阈值时:
- - [ROTATENEEDED]
- [NEWSESSION] 上下文达到80%(已用/最大),自动切换新会话
- [HANDOFF_HINT] ...
低于阈值时:
- - [ROTATENOTNEEDED] 比率=x.xx < 0.800
集成提示(心跳机制)
在心跳流程中,读取上下文使用量后:
- 1. 调用contextguard.py。
- 如果返回[ROTATENEEDED],直接发出[NEW_SESSION]...。
- 除交接确认外,停止在旧会话中处理新任务。
scripts/
- - scripts/context_guard.py:阈值检测器和触发器发射器(无记忆依赖)。