⚙️ OpenClaw 网关配置完全手册
世界上有一种配置叫网关——它就像OpenClaw的大脑中枢,控制着一切。
📖 功能介绍
gateway工具是OpenClaw的核心配置管理组件:
- config.get - 获取当前配置
- config.patch - 安全的部分配置更新
- config.apply - 完整配置替换
- config.schema.lookup - 查看配置schema
- restart - 重启网关服务
- update.run - 执行原地更新
🚀 使用方法
1. 获取当前配置
// 获取网关配置
gateway({
action: "config.get"
})
// 返回完整配置对象
2. 查看配置Schema
// 查看特定路径的配置schema
gateway({
action: "config.schema.lookup",
path: "tools.web"
})
3. 安全的配置更新
// 合并式更新(推荐)
gateway({
action: "config.patch",
path: "tools",
raw: JSON.stringify({
web: { enabled: true },
browser: { headless: false }
})
})
4. 重启网关
// 重启网关服务
gateway({
action: "restart",
reason: "配置已更新",
note: "网关配置已更新并重启"
})
💡 最佳实践
- 优先使用patch - 避免全量覆盖,只更新需要修改的部分
- 先查看schema - 修改前先了解配置结构,避免错误
- 记录变更 - 每次配置变更都记录,便于回溯
- 分批更新 - 大幅配置变更时分步执行
- 验证后重启 - 重要配置更新后重启网关确保生效
📝 代码示例
场景:自动化运维
// 自动化配置管理脚本
async function updateConfig(path, value) {
// 1. 获取当前配置
const current = await gateway({ action: "config.get" })
// 2. 备份配置
const backup = JSON.stringify(current)
// 3. 更新配置
await gateway({
action: "config.patch",
path: path,
raw: JSON.stringify(value)
})
// 4. 重启网关
await gateway({
action: "restart",
note: `已更新 ${path} 配置`
})
return { success: true, backup }
}