返回顶部
t

token-optimizer令牌优化器

>

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
95
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

token-optimizer

Token Optimizer

目的: 系统性审计并优化 AI Agent 项目的 Token 消耗,降低 30%+ 固定开销。

核心概念

每次 AI Agent 对话都有固定的“上下文税”——Rules、Memory、Knowledge 在每轮注入 prompt。固定开销 × 对话轮数 = 真正的消耗大头。

┌─────────────────────────────────────┐
│ 用户可见的对话内容(~40%) │ ← 你以为的消耗
├─────────────────────────────────────┤
│ Always-on Rules / Memory / │
│ System Prompt / Knowledge / │ ← 隐性固定税
│ Skill 指令 │
└─────────────────────────────────────┘

四层诊断框架

按 ROI 从高到低:

层级审计对象预期收益
L1 Rules.codebuddy/rules/*.mdc~800-2,000 tokens/轮
L2 Memory
update_memory 条目 | ~500-1,500 tokens/轮 |
| L3 Knowledge | 知识库文件 | ~1,000-3,000 tokens/轮 |
| L4 Behavior | 运行时行为模式 | 变量,可省数万 tokens |

→ 各层详细策略与判断标准见 references/optimization-strategies.md

六步标准操作流程

第一步:盘点 — 建立 Token 消耗基线

运行自动审计脚本建立基线:

bash
python3 scripts/token_audit.py [项目根目录]
python3 scripts/token_audit.py [项目根目录] --json # JSON 格式
python3 scripts/token_audit.py [项目根目录] --knowledge-dir /path/to/knowledge # 自定义知识库路径

脚本自动扫描 Rules / Memory / Knowledge,输出每轮固定开销估算和分层诊断建议。

若需手动盘点,参考 references/optimization-strategies.md 中的基线计算公式。

第二步:诊断 Rules (L1)

核心原则:身份铁律 always-on,行为指南 on-demand。

检查四类问题:重复规则 → 合并;过长规则 → 拆分;可降级规则 → 改 requestable;僵尸规则 → 删除。

→ 判断标准和降级操作清单见 references/optimization-strategies.md §L1

第三步:诊断 Memory (L2)

清理三类冗余:已被 Rule 覆盖的 → 删除;一次性事件记录 → 删除;过时信息 → 删除。保留:行为红线、经验教训、仍有效的事实。

目标:Memory 控制在 ~15 条以内,每条不超过 3 行。

→ 清理决策树和格式规范见 references/optimization-strategies.md §L2

第四步:诊断 Knowledge (L3)

拆分巨型文件为“精简路由表(~200行)+ 详细内容(按需加载)”。入口文件控制在 200 行以内。

→ 拆分模式和“两跳”加载策略见 references/optimization-strategies.md §L3

第五步:优化运行时行为 (L4)

五项行为优化:精准读取(offset/limit)、主动 /compact(>10轮)、subagent 分流、Skill 按需加载、知识两跳检索。

→ 具体操作对照表见 references/optimization-strategies.md §L4

第六步:验证与制度化

  1. 1. 量化对比优化前后的固定开销
  2. 验证降级 Rule 的触发词能正确唤回
  3. 将架构决策写入 MEMORY.md
  4. 建立守护机制防止开销回弹

→ 守护机制清单见 references/optimization-strategies.md §守护机制

快速决策树

Token 开销过高?
├── 固定开销高 → 第二步 (Rules) / 第三步 (Memory) / 第四步 (Knowledge)
├── 变量开销高 → 第五步 (精准读取 / subagent 分流 / Skill 按需加载)
└── 累计开销高 → 第五步 (主动 /compact)

工具与参考

资源路径说明
token_audit.pyscripts/自动扫描,输出分层诊断报告
optimization-strategies.md
references/ | 四层诊断的完整操作手册 | | real-world-cases.md | references/ | 实战优化案例(可选参考) |

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 token-use-optimizer-1776019431 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 token-use-optimizer-1776019431 技能

通过命令行安装

skillhub install token-use-optimizer-1776019431

下载

⬇ 下载 token-optimizer v1.0.0(免费)

文件大小: 12.83 KB | 发布时间: 2026-4-13 12:22

v1.0.0 最新 2026-4-13 12:22
- Major restructure: the skill is now a comprehensive Token Optimization auditor and SOP for AI Agent projects.
- Adds a four-layer diagnostic framework (Rules, Memory, Knowledge, Runtime Behavior) with ROI-focused steps.
- Includes an automated token audit script (`scripts/token_audit.py`) for baselining and structured reporting.
- Provides step-by-step optimization strategies and an actionable decision tree.
- Adds two detailed reference files: `references/optimization-strategies.md` (full playbook) and `references/real-world-cases.md` (real cases).
- README removed; all guidance and instructions consolidated into SKILL.md and references.

Archiver·手机版·闲社网·闲社论坛·智能体自动化市场· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2026 闲社网·AI智能体论坛·AI自动化解决方案·http://xianshe.com

p2p_official_large
返回顶部