OpenClaw Gateway 配置管理:Agent的大脑中枢

📅 2026-03-20 ⏱️ 阅读时间: 8分钟 🏷️ OpenClaw | Gateway | 配置管理

Gateway就像OpenClaw的心脏——它跳,整个系统才能活。掌握Gateway的配置和管理,就是掌握了OpenClaw的命脉。今天我们来聊聊如何让这个心脏跳动得更稳健。

什么是 Gateway?

Gateway 是 OpenClaw 的核心服务进程,负责:

Gateway 命令行

使用 openclaw 命令管理 Gateway:

# 查看状态
openclaw gateway status

# 启动服务
openclaw gateway start

# 停止服务
openclaw gateway stop

# 重启服务
openclaw gateway restart

# 查看帮助
openclaw gateway --help

配置文件结构

Gateway 配置通常位于 ~/.openclaw/config/gateway.json:

{
  "server": {
    "port": 3000,
    "host": "0.0.0.0"
  },
  "model": {
    "default": "claude-3-sonnet",
    "providers": {
      "openai": {
        "apiKey": "${OPENAI_API_KEY}"
      },
      "anthropic": {
        "apiKey": "${ANTHROPIC_API_KEY}"
      }
    }
  },
  "channels": {
    "discord-main": {
      "type": "discord",
      "botToken": "${DISCORD_BOT_TOKEN}"
    }
  },
  "tools": {
    "policy": "allowlist",
    "allowed": ["web_search", "web_fetch", "exec", "read", "write"]
  },
  "cron": {
    "enabled": true,
    "timezone": "Asia/Shanghai"
  }
}

配置更新方式

方式一:config.patch(推荐)

部分更新配置,不影响其他设置:

// 使用gateway工具
{
  "action": "config.patch",
  "patch": {
    "model": {
      "default": "gpt-4"
    }
  },
  "note": "更新默认模型为GPT-4"
}

方式二:config.apply

完全替换配置(慎用):

{
  "action": "config.apply",
  "raw": "{...完整配置JSON...}",
  "note": "应用新配置"
}

方式三:config.schema.lookup

查看配置项的Schema定义:

{
  "action": "config.schema.lookup",
  "path": "model.default"
}

热更新机制

Gateway支持部分配置的热更新,无需重启:

重启与恢复

// 通过工具重启
{
  "action": "restart",
  "delayMs": 5000,
  "note": "重启以应用新配置"
}

// 查看当前配置
{
  "action": "config.get",
  "sessionKey": "your-session-key"
}

环境变量

敏感信息使用环境变量存储:

# ~/.bashrc 或 ~/.zshrc
export OPENAI_API_KEY="sk-xxx"
export ANTHROPIC_API_KEY="sk-ant-xxx"
export DISCORD_BOT_TOKEN="MTk4NjIy..."
export TELEGRAM_BOT_TOKEN="123456:ABC..."

最佳实践

常见问题

Q: 配置更新后没生效?

A: 检查是否需要重启Gateway,或查看配置语法是否正确。

Q: 如何回滚配置?

A: 使用Git恢复旧版本配置,或用config.patch覆盖。

相关链接

⚙️ 想深入了解配置?查看 配置参考文档