OpenClaw 多智能体部署指南

OpenClaw 多智能体部署指南

从零开始创建多个独立的飞书智能体助手


📋 目录

  1. 前置准备
  2. 架构说明
  3. 创建第一个智能体
  4. 创建多个智能体
  5. 配置飞书应用
  6. 启动与测试
  7. 运维管理
  8. 故障排查

前置准备

系统要求

  • macOS / Linux
  • Node.js v18+ (推荐 v22+)
  • npm / yarn
  • 飞书企业账号

安装 OpenClaw

bash 复制代码
# 安装 OpenClaw CLI
npm install -g openclaw

# 验证安装
openclaw --version

配置基础环境

bash 复制代码
# 运行初始化配置
openclaw configure

# 按提示完成:
# 1. 模型配置(推荐通义千问)
# 2. 飞书应用配置
# 3. Gateway 配置

架构说明

多智能体架构

每个智能体独立运行,互不干扰:

复制代码
┌─────────────────────────────────────────────────────────┐
│                    飞书开放平台                          │
├─────────────┬─────────────┬─────────────┬─────────────┤
│  应用 A     │  应用 B     │  应用 C     │  应用 D     │
│  (虾米)     │  (投资顾问)  │  (办公助手)  │  (编程助手)  │
└──────┬──────┴──────┬──────┴──────┬──────┴──────┬──────┘
       │             │             │             │
       ▼             ▼             ▼             ▼
┌─────────────┬─────────────┬─────────────┬─────────────┐
│ 端口 18789  │ 端口 18790  │ 端口 18800  │ 端口 18801  │
│  Gateway 1  │  Gateway 2  │  Gateway 3  │  Gateway 4  │
└─────────────┴─────────────┴─────────────┴─────────────┘

目录结构

复制代码
~/.openclaw/
├── openclaw.json                    # 主配置文件
├── gateway-main.json                # 主应用 Gateway 配置
├── gateway-finance.json             # 金融助手 Gateway 配置
├── gateway-office.json              # 办公助手 Gateway 配置
├── gateway-programming.json         # 编程助手 Gateway 配置
├── agents/
│   ├── main/                        # 主智能体
│   │   └── agent/
│   │       └── agent.json
│   ├── financial-assistant/         # 金融助手
│   │   └── agent/
│   │       └── agent.json
│   ├── office-assistant/            # 办公助手
│   │   └── agent/
│   │       └── agent.json
│   └── programming-assistant/       # 编程助手
│       └── agent/
│           └── agent.json
├── workspace/                       # 主应用工作区
├── workspace-finance/               # 金融助手独立工作区
├── workspace-office/                # 办公助手独立工作区
├── workspace-programming/           # 编程助手独立工作区
└── skills/                          # 技能目录

重要:独立工作区配置

⚠️ 每个智能体必须有独立的工作区,原因:

  • ✅ 职责隔离 - 每个助手明确自己的职责边界

  • ✅ 记忆隔离 - 避免记忆混淆

  • ✅ 技能隔离 - 只访问专属技能

    workspace-finance/ # 投资顾问工作区
    ├── IDENTITY.md # 身份:投资顾问
    ├── SOUL.md # 个性:专业严谨
    ├── USER.md # 用户投资偏好
    └── memory/ # 独立记忆

    workspace-office/ # 办公助手工作区
    ├── IDENTITY.md # 身份:办公助手
    ├── SOUL.md # 个性:细致高效
    ├── USER.md # 用户办公场景
    └── memory/ # 独立记忆

    workspace-programming/ # 编程助手工作区
    ├── IDENTITY.md # 身份:编程助手
    ├── SOUL.md # 个性:逻辑严谨
    ├── USER.md # 用户技术栈
    └── memory/ # 独立记忆


创建第一个智能体

步骤 1:创建 Agent 目录

bash 复制代码
mkdir -p ~/.openclaw/agents/main/agent

步骤 2:创建 Agent 配置

bash 复制代码
cat > ~/.openclaw/agents/main/agent/agent.json << 'EOF'
{
  "name": "main",
  "displayName": "虾米",
  "model": {
    "primary": "custom-coding-dashscope-aliyuncs-com/qwen3.5-plus"
  },
  "models": {
    "custom-coding-dashscope-aliyuncs-com/qwen3.5-plus": {
      "alias": "coding-qwen3.5-plus"
    }
  },
  "workspace": "/home/<USER>/.openclaw/workspace",
  "compaction": {
    "mode": "safeguard"
  },
  "channels": {
    "feishu": {
      "enabled": true,
      "appId": "cli_xxxxxxxxxxxxxx",
      "appSecret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "domain": "feishu",
      "connectionMode": "websocket",
      "groupPolicy": "open",
      "dmPolicy": "open",
      "allowFrom": ["*"]
    }
  },
  "tools": {
    "profile": "coding"
  }
}
EOF

步骤 3:创建 Gateway 配置

bash 复制代码
cat > ~/.openclaw/gateway-main.json << 'EOF'
{
  "models": {
    "mode": "merge",
    "providers": {
      "custom-coding-dashscope-aliyuncs-com": {
        "baseUrl": "https://coding.dashscope.aliyuncs.com/v1",
        "apiKey": "sk-xxxxxxxxxxxxxxxxxxxxxxxx",
        "api": "openai-completions",
        "models": [
          {
            "id": "qwen3.5-plus",
            "name": "qwen3.5-plus",
            "api": "openai-completions",
            "reasoning": false,
            "input": ["text", "image"],
            "cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0},
            "contextWindow": 1000000,
            "maxTokens": 65536
          }
        ]
      }
    }
  },
  "agents": {
    "defaults": {
      "model": {"primary": "custom-coding-dashscope-aliyuncs-com/qwen3.5-plus"},
      "workspace": "/home/<USER>/.openclaw/workspace",
      "compaction": {"mode": "safeguard"},
      "maxConcurrent": 4
    }
  },
  "tools": {"profile": "coding"},
  "channels": {
    "feishu": {
      "enabled": true,
      "appId": "cli_xxxxxxxxxxxxxx",
      "appSecret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "domain": "feishu",
      "connectionMode": "websocket",
      "groupPolicy": "open",
      "dmPolicy": "open",
      "allowFrom": ["*"]
    }
  },
  "gateway": {
    "port": 18789,
    "mode": "local",
    "bind": "loopback",
    "auth": {"mode": "token", "token": "your_gateway_token"}
  },
  "plugins": {
    "allow": ["feishu"],
    "entries": {"feishu": {"enabled": true}}
  }
}
EOF

步骤 4:启动 Gateway

bash 复制代码
OPENCLAW_CONFIG_PATH=/home/<USER>/.openclaw/gateway-main.json \
  nohup openclaw gateway run --port 18789 > /tmp/gateway-main.log 2>&1 &

步骤 5:验证启动

bash 复制代码
# 检查端口
lsof -i :18789 | grep LISTEN

# 查看日志
tail -f /tmp/gateway-main.log

创建多个智能体

智能体命名规范

智能体 目录名 配置文件 端口 工作区
主应用 main gateway-main.json 18789 workspace/
金融助手 financial-assistant gateway-finance.json 18790 workspace-finance/
办公助手 office-assistant gateway-office.json 18800 workspace-office/
编程助手 programming-assistant gateway-programming.json 18801 workspace-programming/

职责边界定义

⚠️ 必须为每个智能体定义明确的职责边界,避免越界:

智能体 ✅ 职责范围 ❌ 禁止越界
投资顾问 股票、基金、财经、投资分析 办公文档、编程
办公助手 Excel、PPT、PDF、文档处理 投资建议、编程
编程助手 代码、调试、架构、技术答疑 投资建议、办公文档

创建独立工作区

bash 复制代码
# 创建工作区目录
mkdir -p ~/.openclaw/workspace-finance/memory
mkdir -p ~/.openclaw/workspace-office/memory
mkdir -p ~/.openclaw/workspace-programming/memory

配置身份文件

为每个工作区创建 IDENTITY.mdSOUL.mdUSER.md

投资顾问工作区 (workspace-finance/IDENTITY.md):

markdown 复制代码
# IDENTITY.md - 投资顾问身份

- **名称**: 投资顾问
- **职责**: 股票、基金、财经、投资分析
- **边界**:
  - ✅ 股票行情查询
  - ✅ 基金净值查询
  - ❌ 不处理办公文档
  - ❌ 不处理编程任务

办公助手工作区 (workspace-office/IDENTITY.md):

markdown 复制代码
# IDENTITY.md - 办公助手身份

- **名称**: 办公助手
- **职责**: Excel、PPT、PDF、文档处理
- **边界**:
  - ✅ Excel 表格处理
  - ✅ PPT 制作优化
  - ❌ 不提供投资建议
  - ❌ 不处理编程任务

编程助手工作区 (workspace-programming/IDENTITY.md):

markdown 复制代码
# IDENTITY.md - 编程助手身份

- **名称**: 编程助手
- **职责**: 代码、调试、架构、技术答疑
- **边界**:
  - ✅ 代码编写
  - ✅ 代码审查
  - ❌ 不提供投资建议
  - ❌ 不处理办公文档

创建金融助手示例

bash 复制代码
# 1. 创建目录
mkdir -p ~/.openclaw/agents/financial-assistant/agent
mkdir -p ~/.openclaw/workspace-finance/memory

# 2. 创建身份文件
cat > ~/.openclaw/workspace-finance/IDENTITY.md << 'EOF'
# 投资顾问身份

- **职责**: 股票、基金、财经、投资分析
- **边界**: 不处理办公文档、不处理编程任务
EOF

# 3. 创建 Agent 配置
cat > ~/.openclaw/agents/financial-assistant/agent/agent.json << 'EOF'
{
  "name": "financial-assistant",
  "displayName": "投资顾问",
  "model": {
    "primary": "custom-coding-dashscope-aliyuncs-com/qwen3.5-plus"
  },
  "workspace": "/home/<USER>/.openclaw/workspace-finance",
  "compaction": {"mode": "safeguard"},
  "channels": {
    "feishu": {
      "enabled": true,
      "appId": "cli_xxxxxxxxxxxxxx",
      "appSecret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "domain": "feishu",
      "connectionMode": "websocket",
      "groupPolicy": "open",
      "dmPolicy": "open",
      "allowFrom": ["*"]
    }
  },
  "tools": {"profile": "coding"}
}
EOF

# 3. 创建 Gateway 配置
cat > ~/.openclaw/gateway-finance.json << 'EOF'
{
  "models": {
    "mode": "merge",
    "providers": {
      "custom-coding-dashscope-aliyuncs-com": {
        "baseUrl": "https://coding.dashscope.aliyuncs.com/v1",
        "apiKey": "sk-xxxxxxxxxxxxxxxxxxxxxxxx",
        "api": "openai-completions"
      }
    }
  },
  "agents": {
    "defaults": {
      "model": {"primary": "custom-coding-dashscope-aliyuncs-com/qwen3.5-plus"},
      "workspace": "/home/<USER>/.openclaw/workspace-finance"
    }
  },
  "tools": {"profile": "coding"},
  "channels": {
    "feishu": {
      "enabled": true,
      "appId": "cli_xxxxxxxxxxxxxx",
      "appSecret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "domain": "feishu",
      "connectionMode": "websocket",
      "groupPolicy": "open",
      "dmPolicy": "open"
    }
  },
  "gateway": {
    "port": 18790,
    "mode": "local",
    "bind": "loopback",
    "auth": {"mode": "token", "token": "your_gateway_token_here"}
  },
  "plugins": {
    "allow": ["feishu"],
    "entries": {"feishu": {"enabled": true}}
  }
}
EOF

# 4. 启动 Gateway
OPENCLAW_CONFIG_PATH=/home/<USER>/.openclaw/gateway-finance.json \
  nohup openclaw gateway run --port 18790 > /tmp/gateway-finance.log 2>&1 &

⚠️ 注意 : workspace 必须指向独立工作区 (workspace-finance/),不能共享!

批量创建脚本

bash 复制代码
#!/bin/bash
# create-assistant.sh

ASSISTANT_NAME=$1
APP_ID=$2
APP_SECRET=$3
PORT=$4

# 创建目录
mkdir -p ~/.openclaw/agents/${ASSISTANT_NAME}/agent

# 创建 Agent 配置
cat > ~/.openclaw/agents/${ASSISTANT_NAME}/agent/agent.json << EOF
{
  "name": "${ASSISTANT_NAME}",
  "displayName": "${ASSISTANT_NAME}",
  "model": {"primary": "custom-coding-dashscope-aliyuncs-com/qwen3.5-plus"},
  "workspace": "/home/<USER>/.openclaw/workspace",
  "compaction": {"mode": "safeguard"},
  "channels": {
    "feishu": {
      "enabled": true,
      "appId": "${APP_ID}",
      "appSecret": "${APP_SECRET}",
      "domain": "feishu",
      "connectionMode": "websocket",
      "groupPolicy": "open",
      "dmPolicy": "open"
    }
  },
  "tools": {"profile": "coding"}
}
EOF

# 创建 Gateway 配置
cat > ~/.openclaw/gateway-${ASSISTANT_NAME}.json << EOF
{
  "models": {
    "mode": "merge",
    "providers": {
      "custom-coding-dashscope-aliyuncs-com": {
        "baseUrl": "https://coding.dashscope.aliyuncs.com/v1",
        "apiKey": "sk-xxxxxxxxxxxxxxxxxxxxxxxx",
        "api": "openai-completions"
      }
    }
  },
  "agents": {
    "defaults": {
      "model": {"primary": "custom-coding-dashscope-aliyuncs-com/qwen3.5-plus"},
      "workspace": "/home/<USER>/.openclaw/workspace"
    }
  },
  "tools": {"profile": "coding"},
  "channels": {
    "feishu": {
      "enabled": true,
      "appId": "${APP_ID}",
      "appSecret": "${APP_SECRET}",
      "domain": "feishu",
      "connectionMode": "websocket",
      "groupPolicy": "open",
      "dmPolicy": "open"
    }
  },
  "gateway": {
    "port": ${PORT},
    "mode": "local",
    "bind": "loopback",
    "auth": {"mode": "token", "token": "your_gateway_token_here"}
  },
  "plugins": {
    "allow": ["feishu"],
    "entries": {"feishu": {"enabled": true}}
  }
}
EOF

# 启动 Gateway
OPENCLAW_CONFIG_PATH=/home/<USER>/.openclaw/gateway-${ASSISTANT_NAME}.json \
  nohup openclaw gateway run --port ${PORT} > /tmp/gateway-${ASSISTANT_NAME}.log 2>&1 &

echo "✅ ${ASSISTANT_NAME} 创建完成,运行在端口 ${PORT}"

配置飞书应用

步骤 1:创建飞书应用

  1. 访问 飞书开放平台
  2. 点击「企业自建应用」→「创建应用」
  3. 填写应用名称(如:投资顾问)
  4. 获取 App IDApp Secret

步骤 2:配置事件订阅

  1. 进入应用 → 「事件与回调」
  2. 选择「使用长连接接收事件/回调」
  3. 点击「添加事件」
  4. 搜索并添加:
    • ✅ 接收消息 v2.0 (im.message.receive_v1)
    • ✅ 群聊消息(如需要)
  5. 保存配置

步骤 3:发布应用

  1. 进入「版本管理与发布」
  2. 点击「发布」
  3. 等待审核通过(通常几分钟)

步骤 4:添加到群聊

方法 A:在飞书客户端添加

  1. 打开飞书 → 进入目标群聊
  2. 点击右上角「设置」→「机器人」
  3. 点击「添加机器人」
  4. 选择你的应用

方法 B:通过@测试

  1. 在群里输入 @
  2. 在列表中找到应用名称
  3. 发送消息测试

启动与测试

启动所有智能体

bash 复制代码
# 主应用
OPENCLAW_CONFIG_PATH=~/.openclaw/gateway-main.json \
  nohup openclaw gateway run --port 18789 > /tmp/gateway-main.log 2>&1 &

# 金融助手
OPENCLAW_CONFIG_PATH=~/.openclaw/gateway-finance.json \
  nohup openclaw gateway run --port 18790 > /tmp/gateway-finance.log 2>&1 &

# 办公助手
OPENCLAW_CONFIG_PATH=~/.openclaw/gateway-office.json \
  nohup openclaw gateway run --port 18800 > /tmp/gateway-office.log 2>&1 &

# 编程助手
OPENCLAW_CONFIG_PATH=~/.openclaw/gateway-programming.json \
  nohup openclaw gateway run --port 18801 > /tmp/gateway-programming.log 2>&1 &

测试职责边界

每个助手应该正确识别自己的职责

bash 复制代码
# 投资顾问测试
# ✅ 应该响应
"帮我查一下茅台股价"
"今天财经新闻"

# ❌ 应该拒绝或引导
"帮我写个 Python 脚本"  → 引导找编程助手
"帮我处理这个 Excel"    → 引导找办公助手

# 办公助手测试
# ✅ 应该响应
"帮我处理这个 Excel"
"转换这个 PDF 为 Word"

# ❌ 应该拒绝或引导
"茅台股价多少"         → 引导找投资顾问
"帮我写个函数"         → 引导找编程助手

# 编程助手测试
# ✅ 应该响应
"帮我写个 Python 函数"
"这段代码有什么 bug"

# ❌ 应该拒绝或引导
"茅台股价多少"         → 引导找投资顾问
"帮我做个 PPT"         → 引导找办公助手

检查状态

bash 复制代码
# 查看所有 Gateway 进程
lsof -i :18789,18790,18800,18801 | grep LISTEN

# 或使用一行命令
ps aux | grep "openclaw gateway" | grep -v grep

测试消息

在每个智能体对应的飞书群里发送测试消息:

智能体 测试消息
虾米 "你好"
投资顾问 "帮我查一下茅台股价"
办公助手 "帮我处理这个 Excel"
编程助手 "帮我写一个 Python 函数"

查看日志

bash 复制代码
# 实时查看日志
tail -f /tmp/gateway-finance.log

# 查看错误
grep -i "error\|failed" /tmp/gateway-finance.log

# 查看消息接收
grep "received message" /tmp/gateway-finance.log

运维管理

工作区管理

bash 复制代码
# 查看工作区
ls -la ~/.openclaw/workspace-*/

# 备份工作区
cp -r ~/.openclaw/workspace-finance ~/.openclaw/workspace-finance.bak

# 清理记忆(谨慎使用)
rm -rf ~/.openclaw/workspace-finance/memory/*

重启单个智能体

bash 复制代码
# 1. 找到 PID
lsof -i :18790 | grep LISTEN | awk '{print $2}'

# 2. 停止
kill <PID>

# 3. 重启
OPENCLAW_CONFIG_PATH=~/.openclaw/gateway-finance.json \
  nohup openclaw gateway run --port 18790 > /tmp/gateway-finance.log 2>&1 &

批量重启脚本

bash 复制代码
#!/bin/bash
# restart-all.sh

PORTS=(18789 18790 18800 18801)
NAMES=(main finance office programming)

for i in "${!PORTS[@]}"; do
  PORT=${PORTS[$i]}
  NAME=${NAMES[$i]}
  
  # 停止
  PID=$(lsof -i :${PORT} | grep LISTEN | awk '{print $2}')
  if [ -n "$PID" ]; then
    kill $PID
    echo "⏹️  已停止 ${NAME} (PID: $PID)"
  fi
  
  sleep 1
  
  # 启动
  OPENCLAW_CONFIG_PATH=~/.openclaw/gateway-${NAME}.json \
    nohup openclaw gateway run --port ${PORT} > /tmp/gateway-${NAME}.log 2>&1 &
  echo "▶️  已启动 ${NAME} (端口:${PORT})"
done

echo "✅ 所有智能体重启完成"

设置开机自启

bash 复制代码
# 创建 launchd 配置文件(macOS)
cat > ~/Library/LaunchAgents/com.openclaw.gateway-main.plist << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.openclaw.gateway-main</string>
    <key>ProgramArguments</key>
    <array>
        <string>/home/<USER>/.nvm/versions/node/v22.22.0/bin/openclaw</string>
        <string>gateway</string>
        <string>run</string>
        <string>--port</string>
        <string>18789</string>
    </array>
    <key>EnvironmentVariables</key>
    <dict>
        <key>OPENCLAW_CONFIG_PATH</key>
        <string>/home/<USER>/.openclaw/gateway-main.json</string>
    </dict>
    <key>RunAtLoad</key>
    <true/>
    <key>StandardOutPath</key>
    <string>/tmp/gateway-main.log</string>
    <key>StandardErrorPath</key>
    <string>/tmp/gateway-main-error.log</string>
</dict>
</plist>
EOF

# 加载配置
launchctl load ~/Library/LaunchAgents/com.openclaw.gateway-main.plist

监控脚本

bash 复制代码
#!/bin/bash
# monitor.sh

PORTS=(18789 18790 18800 18801)
NAMES=(main finance office programming)

echo "=== OpenClaw 智能体状态 ==="
echo ""

for i in "${!PORTS[@]}"; do
  PORT=${PORTS[$i]}
  NAME=${NAMES[$i]}
  
  PID=$(lsof -i :${PORT} | grep LISTEN | awk '{print $2}')
  
  if [ -n "$PID" ]; then
    echo "✅ ${NAME}: 运行中 (PID: $PID, 端口:${PORT})"
  else
    echo "❌ ${NAME}: 未运行 (端口:${PORT})"
  fi
done

故障排查

问题 0:智能体越界

症状: 投资顾问处理编程任务,或办公助手提供投资建议

原因:

  • ❌ 工作区共享(所有助手使用同一个 workspace/
  • ❌ 缺少身份定义(没有 IDENTITY.md

解决方案:

bash 复制代码
# 1. 为每个助手创建独立工作区
mkdir -p ~/.openclaw/workspace-finance/memory
mkdir -p ~/.openclaw/workspace-office/memory
mkdir -p ~/.openclaw/workspace-programming/memory

# 2. 创建身份文件
cat > ~/.openclaw/workspace-finance/IDENTITY.md << 'EOF'
# 投资顾问身份
- **职责**: 股票、基金、财经
- **边界**: 不处理办公文档、不处理编程任务
EOF

# 3. 更新 Gateway 配置
# 编辑 gateway-finance.json,修改 workspace 为独立工作区
"workspace": "/home/<USER>/.openclaw/workspace-finance"

# 4. 重启 Gateway
kill $(lsof -i :18790 | grep LISTEN | awk '{print $2}')
OPENCLAW_CONFIG_PATH=~/.openclaw/gateway-finance.json \
  nohup openclaw gateway run --port 18790 > /tmp/gateway-finance.log 2>&1 &

问题 1:端口被占用

错误信息 : Port 18790 is already in use

解决方案:

bash 复制代码
# 1. 查看占用端口的进程
lsof -i :18790

# 2. 停止占用进程
kill <PID>

# 3. 或修改配置使用其他端口
# 编辑 gateway-finance.json,修改 "port": 18791

问题 2:飞书消息无响应

检查清单:

  1. ✅ 飞书应用是否已发布
  2. ✅ 事件订阅是否配置(接收消息 v2.0)
  3. ✅ 长连接是否启用
  4. ✅ App ID 和 App Secret 是否正确
  5. ✅ Gateway 日志是否有错误

查看日志:

bash 复制代码
# 查看消息接收
grep "received message" /tmp/gateway-finance.log

# 查看错误
grep -i "error\|failed" /tmp/gateway-finance.log

# 查看 WebSocket 连接
grep "WebSocket" /tmp/gateway-finance.log

问题 3:配置无效

错误信息 : Config invalid

解决方案:

bash 复制代码
# 运行 doctor 修复
openclaw doctor --fix

# 或手动检查 JSON 格式
cat ~/.openclaw/gateway-finance.json | python3 -m json.tool

问题 4:智能体无响应

排查步骤:

bash 复制代码
# 1. 检查 Gateway 是否运行
lsof -i :18790 | grep LISTEN

# 2. 检查日志
tail -100 /tmp/gateway-finance.log

# 3. 重启 Gateway
kill <PID>
OPENCLAW_CONFIG_PATH=~/.openclaw/gateway-finance.json \
  nohup openclaw gateway run --port 18790 > /tmp/gateway-finance.log 2>&1 &

# 4. 测试消息
# 在飞书里发送测试消息

常用诊断命令

bash 复制代码
# 查看所有 Gateway 状态
ps aux | grep "openclaw gateway" | grep -v grep

# 查看端口占用
lsof -i :18789,18790,18800,18801 | grep LISTEN

# 查看日志文件
ls -lh /tmp/gateway-*.log

# 查看配置有效性
openclaw doctor

# 测试飞书连接
curl -X POST "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal" \
  -H "Content-Type: application/json" \
  -d '{"app_id":"cli_xxx","app_secret":"xxx"}'

附录:职责边界配置示例

投资顾问身份定义

markdown 复制代码
# IDENTITY.md - 投资顾问

- **名称**: 投资顾问
- **职责**: 股票、基金、财经、投资分析
- **边界**:
  - ✅ 股票行情查询
  - ✅ 基金净值查询
  - ✅ 财经新闻
  - ❌ 不处理办公文档
  - ❌ 不处理编程任务

办公助手身份定义

markdown 复制代码
# IDENTITY.md - 办公助手

- **名称**: 办公助手
- **职责**: Excel、PPT、PDF、文档处理
- **边界**:
  - ✅ Excel 表格处理
  - ✅ PPT 制作优化
  - ✅ PDF 转换编辑
  - ❌ 不提供投资建议
  - ❌ 不处理编程任务

编程助手身份定义

markdown 复制代码
# IDENTITY.md - 编程助手

- **名称**: 编程助手
- **职责**: 代码、调试、架构、技术答疑
- **边界**:
  - ✅ 代码编写
  - ✅ 代码审查
  - ✅ Bug 调试
  - ❌ 不提供投资建议
  - ❌ 不处理办公文档

附录:完整配置示例

主应用配置 (~/.openclaw/agents/main/agent/agent.json)

json 复制代码
{
  "name": "main",
  "displayName": "虾米",
  "model": {
    "primary": "custom-coding-dashscope-aliyuncs-com/qwen3.5-plus"
  },
  "models": {
    "custom-coding-dashscope-aliyuncs-com/qwen3.5-plus": {
      "alias": "coding-qwen3.5-plus"
    }
  },
  "workspace": "/home/<USER>/.openclaw/workspace",
  "compaction": {
    "mode": "safeguard"
  },
  "channels": {
    "feishu": {
      "enabled": true,
      "appId": "cli_xxxxxxxxxxxxxx",
      "appSecret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "domain": "feishu",
      "connectionMode": "websocket",
      "groupPolicy": "open",
      "dmPolicy": "open",
      "allowFrom": ["*"]
    }
  },
  "tools": {
    "profile": "coding"
  }
}

Gateway 配置 (~/.openclaw/gateway-finance.json)

json 复制代码
{
  "models": {
    "mode": "merge",
    "providers": {
      "custom-coding-dashscope-aliyuncs-com": {
        "baseUrl": "https://coding.dashscope.aliyuncs.com/v1",
        "apiKey": "sk-xxxxxxxxxxxxxxxxxxxxxxxx",
        "api": "openai-completions",
        "models": [
          {
            "id": "qwen3.5-plus",
            "name": "qwen3.5-plus",
            "api": "openai-completions",
            "reasoning": false,
            "input": ["text", "image"],
            "cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0},
            "contextWindow": 1000000,
            "maxTokens": 65536
          }
        ]
      }
    }
  },
  "agents": {
    "defaults": {
      "model": {"primary": "custom-coding-dashscope-aliyuncs-com/qwen3.5-plus"},
      "workspace": "/home/<USER>/.openclaw/workspace",
      "compaction": {"mode": "safeguard"},
      "maxConcurrent": 4
    }
  },
  "tools": {"profile": "coding"},
  "channels": {
    "feishu": {
      "enabled": true,
      "appId": "cli_xxxxxxxxxxxxxx",
      "appSecret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "domain": "feishu",
      "connectionMode": "websocket",
      "groupPolicy": "open",
      "dmPolicy": "open",
      "allowFrom": ["*"]
    }
  },
  "gateway": {
    "port": 18790,
    "mode": "local",
    "bind": "loopback",
    "auth": {"mode": "token", "token": "your_gateway_token_here"}
  },
  "plugins": {
    "allow": ["feishu"],
    "entries": {"feishu": {"enabled": true}}
  }
}

快速参考卡

端口分配

智能体 端口 配置文件 日志文件 工作区
虾米 18789 gateway-main.json /tmp/gateway-main.log workspace/
投资顾问 18790 gateway-finance.json /tmp/gateway-finance.log workspace-finance/
办公助手 18800 gateway-office.json /tmp/gateway-office.log workspace-office/
编程助手 18801 gateway-programming.json /tmp/gateway-programming.log workspace-programming/

常用命令

bash 复制代码
# 启动
OPENCLAW_CONFIG_PATH=~/.openclaw/gateway-xxx.json nohup openclaw gateway run --port XXXX > /tmp/gateway-xxx.log 2>&1 &

# 停止
kill $(lsof -i :XXXX | grep LISTEN | awk '{print $2}')

# 查看状态
lsof -i :XXXX | grep LISTEN

# 查看日志
tail -f /tmp/gateway-xxx.log

文档版本 : v1.0
最后更新 : 2026-03-20
维护者: 本文档有虾米自动生成

相关推荐
arvin_xiaoting3 小时前
OpenClaw学习总结_I_核心架构系列_AgentLoop详解
java·学习·架构·llm·ai-agent·飞书机器人·openclaw
坐吃山猪3 小时前
OpenClaw08_监听器
源码·openclaw
zhangyifang_0093 小时前
openclaw常用命令
openclaw
huazi-J3 小时前
Datawhale openclaw 课程 task2:clawX本地openclaw使用skill
llm·datawhale·openclaw·龙虾
gallonyin4 小时前
【企业级龙虾】LLM Gateway 工程化落地:配置中心、429故障转移与统计持久化实战
gateway·openclaw
Web极客码4 小时前
OpenAI GPT-5.2-Codex (High) vs. Claude Opus 4.5 vs. Gemini 3 Pro:真实场景编程大横评
ai编程·claude code·claude skill·openclaw
API开发4 小时前
一个MCP操作所有的数据库
数据库·api·api接口·apisql·mcp·mcpserver·openclaw
supersolon4 小时前
OpenClaw安装碰到的一些问题和解决方法
linux·运维·ai·openclaw·龙虾
海兰5 小时前
【安全】OpenClaw 安全配置基础
安全·agent·openclaw