云计算百科
云计算领域专业知识百科平台

小龙虾-养虾人的终极配置指南---详解OpenClaw.json

⚡⚡⚡ 新年新文⚡⚡⚡


文章目录

    • 一、配置结构总览
    • 二、Channels 渠道配置通用配置字段
      • 2.1,DM Policy 选项
      • 2.2,Group Policy 选项
    • 三、Agents Agent 配置
    • 四、Models 模型配置
    • 五、Gateway 服务器配置
    • 六、Cron 定时任务
    • 七、Bindings 路由绑定
    • 八、Environment 环境变量
    • 九、常用配置任务速查
    • 十、配置验证与调试

安装使用OpenClaw 过程中,如何配置 openclaw.json是用好小龙虾的关键 ,本文大部分内容来自官方文档,现整理如下,希望能帮到养虾人。

OpenClaw 官方文档:https://docs.openclaw.ai GitHub:https://github.com/openclaw/openclaw 配置示例:https://docs.openclaw.ai/gateway/configuration-examples

一、配置结构总览

配置文件:~/.openclaw/openclaw.json 配置格式:JSON5(支持注释和尾随逗号) 严格验证:未知字段会导致 Gateway 拒绝启动

主要配置模块:

  • channels – 渠道配置
  • agents – Agent 配置
  • models – 模型配置
  • gateway – Gateway 服务器配置
  • tools – 工具配置
  • session – 会话配置
  • cron – 定时任务
  • bindings – 路由绑定

二、Channels 渠道配置通用配置字段

字段类型默认值说明
enabled boolean true 是否启用该渠道
dmPolicy string pairing DM 消息策略
allowFrom array [] 允许的用户列表
groupPolicy string allowlist 群聊策略
historyLimit number 50 历史消息限制
configWrites boolean true 允许渠道端配置修改

2.1,DM Policy 选项

  • pairing(默认):未知用户获得一次性配对码,需管理员批准
  • allowlist:仅允许 allowFrom 列表中的用户
  • open:允许所有 DM(需设置 allowFrom: [“*”])
  • disabled:忽略所有 DM

2.2,Group Policy 选项

  • allowlist(默认):仅允许配置中的群组
  • open:允许所有群组(提及门控仍适用)
  • disabled:阻止所有群聊消息

WhatsApp 配置示例

{
"channels": {
"whatsapp": {
"dmPolicy": "pairing",
"allowFrom": ["+15555550123"],
"textChunkLimit": 4000,
"mediaMaxMb": 50,
"groups": { "*": { "requireMention": true } }
}
}
}

关键字段:dmPolicy、allowFrom、textChunkLimit、mediaMaxMb、groups

Telegram 配置示例

{
"channels": {
"telegram": {
"botToken": "123456:ABC…",
"dmPolicy": "pairing",
"groups": { "*": { "requireMention": true } },
"customCommands": [{ "command": "backup" }],
"streaming": "partial"
}
}
}

关键字段:botToken、groups、customCommands、streaming

Discord 配置示例

{
"channels": {
"discord": {
"token": "…",
"guilds": {
"123456789": {
"requireMention": false,
"channels": { "general": { "allow": true } }
}
},
"threadBindings": { "enabled": true }
}
}
}

关键字段:token、guilds、threadBindings

Slack 配置示例

{
"channels": {
"slack": {
"enabled": true,
"botToken": "xoxb-…",
"appToken": "xapp-…",
"slashCommand": { "enabled": true }
}
}
}

关键字段:botToken、appToken、slashCommand

三、Agents Agent 配置

{
"agents": {
"list": [{
"id": "agent_robot1",
"workspace": "~/.openclaw/workspace/robot1",
"model": "anthropic/claude-sonnet-4-6",
"identity": { "name": "总助", "emoji": "👔" }
}],
"defaults": {
"model": { "primary": "anthropic/claude-sonnet-4-6" },
"maxConcurrent": 40000
}
}
}

关键字段:list(Agent 列表)、defaults.model(默认模型)、defaults.workspace(默认工作区)

四、Models 模型配置

{
"models": {
"mode": "merge",
"providers": {
"anthropic": {
"baseUrl": "https://api.anthropic.com",
"apiKey": "sk-ant-…",
"models": [{
"id": "claude-sonnet-4-6",
"contextWindow": 200000,
"maxTokens": 8192
}]
},
"openai": {
"baseUrl": "https://api.openai.com/v1",
"models": [{
"id": "gpt-4.1",
"contextWindow": 1000000
}]
}
}
}
}

关键字段:mode(合并模式)、providers(模型提供商配置)

五、Gateway 服务器配置

{
"gateway": {
"port": 18789,
"auth": { "mode": "token", "token": "your-token" },
"reload": { "mode": "hybrid" }
}
}

热重载模式说明

模式行为
hybrid(默认) 安全变更热应用,关键变更自动重启
hot 仅热应用安全变更,需重启时记录警告
restart 任何变更都重启
off 禁用热重载,手动重启生效

六、Cron 定时任务

{
"cron": [
{
"id": "daily-article",
"name": "公众号每日文章",
"enabled": true,
"schedule": "0 10 * * *",
"payload": {
"kind": "systemEvent",
"text": "写一篇公众号文章"
}
},
{
"id": "evomap-fetch",
"schedule": "0 */4 * * *",
"payload": { "kind": "systemEvent" }
}
]
}

关键字段:schedule(Cron 表达式)、payload.kind(事件类型)、payload.text(执行内容)

Cron 表达式示例:

  • 0 10 * * * – 每天 10:00 执行
  • 0 */4 * * * – 每 4 小时执行
  • 30 7 * * * – 每天 7:30 执行

七、Bindings 路由绑定

{
"bindings": [
{
"agentId": "agent_robot1",
"match": { "channel": "feishu", "accountId": "robot1" }
},
{
"agentId": "agent_robot2",
"match": { "channel": "discord" }
}
]
}

关键字段:agentId(目标 Agent)、match.channel(匹配渠道)、match.accountId(匹配账户)

八、Environment 环境变量

{
"env": {
"OPENROUTER_API_KEY": "sk-or-…",
"ANTHROPIC_API_KEY": "sk-ant-…",
"vars": {
"GROQ_API_KEY": "gsk-…"
}
}
}

环境变量来源优先级(从高到低):

  • 系统环境变量
  • ~/.openclaw/.env(全局)
  • ./.env(工作区)
  • 配置文件中 env 字段
  • 九、常用配置任务速查

    任务配置字段示例
    添加 WhatsApp channels.whatsapp 见上方示例
    配置多 Agent agents.list[] 添加多个 Agent 对象
    设置默认模型 agents.defaults.model { primary: “anthropic/…” }
    启用沙盒 sandbox.enabled true
    配置定时任务 cron[] 添加 cron 对象
    修改 Gateway 端口 gateway.port 18789
    启用热重载 gateway.reload.mode “hybrid”
    路由渠道到 Agent bindings[] 添加 binding 对象

    十、配置验证与调试

    验证命令

    # 检查配置有效性
    openclaw doctor

    # 自动修复配置问题
    openclaw doctor –fix

    # 查看 Gateway 状态
    openclaw gateway status

    # 查看日志
    openclaw logs –follow

    常见问题

    问题可能原因解决方案
    Gateway 拒绝启动 配置中有未知字段 运行 openclaw doctor 检查
    渠道无法连接 Token 错误或过期 检查 channels.*.botToken
    消息无响应 DM/Group 策略限制 检查 dmPolicy 和 groupPolicy
    模型调用失败 API Key 无效 检查 models.providers.*.apiKey

    感谢阅读,下期更精彩 👋👋👋

    神经网络动画结尾

    赞(0)
    未经允许不得转载:网硕互联帮助中心 » 小龙虾-养虾人的终极配置指南---详解OpenClaw.json
    分享到: 更多 (0)

    评论 抢沙发

    评论前必须登录!