第 9 章

性能调优

🎯 模型配置

{
  "agent": {
    "model": {
      "primary": "anthropic/claude-sonnet-4-6",
      "fallbacks": ["openai/gpt-4o"]
    }
  }
}

temperature 选择

场景 推荐值
代码生成、数据分析 0.3 – 0.5
日常对话、内容创作 0.7 – 0.8
创意写作、头脑风暴 0.9 – 1.0

💰 成本控制

{
  "agents": {
    "defaults": {
      "cache": { "enabled": true, "ttl": 3600 },
      "compaction": { "targetTokens": 50000 }
    }
  },
  "billing": {
    "limits": { "daily": 10.00, "monthly": 200.00 },
    "alerts": { "enabled": true, "thresholds": [0.5, 0.8, 0.95] }
  }
}

降成本策略:

  1. 启用缓存
  2. 简单任务用轻量模型(claude-haiku / gpt-4o-mini)
  3. 精简系统提示
  4. 设置每日限额
openclaw stats --period 7d   # 查看 7 天使用统计

📋 完整配置速查

{
  "agent": {
    "model": {
      "primary": "anthropic/claude-sonnet-4-6",
      "fallbacks": ["openai/gpt-4o"]
    },
    "workspace": "~/.openclaw/workspace",
    "heartbeat": { "every": "30m" }
  },
  "agents": {
    "defaults": {
      "compaction": {
        "reserveTokensFloor": 20000,
        "memoryFlush": { "enabled": true, "softThresholdTokens": 4000 }
      },
      "subAgents": { "enabled": true, "maxConcurrent": 3, "timeout": 300000 },
      "cache": { "enabled": true, "ttl": 3600 },
      "sandbox": { "mode": "non-main" }
    }
  },
  "memorySearch": {
    "enabled": true,
    "provider": "openai",
    "remote": {
      "baseUrl": "https://api.siliconflow.cn/v1",
      "apiKey": "YOUR_API_KEY"
    },
    "model": "BAAI/bge-m3"
  },
  "billing": {
    "limits": { "daily": 10.00, "monthly": 200.00 }
  }
}