乐于分享
好东西不私藏

Nanobot 轻量级的个人AI助手

Nanobot 轻量级的个人AI助手

Nanobot是什么

Nanobot是一款超轻量级的个人AI助手,灵感来源于OpenClaw,该项目实现了从飞书 钉钉等聊天应用发送命令到Nanbot,从而实现用户只需要通过 手机操作就能让大模型干活的理想生活。该项目也实现了怎么用Tool以及MCP服务以及Skill的能力,于此同时也实现了如何在上下文爆炸的情况如何进行有效的压缩。 通过这个项目能够让想要了解和认知大模型能干什么,怎么做,以及它的边界在哪里提供了一系列的思路。

Nanobot的整体流程架构图

┌──────────────────────────────────────────────────────────────────────────────────────────────┐
│                              nanobot AI Assistant                              │
├──────────────────────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│  ┌────────────────┐     ┌────────────────┐     ┌────────────────┐            │
│  │    CLI         │     │   Gateway     │     │  Channel      │            │
│  │ commands.py   │────►│  (entry)     │────►│  Manager     │            │
│  │ (onboard,    │     │              │     │              │            │
│  │  agent,      │     └──────┬───────┘     └──────┬───────┘            │
│  │  gateway)    │            │                    │                     │
│  └──────┬───────┘            │                    ▼                     │
│         │            ┌──────▼───────┐     ┌──────────────────┐             │
│         │            │ Message Bus  │     │  13+ Channels   │             │
│         │            │  (bus/)     │     │ (telegram,      │             │
│         │            │             │     │  discord,       │             │
│         │            │ InboundMsg  │     │  feishu,        │             │
│         │            │ OutboundMsg │     │  slack, ...)    │             │
│         │            └──────┬─────┘     └────────┬─────────┘             │
│         │                   │                   │                        │
│         │                   ▼                   │                        │
│         │            ┌──────────────┐         │                        │
│         │            │Agent Loop   │◄────────┘                        │
│         │            │ (agent/)   │                                 │
│         │            │            │                                 │
│         │  ┌────────┼───────────┼───────────┐                      │
│         │  │        │           │           │                       │
│         │  ▼        ▼           ▼           ▼                      │
│         │ ┌──────────┐ ┌──────────┐ ┌──────────┐                  │
│         │ │Context  │ │ Memory  │ │Sessions │                    │
│         │ │Builder │ │Consolid │ │Manager │                     │
│         │ └────────┘ └────────┘ └──────────┘                    │
│         │                                                       │
│         │            ┌─────────────────────┐                   │
│         │            │   Tool Registry    │                   │
│         │            │                     │                   │
│         │            │ ┌─────┐ ┌────┐ ┌───┴───┐              │
│         │            │ │web  │ │msg │ │spawn │                │
│         │            │ │search│ │tool│ │tool  │              │
│         │            ├──────┼────┼─────┼──────┤              │
│         │            │file  │ │shell│ │cron  │               │
│         │            │tools │ │exec │ │tool  │               │
│         │            └──────┘ └─────┘ └──────┘               │
│         │            ┌─────────────────────┐                 │
│         │            │   MCP Servers      │                  │
│         │            │ (optional)        │                   │
│         │            └─────────────────────┘                 │
│         │                                                    │
│         └───────────────► LLM Provider                       │
│                              │                               │
│                              ▼                               │
│  ┌────────────────────────────────────────────────--┐        │
│  │            20+ LLM Providers                     │        │
│  │                                                  │        │
│  │ OpenAI  Anthropic  OpenRouter  DeepSeek          │        │
│  │ Azure   Groq     Ollama (local)                  │        │
│  │ (any OpenAI-compatible API)                      │        │
│  └────────────────────────────────────────────-----─┘        │
│                                                             │
│  ┌──────────────┐   ┌────────────-─-┐   ┌──────────────┐   │
│  │   Cron       │   │  Heartbeat    │   │   Skills     │   │
│  │ (scheduled   │◄──│ (periodic     │◄──│ (built-in    │   │
│  │  tasks)      │   │  tasks)       │   │  +custom)    │   │
│  └────────────--┘   └──────┬─────--─┘   └─────────────-┘   │
│                            │                               │
└─────────────────────────--─┼──────────────────────────────---┘
                             │
                             ▼
          ┌────────────────────────────────────┐
          │   External Platforms / APIs        │
          │                                    │
          │ Telegram API   Discord API         │
          │ Feishu WebSocket  Slack Socket     │
          │ WhatsApp Bridge  LLM Providers     │
          └────────────────────────────────────┘

消息流详解

1. 用户消息 (Telegram/Discord/Feishu/...)
         │
         ▼
2. Channel._handle_message() ── 权限检查 (allowFrom)
         │
         ▼
3. MessageBus.publish_inbound(InboundMessage)
         │
         ▼
4. AgentLoop._dispatch() ── 会话锁 + 并发控制
         │
         ├──► SessionManager.get_or_create() ── 加载会话历史
         ├──► ContextBuilder.build_messages() ── 构建Prompt
         │         │
         │         ├──► SkillsLoader.load_skills() ── 加载技能
         │         └──► MemoryConsolidator ── 记忆合并
         │
         ▼
5. AgentLoop._run_agent_loop() ── 核心循环
         │
         ├──► Provider.chat_with_retry() ── 调用LLM
         │         │
         │    ┌────┴────┐
         │    ▼        ▼
         │ 有tool_calls   无tool_calls
         │    │          │
         │    ▼          ▼
         │ 执行工具   返回结果
         │    │   
         │    ▼
         │ 添加工具结果到消息
         │    │
         │    └───────► 重复调用LLM (最多40次)
         │
         ▼
6. MessageBus.publish_outbound(OutboundMessage)
         │
         ▼
7. ChannelManager.send() ── 路由到对应Channel
         │
         ▼
8. Channel.send() ── 发送到外部平台
         │
         ▼
9. 用户收到回复

使用配置

安装

对于初试者来说,建议从源码中安装:

git clone https://github.com/HKUDS/nanobot.git
cd nanobot
pip install -e .

配置

这里我们 飞书 为聊天工具端为例子 对于 飞书来说需要在飞书开发平台开启机器人,具体的可以参考Chat Apps中的FeiShu模块配置完后,会有对应的App IDApp Secret,需要配置到~/.nanobot/config.json目录下

"feishu": {
"enabled"true,
"appId""xxx",
"appSecret""xxx",
"encryptKey""",
"verificationToken""",
"allowFrom": ["*"],
"reactEmoji""THUMBSUP",
"groupPolicy""mention",
"replyToMessage"false
    }

于此同时我们可以配置一个默认的大模型,这里我们以deepseek为例子:

agents": {
    "
defaults": {
      "
workspace": "~/.nanobot/workspace",
      "
model": "deepseek-chat",
      "
provider": "auto",
      "
maxTokens": 8192,
      "
contextWindowTokens": 65536,
      "
temperature": 0.1,
      "
maxToolIterations": 40,
      "
reasoningEffort": null,
      "
timezone": "Asia/Shanghai"
    }
  }
...
"
providers": {
    "
deepseek": {
      "
apiKey": "sk-xxx",
      "
apiBase": "https://api.deepseek.com/v1",
      "
extraHeaders": null
    },
}

对于deepseek模型,可以去DeepSeek开发平台注册账号就ok,同时生成apiKey

启动

初始化

nanobot onboard

启动gateway

nanobot gateway

至此,可以在feishu上给Nanobot发送消息,并进行