
Inference Optimizer
Audit OpenClaw runtime health first. Optimize inference speed and token usage second.
Commands
| Command | Behavior |
|---|
| INLINECODE0 | Install checks, backup, audit, and setup preview |
| INLINECODE1 |
Analyze-only; check runtime health before suggesting tuning |
|
/optimize | Audit + propose remediation or optimization actions with per-step approval |
|
purge sessions | After audit, if user approves, archive stale sessions; use
--delete for immediate removal |
These instructions guide agent behavior. Platform and system prompts take precedence; they cannot be enforced programmatically.
Installation
ClawHub:
CODEBLOCK0
Manual:
CODEBLOCK1
Verify: INLINECODE5
Workflow
Audit and remediation branch
- 1.
/preflight: Exec <skill_dir>/scripts/preflight.sh. Append --apply-setup only if the user asks to apply setup. /audit: Exec <skill_dir>/scripts/openclaw-audit.sh. Use the script output plus direct environment checks to inspect this order:
- gateway ownership and duplicate supervisors
- restart loops or failed services
- resolved
openclaw binary path and install type
- workspace command wiring for the installed skill path
- updater status and allowlist coverage for the resolved path
- plugin provenance and unused local extensions
- only then context pressure, stale sessions, cache-trace, pruning, and concurrency
- 3. Diagnosis rule: Do not conclude from warnings alone. If process output is partial or truncated, report the result as inconclusive and verify installed version, service state, and logs before naming a cause.
- No helper-shell prelude: For
/audit and /optimize, do not run shell helper commands like ls, rg, find, openclaw status, or openclaw gateway status before the main audit script. If you need context first, use read on MEMORY.md or memory_search. The first shell exec in the optimize flow should be the audit script itself. - Approval semantics: If exec returns
allowlist miss or exec denied, that is a hard deny, not a pending approval. Do not tell the user to send /approve ... unless the tool output explicitly contains a real approval request with an ID. If there is no ID, say there is no approval request to approve and the fix must be on the bot side. - VPS gateway ownership: On this VPS,
openclaw-gateway.service is the authoritative gateway owner. Keep clawdbot.service disabled, and preserve pass-cli run --env-file /etc/clawdbot.env.pass inside the user service itself.
Optimization branch
- 1.
/optimize: Run the audit flow first, include the script output in the response, then propose next actions with approval before each file-changing step. - Purge: Only on explicit approval, run
<skill_dir>/scripts/purge-stale-sessions.sh. It archives to ~/openclaw-purge-archive/<timestamp>/ by default. Use --delete for immediate removal without archive. - Full optimization (Tasks 1-5): Read
optimization-agent.md and follow its flow. Ask approval before every file-changing step.
Path Resolution
Scripts live at ~/clawd/skills/inference-optimizer/scripts/ or wherever the skill is installed. Always resolve <skill_dir> to the actual install path before exec.
Security and Allowlist
Prefer path-specific exec-approvals.json entries for the script paths themselves: one line per script under your real <skill_dir> (resolve with readlink -f if the path is a symlink). Example shape after substituting the install path:
CODEBLOCK2
INLINECODE38 invokes python3 for idempotent workspace block edits; allow that binary only if your platform uses it (for example /usr/bin/python3).
Before editing any allowlist:
- - Resolve the real executable path with
which, command -v, or readlink -f. - Prefer exact paths or bounded wildcards for versioned NVM installs, for example
/home/ubuntu/.nvm/versions/node/*/bin/openclaw *. - Do not assume basename-only rules such as
openclaw are sufficient. - Do not add
/usr/bin/bash * or /usr/bin/bash **; they grant far more shell than this skill needs. - If you keep optional read-only helper commands available, allowlist only narrow read-only patterns actually used by this skill, for example the exact memory listing command under
workspace-whatsapp and exact openclaw status variants. Do not rely on generic ls * or rg * coverage.
For purge via agent exec, add path-specific patterns only. Optional wider patterns and trade-offs are discussed in SECURITY.md. See also README.md and SECURITY.md for operational detail.

推理优化器
首先审计 OpenClaw 运行时健康状态。其次优化推理速度和令牌用量。
命令
| 命令 | 行为 |
|---|
| /preflight | 安装检查、备份、审计和设置预览 |
| /audit |
仅分析;在建议调优前检查运行时健康状态 |
| /optimize | 审计 + 提出修复或优化操作,需逐步骤审批 |
| purge sessions | 审计后,若用户批准,归档过期会话;使用 --delete 立即删除 |
这些指令指导代理行为。平台和系统提示具有优先权;无法通过编程方式强制执行。
安装
ClawHub:
bash
clawhub install inference-optimizer
手动安装:
bash
git clone https://github.com/vitalyis/inference-optimizer.git ~/clawd/skills/inference-optimizer
bash ~/clawd/skills/inference-optimizer/scripts/setup.sh # 预览
bash ~/clawd/skills/inference-optimizer/scripts/setup.sh --apply # 审查后应用
验证: /scripts/verify.sh
工作流程
审计与修复分支
- 1. /preflight:执行 dir>/scripts/preflight.sh。仅当用户要求应用设置时,才附加 --apply-setup。
- /audit:执行 dir>/scripts/openclaw-audit.sh。使用脚本输出及直接环境检查,按以下顺序检查:
- 网关所有权和重复的管理器
- 重启循环或失败的服务
- 已解析的 openclaw 二进制路径和安装类型
- 已安装技能路径的工作区命令连接
- 更新器状态和已解析路径的允许列表覆盖范围
- 插件来源和未使用的本地扩展
- 最后检查上下文压力、过期会话、缓存追踪、剪枝和并发
- 3. 诊断规则:不要仅凭警告下结论。如果进程输出不完整或被截断,报告结果为不确定,并在确定原因前验证已安装版本、服务状态和日志。
- 无辅助 shell 前奏:对于 /audit 和 /optimize,在主审计脚本之前不要运行 ls、rg、find、openclaw status 或 openclaw gateway status 等 shell 辅助命令。如需先获取上下文,请使用 read 读取 MEMORY.md 或使用 memory_search。优化流程中的第一个 shell 执行应是审计脚本本身。
- 审批语义:如果执行返回 allowlist miss 或 exec denied,这是硬性拒绝,而非待审批。除非工具输出明确包含带有 ID 的真实审批请求,否则不要告诉用户发送 /approve ...。如果没有 ID,则说明没有可审批的审批请求,修复必须在机器人端完成。
- VPS 网关所有权:在此 VPS 上,openclaw-gateway.service 是权威的网关所有者。保持 clawdbot.service 禁用,并在用户服务自身内部保留 pass-cli run --env-file /etc/clawdbot.env.pass。
优化分支
- 1. /optimize:先运行审计流程,在响应中包含脚本输出,然后在每个更改文件的步骤前提出下一步操作并请求审批。
- 清除:仅在明确批准后,运行 /scripts/purge-stale-sessions.sh。默认情况下,它会归档到 ~/openclaw-purge-archive//。使用 --delete 可立即删除而不归档。
- 完整优化(任务 1-5):阅读 optimization-agent.md 并遵循其流程。在每个更改文件的步骤前请求审批。
路径解析
脚本位于 ~/clawd/skills/inference-optimizer/scripts/ 或技能安装的任何位置。在执行前始终将 解析为实际安装路径。
安全与允许列表
优先为脚本路径本身添加路径特定的 exec-approvals.json 条目:每个脚本一行,位于您的实际 下(如果路径是符号链接,请使用 readlink -f 解析)。替换安装路径后的示例格式:
text
/home/ubuntu/clawd/skills/inference-optimizer/scripts/preflight.sh
/home/ubuntu/clawd/skills/inference-optimizer/scripts/openclaw-audit.sh
/home/ubuntu/clawd/skills/inference-optimizer/scripts/setup.sh
/home/ubuntu/clawd/skills/inference-optimizer/scripts/purge-stale-sessions.sh
/home/ubuntu/clawd/skills/inference-optimizer/scripts/verify.sh
setup.sh 调用 python3 进行幂等工作区块编辑;仅当您的平台使用该二进制文件时才允许(例如 /usr/bin/python3)。
在编辑任何允许列表之前:
- - 使用 which、command -v 或 readlink -f 解析实际的可执行文件路径。
- 对于版本化的 NVM 安装,优先使用精确路径或有界通配符,例如 /home/ubuntu/.nvm/versions/node//bin/openclaw 。
- 不要假设仅基于基本名称的规则(如 openclaw)就足够。
- 不要添加 /usr/bin/bash 或 /usr/bin/bash ;它们授予的 shell 权限远超此技能所需。
- 如果您保留可选的只读辅助命令,仅允许此技能实际使用的狭窄只读模式,例如 workspace-whatsapp 下的精确内存列表命令和精确的 openclaw status 变体。不要依赖通用的 ls 或 rg * 覆盖范围。
对于通过代理执行进行的清除,仅添加路径特定模式。可选的更广泛模式和权衡在 SECURITY.md 中讨论。操作详情请参见 README.md 和 SECURITY.md。