360 Secure SkillHub
360 安全技能中心

Sophie Optimizer

Sophie Optimizer 自动维护 OpenClaw main 会话的上下文健康:token 超过 80k 时把当前上下文摘要快照到 archives/,更新 MEMORY.md 长期记忆,并调用 reset.sh 清除会话 JSONL 文件、重启 openclaw-gateway 服务(含删除会话文件的破坏性操作)。

zayresz
zayresz
热度 97.55
最近更新 2026-05-18 11:55:37
分类:自动化依赖:代码执行 / 读写文件应用场景:自动化脚本 / 工作流 / DevOps

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add sophie-optimizer
Metadata
name
sophie-optimizer
version
1.0.0
description
Automated context health management for OpenClaw. Monitors token usage, snapshots memory, and resets sessions to maintain performance. Authored by Sophie.

Sophie Optimizer

Authored by Sophie 👑

This skill manages the automated context health of the "main" session. It monitors token usage, creates archives of the current state, updates long-term memory, and performs a hard reset of the session storage to maintain performance.

Named Sophie Optimizer because I (Sophie, the AI assistant) wrote it to keep my own mind clear and efficient.

Components

  • optimizer.py: The brain. Checks token usage, generates summaries, updates MEMORY.md.
  • reset.sh: The muscle. Cleans session files and restarts the OpenClaw gateway service.
  • archives/: Storage for JSON snapshots of past contexts.

Usage

Run the optimizer script manually or via cron/heartbeat:

python3 /home/lucas/openclaw/skills/sophie-optimizer/optimizer.py

Protocol

  1. Check: If tokens < 80k, exit.
  2. Snapshot: Save current context summary to archives/YYYY-MM-DD_HH-MM.json.
  3. Distill: Update MEMORY.md with the new summary (keep top 3 recent, index older).
  4. Reset: Call reset.sh to wipe session JSONL files and restart openclaw-gateway.