🐈 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 行


🎯 核心亮点

特性nanobotClawdbot
代码行数~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
WhatsApp中等扫码连接
飞书中等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
AnthropicClaude 直连console.anthropic.com
OpenAIGPT 直连platform.openai.com
DeepSeekDeepSeek 直连platform.deepseek.com
GroqLLM + 语音转写(Whisper)console.groq.com
GeminiGemini 直连aistudio.google.com
Moonshot/KimiKimi 直连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/            # 🖥️ 命令行

🔗 相关链接


🎯 总结

nanobot 是学习和研究 AI Agent 的绝佳项目。11K+ stars 证明了社区的认可。如果你想:

  • 🔬 学习 AI Agent 原理:3,400 行代码,清晰易懂
  • 🛠️ 二次开发:极简代码库,容易修改
  • ⚡️ 快速部署:轻量级,资源占用低
  • 📱 多端使用:Telegram/Discord/WhatsApp/飞书

nanobot 就是最好的选择!

💡 立即体验:

pip install nanobot-ai
nanobot onboard
nanobot agent -m "Hello nanobot!"

发表回复

后才能评论