nanobot Architecture: Understanding the 4,000-Line AI Framework

Deep dive into the nano bot's modular, research-friendly design

Explore the clean, understandable architecture that makes nanobot ai so accessible

nanobot Architecture Overview

The nano bot is built with a modular, layered architecture that separates concerns while maintaining simplicity. Every component is designed to be understandable and modifiable by developers.

Modular Design

The nanobot ai architecture divides functionality into clear modules: agent core, channels, providers, tools, and cron. Each module has a specific responsibility, making the nano bot codebase easy to navigate and understand.

Layered Architecture

The nanobot uses a layered approach: agent core orchestrates conversations, providers supply LLM capabilities, channels handle platforms, and tools enable actions. Clean separation of concerns throughout the nano bot.

~4,000 Lines Total

The entire nanobot ai framework fits in approximately 4,000 lines of Python code. This is 99% smaller than Clawdbot (430,000+ lines) while retaining core functionality. Extreme simplification without sacrificing capability.

Research-Friendly

The nano bot architecture is designed for research and learning. Clean code, clear structure, minimal complexity. Developers can comprehend the entire nanobot system in days instead of weeks.

nanobot Directory Structure

The nano bot organizes code into a clear directory structure. Each directory contains related functionality, making the nanobot ai codebase intuitive to navigate.

nanobot/ ├── nanobot/ │ ├── agent/ # Agent Core │ │ ├── context.py # ContextBuilder - system prompt construction │ │ └── memory.py # Memory System - long/short-term memory │ ├── channels/ # Communication Channels │ │ ├── telegram/ # Telegram integration │ │ ├── discord/ # Discord integration │ │ ├── whatsapp/ # WhatsApp integration │ │ ├── slack/ # Slack integration │ │ ├── email/ # Email integration │ │ ├── qq/ # QQ integration │ │ ├── dingtalk/ # DingTalk integration │ │ ├── feishu/ # Feishu integration │ │ └── mochat/ # Mochat integration │ ├── providers/ # LLM Providers │ │ ├── openrouter.py # OpenRouter integration │ │ ├── anthropic.py # Anthropic (Claude) │ │ ├── openai.py # OpenAI (GPT) │ │ ├── deepseek.py # DeepSeek │ │ ├── gemini.py # Google Gemini │ │ ├── zhipu.py # Zhipu (智谱) │ │ ├── dashscope.py # DashScope │ │ ├── moonshot.py # Moonshot │ │ ├── groq.py # Groq │ │ ├── aihubmix.py # AiHubMix │ │ └── vllm.py # vLLM (local models) │ ├── tools/ # Tool Registry │ │ ├── file_ops.py # File operations │ │ ├── shell.py # Shell command execution │ │ └── web.py # Web access │ └── cron/ # Cron System │ └── scheduler.py # Job scheduling (apscheduler) ├── pyproject.toml # Project configuration └── README.md # Documentation

Architecture Principles

Clarity: Every file has a clear purpose
Simplicity: No unnecessary complexity
Modularity: Components are independent
Extensibility: Easy to add new capabilities

nanobot Agent Core Components

The agent core is the heart of the nano bot. It orchestrates conversations, manages context, and coordinates tool execution. Two primary files handle all core functionality.

🧠

ContextBuilder (context.py)

Purpose: Constructs system prompts for LLM calls
Responsibilities: Combines personality, memory, tools, and conversation history

The nanobot ContextBuilder automatically includes:

  • Base personality and instructions
  • Long-term memory (MEMORY.md)
  • Short-term memory (daily notes)
  • Available tools and descriptions
  • Recent conversation history

Every nano bot conversation starts with a complete context built by this component.

💾

Memory System (memory.py)

Purpose: Manages long-term and short-term memory
Redesigned: February 12, 2026 for improved reliability

The nanobot ai memory system handles:

  • Long-term memory: MEMORY.md (persistent knowledge)
  • Short-term memory: memory/YYYY-MM-DD.md (daily notes)
  • Hybrid search: 70% vector + 30% BM25
  • Automatic context: Memory included in every conversation

The redesigned memory system uses less code while being more reliable.

Learn More: Deep dive into the nanobot Memory System for complete details on how memory management works.

nanobot LLM Provider Registry

The nano bot Provider Registry makes integrating new LLM APIs trivial. Adding a new provider takes just 2 steps, enabling the nanobot ai to support 11+ providers.

How the Registry Works

Step 1: Create a provider class (inherit from base provider)
Step 2: Register the provider with the Registry

That's it! The nanobot can now use your new LLM provider. All the plumbing (API calls, error handling, response parsing) is handled automatically by the nano bot framework.

Supported Providers (11+)

The nanobot ai currently supports:

  • OpenRouter (multiple models, one API)
  • Anthropic (Claude Opus, Sonnet, Haiku)
  • OpenAI (GPT-4, GPT-3.5, and others)
  • DeepSeek (specialized reasoning)
  • Google Gemini (multimodal capabilities)
  • Zhipu (智谱), DashScope, Moonshot
  • Groq, AiHubMix
  • vLLM (local model support)

Provider Architecture

Each nano bot provider inherits from a base class that defines the interface. Providers implement send_message() and handle provider-specific details. The nanobot Registry manages provider selection and fallback.

Adding Custom Providers

Want to use a new LLM with the nanobot? Create a simple provider class following the pattern, register it, and the nano bot can immediately use it. The architecture makes LLM integration straightforward.

nanobot Multi-Platform Channels

The nano bot supports 8+ messaging platforms through a modular channel architecture. Each platform has dedicated integration code while sharing common patterns.

✈️

Telegram

Status: Full support (recommended)
Features: Voice transcription, media, inline keyboards
Code: channels/telegram/

The nanobot Telegram integration is the most mature, with complete feature support including voice message transcription.

🎮

Discord

Status: Full support
Features: Server integration, DMs, slash commands
Code: channels/discord/

Deploy the nano bot as a Discord bot for community management and server automation.

💬

WhatsApp, Slack, Email

Status: Supported
Features: Platform-specific capabilities
Code: channels/whatsapp/, channels/slack/, channels/email/

The nanobot ai connects to business and personal communication platforms.

🌐

QQ, DingTalk, Feishu, Mochat

Status: Supported
Regions: Chinese messaging platforms
Code: channels/qq/, channels/dingtalk/, etc.

The nano bot integrates with popular platforms in China and Asia.

Channel Architecture Pattern

All nanobot channels follow a common pattern: authenticate, receive messages, send responses, handle media. Platform-specific code handles API differences while the nano bot core remains platform-agnostic.

nanobot Tool Registry and Integration

The nano bot tool system enables the AI to interact with files, execute commands, and access the web. Tools are registered and made available to the LLM during conversations.

File Operations (file_ops.py)

Capabilities: Read, write, create, delete files
Use Cases: Reading documentation, updating memory, analyzing code

The nanobot can manipulate files on the filesystem with appropriate permissions. Critical for memory management and document processing.

Shell Execution (shell.py)

Capabilities: Execute shell commands
Use Cases: Running scripts, checking processes, system operations

The nano bot can run shell commands to interact with the operating system. Security restrictions apply to prevent misuse.

Web Access (web.py)

Capabilities: Fetch URLs, call APIs
Use Cases: Gathering information, integrating external services, API calls

The nanobot ai can access the internet to fetch data, call APIs, and integrate with external systems.

Tool Registration

Tools register with the nano bot by providing a description and function. The LLM sees available tools in the context and can invoke them during conversations. The nanobot handles tool execution and result integration.

nanobot Code Complexity: 99% Reduction

How does the nano bot achieve full AI assistant functionality in just ~4,000 lines? Through ruthless focus on essentials and clean architecture.

| Project | Lines of Code | Memory Usage | Complexity | |------------|---------------|--------------|------------| | Clawdbot | 430,000+ | High | Very High | | OpenClaw | 430,000+ | ~1GB RAM | Very High | | nanobot | ~4,000 | ~100MB RAM | Low | | Reduction | 99% | 90% | Dramatic |
🎯

Focus on Essentials

The nanobot ai includes only what's necessary for core AI assistant functionality. No GUI, no mobile apps, no extensive admin panels. The nano bot does one thing well: AI assistance.

🧹

No Redundancy

Every line of nanobot code serves a purpose. No duplicate functionality, no dead code, no "just in case" features. The nano bot achieves maximum functionality per line of code.

📐

Clean Architecture

The nanobot architecture is straightforward. No over-engineering, no excessive abstraction. Simple patterns consistently applied throughout the nano bot codebase.

🔬

Research-Driven Design

HKUDS designed the nanobot for research and learning. The nano bot proves that extreme simplification is possible while retaining capability. A model for future AI systems.

Explore the nanobot Architecture Yourself

The nano bot source code is open and available on GitHub. Read the ~4,000 lines yourself to see how extreme simplification works in practice. The nanobot ai architecture is designed to be understood.