Skip to main content
Back

HKU's nanobot Shrinks AI Agent Code by 99% and Hits 41K Stars

nanobot packs a full personal AI agent into ~4,000 lines of Python, with 20+ LLM providers, 14 chat channels, and a novel two-stage memory system

Repo, Full Access
  • What it is: nanobot is an open-source personal AI agent from HKU's data lab, with ~4,000 lines of readable core Python code.
  • 99% smaller: Achieves ~90% of OpenClaw's capabilities in 4,000 lines vs. OpenClaw's 430,000-line codebase.
  • Massive integrations: Supports 20+ LLM providers (OpenAI, Anthropic, DeepSeek V4, Ollama) and 14 chat channels (Telegram, Discord, Slack, Teams, WhatsApp).
  • Dream memory: Two-stage memory system compresses history into long-term facts and learns tool-use patterns across sessions without a vector DB.
  • Latest release: v0.2.2 adds segmented WebUI transcripts, Python SDK runtime controls, and stronger session reliability.
  • Free and MIT-licensed: Install via pip install nanobot-ai or uv tool install nanobot-ai; you supply your own API keys.

nanobot is an open-source personal AI agent from the HKU Data Intelligence Lab (HKUDS) that has quietly become one of the most-starred agent repos on GitHub, crossing 41,000 stars. The pitch is simple but rare: a fully functional, long-running AI agent whose core loop you can actually read, understand, and fork in an afternoon. No 430,000-line monolith, no vendor lock-in, no PhD required to extend it.

The 99% Reduction That Changes Everything

nanobot reduces the codebase from 430,000 lines (comparable to OpenClaw) to approximately 4,000 lines, a 99% reduction, effectively addressing pain points like massive codebase, steep learning curve, and complex deployment. The comparison is intentional: nanobot positions itself in the same family as OpenClaw, Claude Code, and Codex, but with a deliberately small, readable core that you can fit in your head in an afternoon.

The "~4,000 lines" claim refers specifically to the core agent loop, the part that decides what to do next, calls models, dispatches tools, and manages turns. The full repo is much larger because of channel plugins, provider adapters, the Dream memory system, the WebUI, and tests. The "ultra-lightweight" claim is about the readable core, not the total install footprint.

How the Agent Loop Actually Works

nanobot stays lightweight by centering everything around a small agent loop: messages come in from chat apps, the LLM decides when tools are needed, and memory or skills are pulled in only as context instead of becoming a heavy orchestration layer. That keeps the core path readable and easy to extend, while still letting you add channels, tools, memory, and deployment options without turning the system into a monolith.

Architecture diagram showing nanobot's agent loop: messages from chat apps flow through an LLM, which accesses tools and context memory to generate responses

The key architectural components are:

  • AgentLoop: the AgentLoop manages the execution cycle, coordinating LLM queries and tool invocations, with a default configuration allowing up to 200 tool iterations.
  • Provider layer: a unified interface for 25+ LLM services, utilizing native SDKs (OpenAI, Anthropic) and a centralized ProviderSpec registry for metadata and auto-detection.
  • Dream memory: a two-tier memory system consisting of session-based history and a "Dream" memory consolidation process, where DreamConfig defines how the agent periodically compresses history into long-term facts.