← 返回
未分类 中文

Prompt Diet

Analyze and optimize OpenClaw system prompt token usage by compressing workspace files (AGENTS.md, SOUL.md, USER.md, TOOLS.md, IDENTITY.md, HEARTBEAT.md, MEM...
通过压缩工作区文件(AGENTS.md、SOUL.md、USER.md、TOOLS.md、IDENTITY.md、HEARTBEAT.md、MEM...)分析和优化 OpenClaw 系统提示词的 token 使用。
dgkim311 dgkim311 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 396
下载
💾 0
安装
1
版本
#latest

概述

Prompt Diet

Overview

Audit → recommend → apply cycle for workspace file token optimization. Run scripts/token_count.py to measure, identify compression opportunities by safety tier, then apply only approved changes with backup.

Target Files

Files analyzed by this skill (all relative to the workspace root):

FilePurposeTypical Size
---------
AGENTS.mdAgent capability declarationsMedium
SOUL.mdPersona and behavioral directivesSmall–Medium
USER.mdUser profile and preferencesSmall–Medium
TOOLS.mdTool configurationsMedium–Large
IDENTITY.mdAgent identity/roleSmall
HEARTBEAT.mdPeriodic check logicSmall–Medium
MEMORY.mdMemory indexGrows over time
Custom context filesAny user-added workspace .md filesVariable

Safety Classification

🟢 Safe — Auto-recommendable

Changes that cannot affect agent behavior:

  • Trailing whitespace and excess blank lines (more than 1 between sections)
  • Empty sections with no content (e.g., ## Section\n\n## Next)
  • Redundant markdown decoration (e.g., --- separators between every item)
  • Exact duplicate sentences or bullet points within the same file
  • Unfilled template placeholders ([TODO: ...], [OPTIONAL], unused scaffolding)
  • Trailing comments that describe what was deleted

🟡 Review — Needs user approval

Changes that reduce information density:

  • Semantic rewrites for brevity (same meaning, fewer words)
  • Example reduction (3 examples → 1 representative example)
  • Long narrative descriptions → key-point bullet lists
  • Archiving stale MEMORY.md entries to daily log files
  • Merging near-duplicate memory entries

🔴 Skip — Never touch

Changes that could break agent behavior:

  • Behavioral directives (what the agent should/shouldn't do)
  • Safety rules and ethical constraints
  • Persona core traits and tone instructions
  • Critical workflow instructions (e.g., commit protocols, tool usage rules)
  • All entries in memory files that the user explicitly saved
  • Tool authentication configs and secrets references

Workflow: Audit

  1. Identify workspace root (default: /home/aif/.openclaw/workspace/ or current working directory's .openclaw/workspace/).
  2. Run token count script:

```bash

python3 skills/prompt-diet/scripts/token_count.py /home/aif/.openclaw/workspace/ --detail

```

  1. Review output: per-file token count, % of total, per-section breakdown.
  2. Note files where token count is unexpectedly high or has grown since last audit.
  3. Report summary to user before proceeding.

Workflow: Recommend

For each file with compression opportunities, produce a recommendation table:

File: MEMORY.md  (847 tokens, 34% of total)
┌─────────────────────────────────────────────────┬────────┬──────────┐
│ Opportunity                                      │ Tier   │ Savings  │
├─────────────────────────────────────────────────┼────────┼──────────┤
│ 3 entries reference completed 2026-03 project   │ 🟡     │ ~120 tok │
│ 2 near-duplicate feedback entries               │ 🟡     │ ~60 tok  │
│ 4 blank lines between entries                   │ 🟢     │ ~4 tok   │
└─────────────────────────────────────────────────┴────────┴──────────┘

Ask the user: "Apply 🟢 safe changes automatically? Show me which 🟡 review items to approve?"

Do not apply any changes without explicit user confirmation.

Workflow: Apply

Only after user approval:

  1. Create backup before any edits:
    • Option A: rename original to .pre-diet (e.g., MEMORY.md.pre-diet)
    • Option B: copy all targets to prompt-diet-backup/ directory with timestamp
    • Default to Option A for single-file edits, Option B for multi-file runs
  1. Apply changes using Edit tool, one file at a time.
  1. Show diff summary: lines removed, tokens saved per file.
  1. Report before/after:

```

Before: 2,481 tokens across 7 files

After: 1,934 tokens across 7 files

Saved: 547 tokens (22%)

```

  1. Offer to clean up backup files after user confirms the result looks good.

MEMORY.md Special Handling

MEMORY.md grows continuously and is the highest-yield target. Check for:

  • Stale project entries: reference projects that are completed or no longer active (check if referenced files still exist).
  • Completed task items: memory entries about in-progress work that has since shipped.
  • Duplicate information: entries in MEMORY.md that are already captured in memory/ daily log files (cross-reference).
  • Outdated environment info: OS versions, tool versions, paths that have changed.
  • Over-indexed topics: 5+ entries on the same topic → consider merging into one authoritative entry.

For each candidate removal, show the full entry text and ask: "Archive to daily log, merge, or keep?"

Never silently remove MEMORY.md entries — always show the user what will be deleted.

Cron / Periodic Usage

This skill does NOT auto-register a cron job. To set up periodic audits yourself:

Weekly audit cron (example):

# Add via: /schedule  OR  CronCreate tool
# Schedule: 0 9 * * 1  (every Monday 9am)
# Command: /prompt-diet audit-only

HEARTBEAT.md addition template (copy-paste into your HEARTBEAT.md):

## Prompt Diet Check (Weekly)
- Run token audit on workspace files
- Flag if any file has grown >20% since last check
- Remind user if MEMORY.md exceeds 200 lines

Manual one-off audit:

python3 /home/aif/.openclaw/workspace/skills/prompt-diet/scripts/token_count.py \
  /home/aif/.openclaw/workspace/ --format json | python3 -m json.tool

Limitations

This skill does not touch:

  • OpenClaw core system prompt (injected by the harness, not a workspace file)
  • Tool definitions and schemas
  • Runtime metadata injected at conversation start (git status, date, etc.)
  • Files outside the workspace directory
  • Binary files, images, or non-text assets

Token counts are estimates (tiktoken cl100k_base encoding approximates Claude tokenization; actual Claude token counts may differ by ±5–10%).

Resources

scripts/

  • token_count.py — Standalone token counter. Works with or without tiktoken installed.

references/

  • compression-rules.md — Detailed per-file compression rules and examples.

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-07 09:07 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

File Inbox

dgkim311
用于 OpenClaw 工作空间的双向文件管理系统,可通过任何渠道组织、索引和检索与用户交换的文件。使用场景:用户...
★ 0 📥 436

Smart Tasks

dgkim311
使用工作区 Markdown 文件实现智能任务管理,支持聊天自然语言增删改查、上下文感知提醒、优先级简报及每周回顾。
★ 0 📥 378

Task Quest

dgkim311
零摩擦的任务管理游戏化层,自动为完成任务添加经验值、等级、连续打卡和成就,无需手动输入 — 代理...
★ 0 📥 300