作者:Mac | OpenClaw 实操系列
配置文件位置
OpenClaw 的配置文件位于:
~/.openclaw/ | |
~/.openclaw/ | |
%USERPROFILE%\.openclaw\ |
主要配置文件:
• openclaw.json- 主配置• models.json- 模型配置• channels/- 渠道配置
主配置文件结构
{
"meta": {
"version": "2024.1.0"
},
"models": {
"providers": {}
},
"agents": {
"defaults": {
"model": {
"primary": "anthropic/claude-3-sonnet"
}
}
},
"channels": {},
"gateway": {},
"hooks": {}
}模型配置
单模型配置
{
"models": {
"providers": {
"anthropic": {
"baseUrl": "https://api.anthropic.com/v1",
"apiKey": "sk-ant-xxxxx",
"api": "anthropic-messages",
"models": [
{
"id": "claude-3-5-sonnet-latest",
"name": "Claude 3.5 Sonnet"
}
]
}
}
}
}多模型配置
{
"models": {
"mode": "merge",
"providers": {
"anthropic": {
"baseUrl": "https://api.anthropic.com/v1",
"apiKey": "sk-ant-xxxxx",
"models": [
{"id": "claude-3-opus", "name": "Claude 3 Opus"},
{"id": "claude-3-sonnet", "name": "Claude 3 Sonnet"},
{"id": "claude-3-haiku", "name": "Claude 3 Haiku"}
]
},
"openai": {
"baseUrl": "https://api.openai.com/v1",
"apiKey": "sk-xxxxx",
"models": [
{"id": "gpt-4o", "name": "GPT-4o"},
{"id": "gpt-4-turbo", "name": "GPT-4 Turbo"}
]
},
"ali": {
"baseUrl": "https://dashscope.aliyuncs.com/compatible-mode/v1",
"apiKey": "sk-xxxxx",
"models": [
{"id": "qwen-plus", "name": "通义千问 Plus"},
{"id": "qwen-max", "name": "通义千问 Max"}
]
}
}
}
}模型路由规则
{
"models": {
"routing": {
"default": "anthropic/claude-3-sonnet",
"rules": [
{"pattern": "code", "model": "openai/gpt-4o"},
{"pattern": "image", "model": "anthropic/claude-3-sonnet"},
{"pattern": "chinese", "model": "ali/qwen-plus"}
]
}
}
}渠道配置
飞书配置
{
"channels": {
"feishu": {
"enabled":true,
"appId": "cli_axxxxx",
"appSecret": "xxxxx",
"connectionMode": "websocket",
"botName": "AI助手",
"groupPolicy": "allowlist",
"groupAllowFrom": [
"oc_xxxxx"
]
}
}
}微信配置
{
"channels": {
"weixin": {
"enabled":true,
"token": "your_token",
"encodingAesKey": "your_aes_key"
}
}
}Telegram 配置
{
"channels": {
"telegram": {
"enabled":true,
"botToken": "123456:ABC-DEF",
"allowedUsers": ["123456789"]
}
}
}Agent 配置
默认 Agent
{
"agents": {
"defaults": {
"model": {
"primary": "anthropic/claude-3-sonnet",
"temperature": 0.7,
"maxTokens": 4096
},
"workspace": "/path/to/workspace",
"compaction": {
"mode": "safeguard",
"threshold": 100000
}
}
}
}自定义 Agent
{
"agents": {
"named": {
"coder": {
"model": "openai/gpt-4o",
"systemPrompt": "你是一个专业的程序员,擅长写高质量代码..."
},
"writer": {
"model": "anthropic/claude-3-sonnet",
"systemPrompt": "你是一个专业的内容创作者,擅长写吸引人的文章..."
}
}
}
}Gateway 配置
{
"gateway": {
"port": 18789,
"mode": "local",
"bind": "loopback",
"auth": {
"mode": "token",
"token": "your-gateway-token"
},
"tailscale": {
"mode": "off"
},
"cors": {
"allowOrigins": ["https://your-domain.com"]
}
}
}使用命令行配置
查看当前配置
# 查看所有配置
openclaw config list
# 查看特定项
openclaw config get agents.defaults.model.primary
# 查看所有模型
openclaw models list修改配置
# 修改单个值
openclaw config set agents.defaults.model.primary "openai/gpt-4o"
# 重置配置
openclaw config reset
# 导出配置
openclaw config export > backup.json
# 导入配置
openclaw config import backup.json环境变量
除了配置文件,也可以用环境变量:
# 模型 API Key
export ANTHROPIC_API_KEY="sk-ant-xxxxx"
export OPENAI_API_KEY="sk-xxxxx"
# Gateway 配置
export OPENCLAW_PORT=18789
export OPENCLAW_TOKEN="your-token"
# 飞书配置
export FEISHU_APP_ID="cli_xxxxx"
export FEISHU_APP_SECRET="xxxxx"下一步
• 上一篇:OpenClaw 安装指南[1] • 下一篇:OpenClaw Skills 商店:如何安装和使用[1]
关注公众号,获取更多 OpenClaw 实操教程!
作者:Mac | OpenClaw 实操系列第5篇
引用链接
[1] OpenClaw 安装指南:
夜雨聆风