← Back to Skills Marketplace
chungvic

Agent Optimize

by chungvic · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ⚠ suspicious
92
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install agent-optimize
Description
Agent 優化診斷技能。分析 OpenClaw 運行狀態,識別信息過載、上下文堆積、技能噪音等問題。 提供系統級優化方案,實現瘦身提速,解決"貴慢亂"困擾。 Use when: (1) Agent 響應變慢, (2) 上下文過長導致效率低下, (3) 技能加載過多造成噪音, (4) 需要診斷性能瓶頸, (5)...
README (SKILL.md)

🩺 Agent Optimize - Agent 優化診斷技能

"不是模型不行,而是上下文堆積或技能噪音導致效率低下。"

Agent Optimize 是一個系統級體檢顧問,幫助你診斷 OpenClaw 的"信息過載"問題,找出拖慢點,提供優化方案,實現系統級瘦身。

核心問題診斷

1. 上下文堆積 (Context Bloat)

症狀:

  • Agent 響應變慢
  • Token 使用量激增
  • 模型成本上升

診斷方法:

# 檢查會話歷史大小
find ~/.openclaw/sessions -name "*.json" -exec wc -l {} \; | sort -rn | head -10

# 檢查記憶文件總大小
du -sh ~/.openclaw/workspace/*/memory/** 2>/dev/null

優化方案:

  • 清理舊會話歷史(保留最近 7 天)
  • 壓縮記憶文件(歸檔超過 30 天的記錄)
  • 設置上下文長度限制

2. 技能噪音 (Skill Noise)

症狀:

  • 加載不必要技能
  • 技能衝突
  • 技能冗餘

診斷方法:

# 列出所有已安裝技能
find ~/.npm-global/lib/node_modules/openclaw/skills -maxdepth 1 -type d | wc -l
find ~/.openclaw/workspace*/skills -maxdepth 2 -type d | wc -l

# 檢查技能依賴
grep -r "requires" ~/.openclaw/workspace*/skills/*/SKILL.md | head -20

優化方案:

  • 禁用未使用技能
  • 合併重復功能技能
  • 優化技能加載順序

3. 記憶冗餘 (Memory Redundancy)

症狀:

  • 記憶文件重複
  • 未清理的臨時文件
  • 過期的日誌記錄

診斷方法:

# 查找重複記憶文件
find ~/.openclaw/workspace*/memory -name "*.md" -exec md5sum {} \; | sort | uniq -d

# 檢查記憶文件大小
find ~/.openclaw/workspace*/memory -name "*.md" -exec wc -l {} \; | sort -rn | head -10

優化方案:

  • 合併重複記憶
  • 刪除臨時文件
  • 歸檔舊記憶

4. 配置衝突 (Config Conflicts)

症狀:

  • 多個配置文件
  • 配置值衝突
  • 過期配置項

診斷方法:

# 查找所有配置文件
find ~/.openclaw -name "*.json" -path "*/config*" 2>/dev/null
find ~/.openclaw -name ".env*" 2>/dev/null

# 檢查配置重複
grep -r "model" ~/.openclaw/*.json 2>/dev/null | head -10

優化方案:

  • 合併配置文件
  • 統一配置源
  • 清理過期配置

使用方法

基本用法

# 運行完整診斷
node index.js

# 僅檢查上下文
node index.js --context

# 僅檢查技能
node index.js --skills

# 僅檢查記憶
node index.js --memory

# 僅檢查配置
node index.js --config

# 生成優化報告
node index.js --report

高級用法

# 深度診斷(更詳細)
node index.js --deep

# 自動應用安全優化
node index.js --auto-fix

# 輸出 JSON 格式
node index.js --json

# 輸出 Feishu 卡片格式
node index.js --feishu-card

# 指定工作區
node index.js --workspace /path/to/workspace

診斷報告結構

1. 執行摘要

## 📊 Agent 健康狀態

**總體評分:** 75/100 (需要優化)

**關鍵問題:**
- ⚠️ 上下文堆積:超過 5000 行
- ⚠️ 技能冗餘:12 個未使用技能
- ✅ 記憶狀態:良好
- ⚠️ 配置衝突:2 處重複配置

2. 詳細分析

上下文分析

當前會話數量:45
總會話大小:125 MB
平均會話長度:2,777 行
最大會話:15,432 行 (需要清理)

建議:
- 刪除超過 30 天的會話(可釋放 80 MB)
- 壓縮超過 7 天的會話(可釋放 30 MB)

技能分析

已安裝技能總數:67
活躍技能(最近 7 天使用):23
未使用技能:44
技能衝突:2 對

建議:
- 禁用 44 個未使用技能
- 解決 2 對技能衝突

記憶分析

記憶文件總數:156
總大小:45 MB
重複文件:8
過期文件(>90 天):23

建議:
- 合併 8 個重複文件
- 歸檔 23 個過期文件

配置分析

配置文件數量:12
重複配置項:5
過期配置項:3

建議:
- 合併配置文件
- 清理過期配置

3. 優化方案

即時優化(安全,可自動應用)

  1. 清理臨時文件 - 預計釋放 15 MB
  2. 歸檔舊會話 - 預計釋放 50 MB
  3. 禁用未使用技能 - 減少加載時間 30%

手動優化(需要確認)

  1. 合併重複記憶文件
  2. 解決技能衝突
  3. 重構配置文件

長期優化(建議)

  1. 設置自動清理 cron
  2. 實施技能白名單
  3. 建立記憶歸檔策略

自動化優化

設置定時清理

# 添加每日清理任務
clawdbot cron add \
  --name "Agent Optimization" \
  --cron "0 3 * * *" \
  --tz "Asia/Shanghai" \
  --session isolated \
  --message "Run agent-optimize with --auto-fix --report"

設置監控警報

# 當上下文超過閾值時警報
clawdbot cron add \
  --name "Context Monitor" \
  --cron "0 */6 * * *" \
  --message "Check context size, alert if > 10000 lines"

配置選項

配置項 預設值 說明
OPTIMIZE_MAX_CONTEXT_LINES 5000 單次分析最大上下文行數
OPTIMIZE_REPORT_FORMAT markdown 報告格式 (markdown/json/feishu-card)
OPTIMIZE_AUTO_FIX false 自動應用安全優化
OPTIMIZE_BACKUP_BEFORE_FIX true 優化前備份
OPTIMIZE_RETENTION_DAYS 30 會話保留天數
OPTIMIZE_MEMORY_ARCHIVE_DAYS 90 記憶歸檔天數

輸出示例

Markdown 報告

# Agent 優化診斷報告

**生成時間:** 2026-04-03 09:30:00
**工作區:** /home/admin/.openclaw/workspace-skill-dev

## 📊 總體狀態

評分:75/100

## ⚠️ 發現問題

1. 上下文堆積 (嚴重)
2. 技能冗餘 (中等)
3. 配置重複 (輕微)

## ✅ 優化建議

[詳細建議列表]

JSON 報告

{
  "timestamp": "2026-04-03T09:30:00Z",
  "workspace": "/home/admin/.openclaw/workspace-skill-dev",
  "score": 75,
  "issues": [
    {
      "type": "context_bloat",
      "severity": "high",
      "details": {...}
    }
  ],
  "recommendations": [...]
}

安全規範

自動優化限制

允許自動執行:

  • ✅ 清理臨時文件
  • ✅ 歸檔舊會話
  • ✅ 壓縮日誌文件
  • ✅ 刪除空文件

需要用戶確認:

  • ⚠️ 刪除會話歷史
  • ⚠️ 禁用技能
  • ⚠️ 修改配置文件
  • ⚠️ 合併記憶文件

備份策略

# 優化前自動備份
backup_dir="/tmp/agent-optimize-backup-$(date +%Y%m%d-%H%M%S)"
mkdir -p "$backup_dir"
cp -r ~/.openclaw/workspace/*/memory "$backup_dir/"
cp -r ~/.openclaw/sessions "$backup_dir/"

故障排除

問題:診斷運行緩慢

原因: 上下文太大

解決方案:

# 限制分析範圍
node index.js --max-lines 2000

# 或僅分析特定目錄
node index.js --target ~/.openclaw/workspace-skill-dev

問題:報告生成失敗

原因: 權限不足

解決方案:

# 檢查權限
ls -la ~/.openclaw/workspace*/memory

# 修復權限
chmod -R u+rw ~/.openclaw/workspace*/memory

問題:技能檢測不準確

原因: 技能路徑變化

解決方案:

# 更新技能路徑配置
export OPTIMIZE_SKILL_PATHS="~/.npm-global/lib/node_modules/openclaw/skills,~/.openclaw/workspace*/skills"

性能指標

診斷速度

工作區大小 診斷時間
小型 (\x3C100 MB) \x3C5 秒
中型 (100-500 MB) 5-15 秒
大型 (>500 MB) 15-30 秒

優化效果

優化項 預期改善
上下文清理 響應速度 ↑40%
技能精簡 加載時間 ↓30%
記憶歸檔 存儲空間 ↓50%
配置優化 衝突率 ↓80%

最佳實踐

1. 定期診斷

  • 每週運行一次完整診斷
  • 每日運行輕量檢查
  • 性能下降時立即診斷

2. 漸進優化

  • 先應用安全優化
  • 測試確認後再應用風險優化
  • 保留備份以便回滾

3. 監控跟蹤

  • 記錄每次優化前後指標
  • 追蹤長期趨勢
  • 調整優化策略

集成示例

與 capability-evolver 集成

// 在 evolver 中調用 agent-optimize
const optimize = require('agent-optimize');

async function beforeEvolution() {
  const report = await optimize.diagnose();
  if (report.score \x3C 60) {
    await optimize.autoFix();
  }
}

與 auto-updater 集成

// 更新後自動優化
const optimize = require('agent-optimize');

async function afterUpdate() {
  await optimize.diagnose({ report: true });
}

版本歷史

  • 1.0.0 (2026-04-03) - 初始版本
    • 上下文診斷
    • 技能診斷
    • 記憶診斷
    • 配置診斷
    • 優化建議生成

相關資源


版本: 1.0.0
日期: 2026-04-03
狀態: 初始發布
維護者: skill-dev

Usage Guidance
What to check before installing or running this skill: - Review src/index.js locally: confirm exactly what file paths it reads and any delete/archive commands it will run. The script reads ~/.openclaw, workspace memory and sessions, and may suggest or run deletion commands. - Do not enable automatic fixes on a production system without testing. Set OPTIMIZE_AUTO_FIX=false (default) and run the diagnosis to inspect recommendations first. - Back up your OpenClaw data (sessions, memory, configs) before applying fixes. The README and SKILL.md include backup examples — run them manually and verify backups. - The tool can add cron jobs (persistence). If you do not want scheduled runs, do not run the 'clawdbot cron add' commands and remove any created cron entries. - Note capability mismatches: the skill declares no write permission to workspace/.openclaw but advises delete commands and cron creation; ensure the runtime enforces the intended write restrictions or run the tool in a safe test environment first. - If you plan to allow autonomous agent invocation (default platform behavior), be cautious: an agent could invoke this skill and request auto-fix. Prefer manual invocation for the first few runs. - If anything is unclear, ask the skill author for (1) justification for the hard-coded /home/admin path and jq requirement, (2) explicit explanation of what --auto-fix will change, and (3) whether cron creation requires user consent.
Capability Analysis
Type: OpenClaw Skill Name: agent-optimize Version: 1.0.0 The agent-optimize skill is a diagnostic utility designed to audit and improve the performance of the OpenClaw environment. It analyzes session history, memory usage, and configuration files (including .env and openclaw.json) to identify 'context bloat' and 'skill noise.' While the script (src/index.js) uses shell commands via execSync and reads sensitive configuration data, its actions are transparently documented and strictly limited to the stated purpose of system optimization. The SKILL.md manifest explicitly restricts network access, and the code contains no evidence of data exfiltration, unauthorized persistence, or malicious intent.
Capability Assessment
Purpose & Capability
Overall the files and commands align with an agent-diagnostic/optimization tool (it reads sessions, memory, skills, configs). Minor inconsistencies: the registry metadata requires 'jq' though index.js does not use jq; PATHS.npmGlobal is hard-coded to /home/admin/.npm-global/lib/node_modules/openclaw which is brittle and assumes a specific environment. These are plausible engineering sloppiness but worth noting.
Instruction Scope
SKILL.md and src/index.js instruct the agent to read many user files under ~/.openclaw, workspace memory and sessions, and to suggest shell commands that can delete files (e.g. find ... -delete), copy backups, and add cron jobs (clawdbot cron add). Those actions are within an optimizer's remit but are potentially destructive. The documentation warns user confirmation is required, yet the tool supports --auto-fix and an OPTIMIZE_AUTO_FIX flag that would apply fixes automatically — this raises a scope/authority concern if used without careful confirmation.
Install Mechanism
No external download/install spec — the skill is instruction + a local Node script (src/index.js). That reduces supply-chain risk compared to remote fetches. The code uses child_process.execSync; there are no network downloads in the provided files. No red-flag install URLs found.
Credentials
The skill does not request secrets or external credentials and declares optional environment variables (OPTIMIZE_*), which match behavior in index.js. However, declared abilities include reading ~/.npm-global and an absolute /home/admin npm global path; the hard-coded admin path could cause the tool to inspect locations outside the current user's directories. No sensitive tokens are requested, which is proportional, but be cautious about the tool reading many local files.
Persistence & Privilege
The SKILL.md suggests adding cron jobs (clawdbot cron add) for periodic runs and provides an --auto-fix mode; while the skill isn't set always:true, scheduling cron or enabling auto-fix would create persistent actions that could modify system state over time. Also the capability metadata attempts to deny writes to workspace/.openclaw but the instructions include delete operations — a capability/instruction mismatch that could lead to unexpected behavior or inadequate permission checks.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install agent-optimize
  3. After installation, invoke the skill by name or use /agent-optimize
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.0
agent-optimize 1.0.0 - Initial release of an agent performance diagnostic and optimization skill for OpenClaw. - Provides diagnosis for context bloat, skill noise, memory redundancy, and config conflicts. - Generates optimization suggestions and structured reports in markdown, JSON, and Feishu card formats. - Supports safe auto-fix of certain issues and user-guided advanced optimizations. - Includes built-in troubleshooting, backup, and integration examples for automated workflows.
Metadata
Slug agent-optimize
Version 1.0.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is Agent Optimize?

Agent 優化診斷技能。分析 OpenClaw 運行狀態,識別信息過載、上下文堆積、技能噪音等問題。 提供系統級優化方案,實現瘦身提速,解決"貴慢亂"困擾。 Use when: (1) Agent 響應變慢, (2) 上下文過長導致效率低下, (3) 技能加載過多造成噪音, (4) 需要診斷性能瓶頸, (5)... It is an AI Agent Skill for Claude Code / OpenClaw, with 92 downloads so far.

How do I install Agent Optimize?

Run "/install agent-optimize" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is Agent Optimize free?

Yes, Agent Optimize is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does Agent Optimize support?

Agent Optimize is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created Agent Optimize?

It is built and maintained by chungvic (@chungvic); the current version is v1.0.0.

💬 Comments