🐈 nanobot:超轻量 AI 助手,仅 3400 行代码实现 Clawdbot 99% 功能(11K Stars)
Clawdbot/OpenClaw 功能强大,但代码量超过 43 万行,对于想二次开发或学习的人来说门槛太高。nanobot 应运而生——用仅仅 3,400 行代码 实现了 Clawdbot 99% 的核心功能,代码量缩小了 99%!
📌 项目简介
nanobot 是一个超轻量的个人 AI 助手,灵感来自 Clawdbot。它专为研究和学习设计,代码干净可读,易于理解、修改和扩展。
🔗 开源地址:https://github.com/HKUDS/nanobot
📦 PyPI:nanobot-ai
💬 Discord:加入社区
⭐ GitHub Stars:11K+ | 📏 代码行数:3,428 行
🎯 核心亮点
| 特性 | nanobot | Clawdbot |
|---|---|---|
| 代码行数 | ~3,400 行 | 430,000+ 行 |
| 体积缩减 | 99% 更小 | |
| 启动速度 | 极快 | 较慢 |
| 资源占用 | 极低 | 较高 |
| 可读性 | 极高(研究友好) | 较复杂 |
- 🪶 超轻量:3,400 行核心代码,比 Clawdbot 小 99%
- 🔬 研究友好:代码干净可读,易于理解和修改
- ⚡️ 极速启动:最小化占用,快速迭代
- 💎 一键部署:开箱即用
✨ 功能展示
| 场景 | 描述 |
|---|---|
| 📈 实时市场分析 | 24/7 发现洞察、追踪趋势 |
| 🚀 全栈开发 | 开发、部署、扩展 |
| 📅 日程管理 | 安排、自动化、组织 |
| 📚 知识助手 | 学习、记忆、推理 |
📥 快速开始
安装
# 方式一:PyPI 安装(稳定版)
pip install nanobot-ai
# 方式二:uv 安装(更快)
uv tool install nanobot-ai
# 方式三:源码安装(最新功能)
git clone https://github.com/HKUDS/nanobot.git
cd nanobot
pip install -e .
初始化
nanobot onboard
配置
编辑 ~/.nanobot/config.json:
{
"providers": {
"openrouter": {
"apiKey": "sk-or-v1-xxx"
}
},
"agents": {
"defaults": {
"model": "anthropic/claude-opus-4-5"
}
},
"tools": {
"web": {
"search": {
"apiKey": "BSA-xxx"
}
}
}
}
💡 API Key 获取:OpenRouter(LLM)· Brave Search(可选)
开始对话
# 单条消息
nanobot agent -m "What is 2+2?"
# 交互模式
nanobot agent
🎉 2 分钟搞定一个可用的 AI 助手!
🖥️ 本地模型(vLLM)
使用 vLLM 或任何 OpenAI 兼容服务器运行本地模型:
# 1. 启动 vLLM 服务
vllm serve meta-llama/Llama-3.1-8B-Instruct --port 8000
# 2. 配置 config.json
{
"providers": {
"vllm": {
"apiKey": "dummy",
"apiBase": "http://localhost:8000/v1"
}
},
"agents": {
"defaults": {
"model": "meta-llama/Llama-3.1-8B-Instruct"
}
}
}
# 3. 对话
nanobot agent -m "Hello from my local LLM!"
💬 多渠道接入
通过 Telegram、Discord、WhatsApp、飞书随时随地和你的 nanobot 对话:
| 渠道 | 配置难度 | 说明 |
|---|---|---|
| Telegram | 简单 | 只需一个 Token |
| Discord | 简单 | Bot Token + Intents |
| 中等 | 扫码连接 | |
| 飞书 | 中等 | App 凭证(WebSocket 无需公网 IP) |
Telegram 配置示例
// config.json
{
"channels": {
"telegram": {
"enabled": true,
"token": "YOUR_BOT_TOKEN",
"allowFrom": ["YOUR_USER_ID"]
}
}
}
// 运行
nanobot gateway
🤖 支持的 LLM 提供商
| 提供商 | 用途 | 获取 API Key |
|---|---|---|
| OpenRouter | 推荐,访问所有模型 | openrouter.ai |
| Anthropic | Claude 直连 | console.anthropic.com |
| OpenAI | GPT 直连 | platform.openai.com |
| DeepSeek | DeepSeek 直连 | platform.deepseek.com |
| Groq | LLM + 语音转写(Whisper) | console.groq.com |
| Gemini | Gemini 直连 | aistudio.google.com |
| Moonshot/Kimi | Kimi 直连 | platform.moonshot.cn |
⏰ 定时任务
# 添加定时任务
nanobot cron add --name "daily" --message "Good morning!" --cron "0 9 * * *"
nanobot cron add --name "hourly" --message "Check status" --every 3600
# 列出任务
nanobot cron list
# 删除任务
nanobot cron remove
🐳 Docker 部署
# 构建镜像
docker build -t nanobot .
# 初始化配置(首次)
docker run -v ~/.nanobot:/root/.nanobot --rm nanobot onboard
# 编辑配置添加 API Key
vim ~/.nanobot/config.json
# 运行 Gateway
docker run -v ~/.nanobot:/root/.nanobot -p 18790:18790 nanobot gateway
# 单条命令
docker run -v ~/.nanobot:/root/.nanobot --rm nanobot agent -m "Hello!"
🛠️ CLI 命令速查
| 命令 | 描述 |
|---|---|
nanobot onboard | 初始化配置和工作区 |
nanobot agent -m "..." | 发送单条消息 |
nanobot agent | 交互式对话 |
nanobot gateway | 启动网关(Telegram/WhatsApp 等) |
nanobot status | 查看状态 |
nanobot channels login | 连接 WhatsApp(扫码) |
nanobot channels status | 查看渠道状态 |
📁 项目结构
nanobot/
├── agent/ # 🧠 核心 Agent 逻辑
│ ├── loop.py # Agent 循环 (LLM ↔ 工具执行)
│ ├── context.py # Prompt 构建
│ ├── memory.py # 持久化记忆
│ ├── skills.py # 技能加载
│ └── tools/ # 内置工具
├── skills/ # 🎯 内置技能 (github, weather, tmux...)
├── channels/ # 📱 消息渠道
├── bus/ # 🚌 消息路由
├── cron/ # ⏰ 定时任务
├── heartbeat/ # 💓 心跳检测
├── providers/ # 🤖 LLM 提供商
├── session/ # 💬 会话管理
├── config/ # ⚙️ 配置
└── cli/ # 🖥️ 命令行
🔗 相关链接
- GitHub:https://github.com/HKUDS/nanobot
- PyPI:nanobot-ai
- Discord:加入社区
🎯 总结
nanobot 是学习和研究 AI Agent 的绝佳项目。11K+ stars 证明了社区的认可。如果你想:
- 🔬 学习 AI Agent 原理:3,400 行代码,清晰易懂
- 🛠️ 二次开发:极简代码库,容易修改
- ⚡️ 快速部署:轻量级,资源占用低
- 📱 多端使用:Telegram/Discord/WhatsApp/飞书
nanobot 就是最好的选择!
💡 立即体验:
pip install nanobot-ai
nanobot onboard
nanobot agent -m "Hello nanobot!"
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。




