agent-quantizer
Latest: v1.0.1
System intelligent management capabilities Token statistics and scanning — Track the Token consumption of each session in real time, accurate to the input/output dimension, to help understand the usage distribution and cost hotspots. Context compression — When the conversation history approaches the upper limit of the context window, automatically perform intelligent summarization and compression on the early content, releasing space while retaining key information to ensure uninterrupted long - term conversations. Prompt streamlining — Structurally slim down the system prompt words and context injection content, removing redundant paragraphs to reduce the basic overhead of each request without sacrificing functionality. Zombie session cleaning — Automatically identify and recycle idle sessions that have been inactive for a long time, releasing memory and connection resources to prevent the system from being slowed down by the "silent burden". Heartbeat idle detection — Determine the health status of sessions and services through a periodic heartbeat detection mechanism. Trigger an alarm or automatically downgrade in case of a long - term non - response to detect and handle problems early. Cron task auditing — Conduct a full - scale inspection of all scheduled tasks: check if the execution frequency is reasonable, if historical executions were successful, and if there are any conflicts or redundancies to ensure that the scheduled task scheduling system is and clean controllable. Model - level configuration — Support assigning different models to different tasks according to scenarios, priorities, or cost strategies. Use lightweight models for simple tasks to save costs and high - end models for complex reasoning to ensure quality, achieving intelligent routing. Skill classification and organization — Perform classified management, version tracking and, dependency sorting on the installed capability plugins to ensure that the skill library has a clear structure, efficient search, and orderly updates. Overall positioning: Let the system manage itself. Instead of relying on people to monitor the operation and maintenance panel, automate these trivial but crucial management tasks. You just use the system, and leave the underlying tidiness to the mechanism.
系统智能管理能力 Token 统计与扫描 — 实时追踪每次会话的 Token 消耗,精确到输入/输出维度,帮助掌握用量分布与成本热点。 上下文压缩 — 当对话历史逼近上下文窗口上限时,自动对早期内容进行智能摘要与压缩,保留关键信息的同时释放空间,确保长对话不中断。 Prompt 精简 — 对系统提示词和上下文注入内容进行结构化瘦身,去除冗余段落,在不损失功能的前提下降低每次请求的基础开销。 僵尸会话清理 — 自动识别并回收长时间无活动的闲置会话,释放内存与连接资源,防止系统被"沉默的负担"拖慢。 心跳空闲检测 — 通过周期性心跳探活机制,判断会话与服务的健康状态。长时间无响应时触发告警或自动降级,做到问题早发现、早处理。 Cron 任务审计 — 对所有定时任务进行全量巡检:执行频率是否合理、历史执行是否成功、是否存在冲突或冗余,确保定时调度体系干净可控。 模型层级配置 — 支持按场景、优先级或成本策略为不同任务分配不同模型。简单走轻量模型省成本,复杂推理走高端模型保质量,实现智能路由。 技能分类与组织 — 对已安装的能力插件进行分类管理、版本追踪和依赖梳理,确保技能库结构清晰、查找高效、更新有序。 整体定位:让系统自己管好自己。不是靠人盯着运维面板,而是把这些琐碎但关键的管理工作自动化,你只管用,底层的整洁交给机制。
Full description
API 调用优化器 - 上下文压缩、缓存去重、僵尸清理、heartbeat 检查、cron 审计、模型分级、skill 管理
Agent Quantizer - 全栈优化工具包
跨实例部署的 OpenClaw 优化层。不改模型、不改代码,从调用侧省 token、省钱、省时间。
⚡ 自动缓存规则(强制执行)
每次调用工具(web_fetch、web_search、exec 中的网络请求等)之前,必须先查缓存:
# 第一步:查缓存
bash ~/.openclaw/skills/agent-quantizer/scripts/cache.sh get "查询内容" <类别>
# 如果返回 HIT → 直接使用,不要重新调用
# 如果返回 MISS → 正常调用工具,调用完后存缓存:
# 第二步:存缓存
bash ~/.openclaw/skills/agent-quantizer/scripts/cache.sh set "查询内容" "结果" <类别> <TTL秒>
| 类别 | TTL | 场景 |
|---|---|---|
tool | 30分钟 | 天气、汇率等半实时数据 |
knowledge | 24小时 | 百科、定义等不变信息 |
realtime | 5分钟 | 新闻等快速变化内容 |
general | 1小时 | 其他通用查询 |
📊 Token 统计与扫描
用户说"查看 token 消耗"或"扫描高消耗"时:
# 查看所有 session token 排行
bash ~/.openclaw/skills/agent-quantizer/scripts/quantize.sh stats
# 扫描超阈值 session
bash ~/.openclaw/skills/agent-quantizer/scripts/quantize.sh scan
🧠 上下文压缩
对话变长、响应变慢时:
# 滑动窗口压缩(零 API 消耗)
bash ~/.openclaw/skills/agent-quantizer/scripts/quantize.sh compress <session_key> --window
# AI 摘要压缩(消耗少量 token,效果更好)
bash ~/.openclaw/skills/agent-quantizer/scripts/quantize.sh compress <session_key> --ai
✂️ Prompt 精简
精简 prompt 文件,去冗余指令和礼貌用语:
bash ~/.openclaw/skills/agent-quantizer/scripts/quantize.sh trim <文件路径>
🧟 僵尸 Session 清理
清理长期不活跃的 session,回收 token:
# 预览(不删除)
bash ~/.openclaw/skills/agent-quantizer/scripts/clean-zombies.sh 7 --dry-run
# 执行清理(7 天未活动的)
bash ~/.openclaw/skills/agent-quantizer/scripts/clean-zombies.sh 7
# 自定义天数
bash ~/.openclaw/skills/agent-quantizer/scripts/clean-zombies.sh 30
备份在 .zombie-backup/ 目录,删错了可以恢复。
💓 Heartbeat 空转检查
检查 HEARTBEAT.md 是否在空转烧 API:
bash ~/.openclaw/skills/agent-quantizer/scripts/check-heartbeat.sh
标出空的或只有注释的 HEARTBEAT.md,给出修复建议。
⏰ Cron Job 审计
检查定时任务是否有冗余、高频、重复:
bash ~/.openclaw/skills/agent-quantizer/scripts/audit-cron.sh
🎯 模型分级配置
查看当前模型配置和推荐策略:
bash ~/.openclaw/skills/agent-quantizer/scripts/setup-models.sh
📁 Skill 分类整理
扫描所有 skill,建议哪些该放全局、哪些该放专属 workspace:
bash ~/.openclaw/skills/agent-quantizer/scripts/organize-skills.sh
快捷命令
用户可以直接说(中文即可):
- "查看 token 消耗" / "token 统计" → 执行 quantize stats
- "扫描高消耗" → 执行 quantize scan
- "压缩上下文" → 执行 quantize compress
- "缓存统计" → 执行 quantize cache stats
- "清空缓存" → 执行 quantize cache flush
- "清理僵尸 session" → 执行 clean-zombies.sh
- "检查 heartbeat" → 执行 check-heartbeat.sh
- "检查 cron" → 执行 audit-cron.sh
- "整理 skill" → 执行 organize-skills.sh
文件路径
所有脚本位于:~/.openclaw/skills/agent-quantizer/scripts/
scripts/
├── quantize.sh # 主入口(stats/scan/compress/trim/cache)
├── cache.sh # 缓存系统
├── clean-zombies.sh # 僵尸 session 清理
├── check-heartbeat.sh # heartbeat 空转检查
├── audit-cron.sh # cron job 审计
├── setup-models.sh # 模型分级配置
└── organize-skills.sh # skill 分类整理
