一、安装教程
1.1 下载
使用默认命令安装可能会遇到环境管理错误:
git clone https://github.com/HKUDS/nanobot.git
cd nanobot
pip install -e .
⚠️ 注意事项: 若 pip install -e . 报错 externally-managed-environment,建议使用 uv 进行安装,以避免环境冲突。
推荐:使用 UV 安装
-
安装 uv
curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.local/bin/env
uv --version -
安装 nanobot
uv tool install nanobot-ai
-
验证安装
nanobot --help
1.2 Nanobot 初始化配置
运行以下命令开始配置流程:
nanobot onboard
1.3 Config.json 配置
编辑配置文件:
nano ~/.nanobot/config.json
以下是完整的配置模版(请根据实际情况修改 Key 和模型名):
{
"agents": {
"defaults": {
"workspace": "~/.nanobot/workspace",
"model": "openai/glm-4.7",
"maxTokens": 10240,
"temperature": 0.7,
"maxToolIterations": 20
}
},
"channels": {
"whatsapp": {
"enabled": false,
"bridgeUrl": "ws://localhost:3001",
"allowFrom": []
},
"telegram": {
"enabled": false,
"token": "",
"allowFrom": [],
"proxy": null
},
"discord": {
"enabled": false,
"token": "",
"allowFrom": [],
"gatewayUrl": "wss://gateway.discord.gg/?v=10&encoding=json",
"intents": 37377
},
"feishu": {
"enabled": false,
"appId": "",
"appSecret": "",
"encryptKey": "",
"verificationToken": "",
"allowFrom": []
},
"dingtalk": {
"enabled": false,
"clientId": "",
"clientSecret": "",
"allowFrom": []
},
"email": {
"enabled": false,
"consentGranted": false,
"imapHost": "",
"imapPort": 993,
"imapUsername": "",
"imapPassword": "",
"imapMailbox": "INBOX",
"imapUseSsl": true,
"smtpHost": "",
"smtpPort": 587,
"smtpUsername": "",
"smtpPassword": "",
"smtpUseTls": true,
"smtpUseSsl": false,
"fromAddress": "",
"autoReplyEnabled": true,
"pollIntervalSeconds": 30,
"markSeen": true,
"maxBodyChars": 12000,
"subjectPrefix": "Re: ",
"allowFrom": []
},
"slack": {
"enabled": false,
"mode": "socket",
"webhookPath": "/slack/events",
"botToken": "",
"appToken": "",
"userTokenReadOnly": true,
"groupPolicy": "mention",
"groupAllowFrom": [],
"dm": {
"enabled": true,
"policy": "open",
"allowFrom": []
}
},
"qq": {
"enabled": false,
"appId": "",
"secret": "",
"allowFrom": []
}
},
"providers": {
"anthropic": {
"apiKey": "",
"apiBase": null,
"extraHeaders": null
},
"openai": {
"apiKey": "密钥XXXXXX",
"apiBase": "https://open.bigmodel.cn/api/paas/v4",
"extraHeaders": null
},
"openrouter": {
"apiKey": "",
"apiBase": null,
"extraHeaders": null
},
"deepseek": {
"apiKey": "",
"apiBase": null,
"extraHeaders": null
},
"groq": {
"apiKey": "",
"apiBase": null,
"extraHeaders": null
},
"zhipu": {
"apiKey": "",
"apiBase": "https://docs.litellm.ai/docs/providers",
"extraHeaders": null
},
"dashscope": {
"apiKey": "",
"apiBase": null,
"extraHeaders": null
},
"vllm": {
"apiKey": "",
"apiBase": null,
"extraHeaders": null
},
"gemini": {
"apiKey": "",
"apiBase": null,
"extraHeaders": null
},
"moonshot": {
"apiKey": "",
"apiBase": null,
"extraHeaders": null
},
"aihubmix": {
"apiKey": "",
"apiBase": null,
"extraHeaders": null
}
},
"gateway": {
"host": "0.0.0.0",
"port": 18790
},
"tools": {
"web": {
"search": {
"apiKey": "",
"maxResults": 5
}
},
"exec": {
"timeout": 60
},
"restrictToWorkspace": false
}
}
💡 配置提示:
- 确保
providers.openai.apiBase指向智谱的官方地址。 - 原文中
zhipu.apiBase指向了文档地址,代码中已修正为 API 地址,以避免潜在错误。
二、验证
配置完成后,运行以下命令验证效果:
nanobot agent -m "what is 2 + 2"
效果:
