OpenClaw 最近很火,正好公司有台空闲的 Mac Mini,可以在上面捣鼓一下这个新东西。

1. 安装 Lume

Lume 是 MacOS 上的原生虚拟化框架,让 OpenClaw 在虚拟环境下运行不会搞乱我们的系统。

1.1 安装 Lume

方式一:脚本安装

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/trycua/cua/main/libs/lume/scripts/install.sh)"

方式二:Homebrew 安装

brew tap trycua/lume
brew install lume

验证安装

使用以下命令验证是否安装成功:

lume --version

1.2 下载 MacOS 镜像

lume 安装成功后,需要获取 MacOS 镜像,使用下面指令将镜像下载到 Downloads 文件夹中:

curl -L -o ~/Downloads/macos.ipsw "$(lume ipsw 2>/dev/null | tail -1)"

1.3 运行虚拟机

使用下面指令即可运行虚拟机

lume create openclaw --os macos --ipsw ~/Downloads/macos.ipsw

2. 安装 OpenClaw

openclaw 中文文档

openclaw 的安装方式在其官方文档中已经很清楚了,我这里只列出几个我安装时遇到的问题

2.1 踩坑记录

2.1.1 对接飞书频道

安装飞书插件

openclaw plugins install @openclaw/feishu

使用下面命令配置飞书通道

openclaw channels add

2.1.2 配置其他模型

~/.openclaw/openclaw.json 文件中添加 models

"models": {
  "providers": {
    // 这里配置供应商
    "bailian": {
      "baseUrl": "https://coding.dashscope.aliyuncs.com/v1",	// 供应商接口链接
      "apiKey": "sk-sp-xxxxxxxxx",
      "api": "openai-completions",
      "models": [
        {
          "id": "qwen3.5-plus",
          "name": "qwen3.5-plus",
          "reasoning": false,
          "input": [
            "text",
            "image"	// 这里添加 image 才有办法识别图片
          ]
        }
      ]
    }
  }
}

添加完 models 块后,在修改 agents

"agents": {
    "defaults": {
        "model": {
            "primary": "bailian/qwen3.5-plus" // mdels中配置的供应商名称和模型名称
        }
    }
}

最后执行 openclaw gateway restart 即可生效

2.1.3 配置浏览器

默认情况下 openclaw 会尝试使用扩展中继的方式控制用户的浏览器,这会导致运行不顺畅,所以直接让openclaw使用自托管的方式去运行更方便。

"browser": {
  "enabled": true,
  "headless": false,
  "noSandbox": false,
  "attachOnly": false,
  "defaultProfile": "openclaw"
}

3. 调优

根据 OpenClaw 的官方文档,OpenClaw 有一些可以优化的地方,这里总结一下

需要注意的是,下面调优的参数都是和使用的模型有关

3.1 历史的工具调用结果裁剪

可以让 OpenClaw 在请求发到 LLM 之前对历史的工具调用结果进行裁剪

裁剪有 硬裁剪软裁剪 两种

  • 硬裁剪: 直接把工具结果替换为 hardClear.placeholder 中的内容

  • 软裁剪: 只正对过大的工具结果,并且保留开头和结尾,在中间插入 hardClear.placeholder 中的内容

配置示例:

{
  "agents": {
    "defaults": {
      // 工具裁剪配置
      "contextPruning": {
        "mode": "cache-ttl", // 有 off 和 cache-ttl
        "ttl": "1h",  // tool result 保留时间,单位 ms/s/m/h,默认是m
        "keepLastAssistants": 5,  // 保留最近几条工具调用信息
        "softTrimRatio": 0.1, // 触发软裁剪时,尝试清理的目标比例
        "hardClearRatio": 0.3,  // 触发硬裁剪是,尝试清理的目标比例
        "minPrunableToolChars": 50000,  // 单个工具结果超过多少字符才会进入可裁剪名单
        "softTrim": {
          "maxChars": 4000,   // 最多保留字符书
          "headChars": 1500,  // 开头保留的字符数
          "tailChars": 1500   // 结尾保留的字符数
        },
        "hardClear": {
          "enabled": true,
          "placeholder": "[Old tool result content cleared]"  // 硬裁剪时的占位符
        },
        // 永远不执行 pruning 的工具
        "tools": {
          "deny": ["browser", "canvas"]
        },
      },
    },
  },
}

3.2 记忆压缩

当模型的上下文达到阈值时压缩较早的历史记录。

另外openclaw还支持配置专门的模型做压缩动作

配置示例:

{
  "agents": {
    "defaults": {
      "compaction": {
        "mode": "safeguard", // default | safeguard
        "reserveTokensFloor": 24000,  // 保证在 compaction 前预留的token空间

        // 压缩时对关键ID的保护策略,strict严格保护(保留原样);off 不保护; custom 使用自己规则
        "identifierPolicy": "strict", // strict | off | custom
        "identifierInstructions": "Preserve deployment IDs, ticket IDs, and host:port pairs exactly.", // used when identifierPolicy=custom

        // 在 compaction 后重新注入一些关键提示词
        "postCompactionSections": ["Session Startup", "Red Lines"], // [] disables reinjection

        // 压缩专用模型配置
        "model": "openrouter/anthropic/claude-sonnet-4-5", // optional compaction-only model override


        "memoryFlush": {
          "enabled": true,

          // compaction 前多少 token 触发 memory flush
          // 触发条件:session_tokens > context_window - reserveTokensFloor - softThresholdTokens
          "softThresholdTokens": 6000,

          "systemPrompt": "Session nearing compaction. Store durable memories now.",
          "prompt": "Write any lasting notes to memory/YYYY-MM-DD.md; reply with NO_REPLY if nothing to store.",
        },
      },
    },
  },
}