前言
OpenClaw作为开源AI Agent框架,核心优势在于本地部署、数据安全、企业微信原生接入。
本文将完整介绍从零开始部署OpenClaw的全流程,包括环境准备、项目部署、模型配置、企微接入四个阶段,更完整的技术细节、配置参数、API文档,可以参考《OpenClaw完全使用手册》。
一、环境准备
1.1 系统要求
| 组件 | 最低要求 | 推荐配置 |
|---|---|---|
| 操作系统 | Windows 10/macOS 10.15 | Windows 11/macOS 12+ |
| Node.js | 12.x | 18.x LTS |
| 内存 | 4GB | 8GB+ |
| 磁盘空间 | 2GB | 5GB+ |
1.2 安装Node.js
Windows环境:
- 访问 https://nodejs.org/
- 下载LTS版本安装包
- 双击安装,一路下一步
- 打开命令行验证:
bash
node -v
npm -v
macOS环境:
bash
# 使用Homebrew安装
brew install node
# 验证安装
node -v
npm -v
1.3 配置npm镜像源(国内用户)
bash
# 设置淘宝镜像源
npm config set registry https://registry.npmmirror.com
# 验证配置
npm config get registry
二、项目部署
2.1 克隆项目
官方版本:
bash
git clone https://github.com/OpenClaw/openclaw.git
cd openclaw
中文社区版本(推荐国内用户):
bash
git clone https://github.com/OpenClaw/openclaw-chinese.git
cd openclaw-chinese
2.2 安装依赖
bash
npm install
如果遇到依赖安装失败,尝试:
bash
# 清除缓存
npm cache clean --force
# 重新安装
npm install
2.3 启动项目
开发模式:
bash
npm run start
生产模式:
bash
npm run build
npm run serve
2.4 验证安装
浏览器访问:http://localhost:3000/
如果看到OpenClaw界面,说明安装成功。
三、模型配置
OpenClaw支持多种AI模型,以下介绍几种常见配置。
3.1 DeepSeek配置
步骤1:获取API Key
- 访问 https://platform.deepseek.com/
- 注册账号并登录
- 在"API Keys"页面创建新密钥
步骤2:配置OpenClaw
编辑配置文件 ~/.openclaw/config/preferences.json:
json
{
"agents": {
"defaults": {
"model": "deepseek-chat"
}
},
"models": {
"providers": {
"deepseek": {
"api_key": "sk-xxxxxxxxxxxxxxxx",
"base_url": "https://api.deepseek.com"
}
}
}
}
步骤3:验证配置
在OpenClaw界面发送消息,检查是否能正常回复。
3.2 腾讯云DeepSeek配置
腾讯云提供DeepSeek API服务,适合企业用户。
步骤1:开通服务
- 登录腾讯云控制台
- 开通"DeepSeek API"服务
- 获取SecretId和SecretKey
步骤2:配置OpenClaw
json
{
"agents": {
"defaults": {
"model": "tencent/deepseek-chat"
}
},
"models": {
"providers": {
"tencent": {
"secret_id": "your-secret-id",
"secret_key": "your-secret-key",
"base_url": "https://api.tencentcloudapi.com"
}
}
}
}
3.3 飞桨PaddlePaddle配置
适合中文场景优化。
步骤1:安装飞桨
bash
pip install paddlepaddle
步骤2:配置OpenClaw
json
{
"agents": {
"defaults": {
"model": "paddle/glm-4.7"
}
},
"models": {
"providers": {
"paddle": {
"api_key": "your-api-key",
"base_url": "https://open.paddlepaddle.org/api/v1"
}
}
}
}
四、企业微信接入
4.1 创建企业微信机器人
步骤1:打开企业微信管理后台
- 登录 https://work.weixin.qq.com/
- 进入"应用管理"页面
步骤2:创建应用
- 点击"自建应用"
- 填写应用名称、Logo
- 记录AgentId和Secret
步骤3:配置API接收
- 在应用详情页找到"API接收消息"
- 记录Token和EncodingAESKey
4.2 配置OpenClaw
编辑配置文件:
json
{
"channels": {
"wecom": {
"corp_id": "your-corp-id",
"agent_id": "your-agent-id",
"secret": "your-secret",
"token": "your-token",
"encoding_aes_key": "your-encoding-aes-key"
}
}
}
4.3 验证接入
在企业微信中找到创建的应用,发送消息测试。
五、高级配置
5.1 定时任务配置
OpenClaw支持定时任务,可以在指定时间自动执行操作。
示例配置:
json
{
"cron": {
"tasks": [
{
"schedule": "0 10 * * *",
"action": "send_message",
"message": "早上好!今日资讯推送..."
},
{
"schedule": "0 18 * * 1-5",
"action": "send_message",
"message": "下班提醒:请记得打卡!"
}
]
}
}
Cron表达式说明:
┌───────────── 分钟 (0 - 59)
│ ┌───────────── 小时 (0 - 23)
│ │ ┌───────────── 日 (1 - 31)
│ │ │ ┌───────────── 月 (1 - 12)
│ │ │ │ ┌───────────── 星期 (0 - 6)
│ │ │ │ │
* * * * *
5.2 系统管理配置
自动启动/停机:
json
{
"system": {
"auto_start": "0 2 * * 1",
"auto_stop": "0 2 * * 6"
}
}
系统备份:
json
{
"backup": {
"schedule": "0 2 * * 4",
"retention_days": 30
}
}
5.3 权限控制
OpenClaw提供四级权限模式:
| 模式 | 权限范围 |
|---|---|
| Full | 完全访问权限 |
| Coding | 可执行代码,不可访问敏感文件 |
| Chat | 仅对话,不可访问文件系统 |
| Minimal | 最小权限,仅基础对话 |
配置示例:
json
{
"agents": {
"defaults": {
"permission": "chat"
}
}
}
六、常见问题
Q1:npm install很慢怎么办?
**方案:**使用国内镜像源
bash
npm config set registry https://registry.npmmirror.com
Q2:启动后无法访问localhost:3000?
排查步骤:
- 检查端口是否被占用
bash
# Windows
netstat -ano | findstr :3000
# macOS/Linux
lsof -i :3000
- 检查防火墙设置
Q3:企业微信接入失败?
常见原因:
- AgentId或Secret配置错误
- IP白名单未设置
- 应用未发布
Q4:模型调用失败?
排查步骤:
- 检查API Key是否正确
- 检查账户余额
- 检查网络连接
七、部署检查清单
| 阶段 | 检查项 | 状态 |
|---|---|---|
| 环境准备 | Node.js已安装 | ☐ |
| 环境准备 | npm镜像源已配置 | ☐ |
| 项目部署 | 项目已克隆 | ☐ |
| 项目部署 | 依赖已安装 | ☐ |
| 项目部署 | 服务已启动 | ☐ |
| 模型配置 | API Key已获取 | ☐ |
| 模型配置 | 配置文件已编辑 | ☐ |
| 模型配置 | 模型调用正常 | ☐ |
| 企微接入 | 机器人已创建 | ☐ |
| 企微接入 | 配置已填写 | ☐ |
| 企微接入 | 消息收发正常 | ☐ |
结语
OpenClaw的本地部署并不复杂,关键是按照步骤逐一完成。
环境准备→项目部署→模型配置→企微接入,四个阶段走完,就能在企业微信里使用AI Agent了。
更完整的技术细节、配置参数、API文档,可以参考《OpenClaw完全使用手册》。