Skip to main content

NanoBot

  • HKUDS/nanobot
    • MIT, Python
    • 超轻量个人 AI 助手框架,受 OpenClaw 启发
    • 核心代码 ~3500 行(OpenClaw 的 1%)
    • 支持 9 渠道: Telegram, Discord, WhatsApp, Feishu, DingTalk, Slack, Email, QQ, Mochat
    • LiteLLM 统一 12+ LLM Provider,支持 vLLM 本地模型

架构

Channel (Telegram/Discord/...) ──→ MessageBus (inbound queue)


AgentLoop
│ 1. get_or_create session
│ 2. build_messages (system + history + user)
│ 3. provider.chat (LiteLLM)
│ 4. execute tool_calls (max 20 轮)
│ 5. save session


MessageBus (outbound queue)


ChannelManager._dispatch_outbound()
│ 按 msg.channel 路由

Channel.send() ──→ 用户

核心模块

模块作用
agent/loop.pyAgentLoop:消息处理引擎,LLM调用+工具执行循环
agent/context.pyContextBuilder:组装 system prompt(identity + bootstrap + memory + skills)
agent/memory.pyMemoryStore:workspace 下 MEMORY.md 持久化记忆
agent/skills.pySkillsLoader:技能加载(always-load + on-demand)
agent/subagent.pySubagentManager:后台子任务
bus/queue.pyMessageBus:双 asyncio.Queue 解耦 channel↔agent
bus/events.pyInboundMessage / OutboundMessage 数据类
channels/base.pyBaseChannel ABC:start/stop/send + allowFrom 权限
channels/manager.pyChannelManager:初始化+启动+路由所有渠道
providers/registry.pyProviderSpec 注册表:12 个 provider 元数据
providers/litellm_provider.pyLiteLLM 封装:统一 LLM 调用接口
session/manager.pySessionManager:JSONL 文件持久化会话
config/schema.pyPydantic Config:JSON 配置定义

工具

read_file, write_file, edit_file, list_dir, exec (shell), web_search (Brave), web_fetch, message, spawn (子agent), cron

Provider 注册 (ProviderSpec)

添加 provider 只需 2 步:在 registry.pyProviderSpec + 在 schema.py 加配置字段。

支持:OpenRouter, AiHubMix (gateway), Anthropic, OpenAI, DeepSeek, Gemini, Zhipu, DashScope, Moonshot, MiniMax, vLLM, Groq

与 OpenClaw 对比

维度NanoBotOpenClaw
语言PythonTypeScript (ESM)
代码量~3,500 行~430,000 行
定位轻量研究/个人助手生产级多渠道 AI 网关
渠道数9 (硬编码)8 内置 + 35 扩展插件
渠道架构BaseChannel ABC + ChannelManager 硬编码 if/elseChannelPlugin adapter 模式 + 独立 workspace packages
消息总线MessageBus:双 asyncio.QueuedispatchInboundMessagegetReplyFromConfig 管道
ProviderLiteLLM + ProviderSpec 注册表自建 provider 抽象 + 多粒度 model 解析
SessionJSONL 文件 (channel:chat_id)多层 session store + 6 级路由绑定
路由channel:chat_id 简单 keypeer→guild→team→account→channel→default 6 级
流式回复❌ 无✅ block streaming + thinking tag 过滤
API 兼容❌ 无 HTTP API✅ OpenAI 兼容 /v1/chat/completions
配置JSON + PydanticJSON5 + Zod + 热重载 + 遗留迁移
客户端CLI onlyCLI + WebSocket + Control UI + macOS/iOS/Android
子任务spawn tool + SubagentManager内置 subagent 注册表
定时任务cron tool + CronService内置 cron service
Skillsworkspace SKILL.md(always-load + on-demand)skills/ 目录 + remote skills
MemoryMEMORY.md 文件多种 session store