Die Analogie des zentralen Nervensystems
Most people think of AI assistants as standalone brains—a single entity that processes and responds. clawbot is different: it's architected like a biological nervous system . Your brain (the AI model) doesn't directly control your muscles; signals travel through nerves (channels), are processed by the spinal cord (Gateway), and execute through motor neurons (system tools).
Diese verteilte Architektur ist der Grund, warum clawbot gleichzeitig WhatsApp abhören, über Telegram antworten, einen Shell-Befehl ausführen und sein Gedächtnis aktualisieren kann – alles parallel. Traditionelle monolithische KIs können das nicht, da jede Fähigkeit eng gekoppelt ist. Das modulare Design von clawbot behandelt jede Komponente als unabhängigen Dienst, der über klar definierte Protokolle kommuniziert.
clawbot Systemarchitektur
Komponenten-Deep-Dive: Wie jedes Teil funktioniert
🌐 The Gateway: Central Command
The Gateway is the heart of clawbot—a persistent Node.js process that never sleeps. Why a dedicated service instead of running AI directly in each channel? Three critical reasons:
- Unified State : Single source of truth for conversation history across all channels
- Resource Efficiency : One connection to AI APIs instead of 15+ separate connections
- Fault Isolation : If WhatsApp crashes, Telegram keeps working—channels are replaceable plugins
The Gateway communicates via WebSockets, not HTTP. Why? HTTP requires the client to constantly ask "any updates?" (polling). WebSockets maintain a persistent two-way connection—the Gateway can push messages to channels the instant they're ready, enabling real-time streaming responses.
💬 Channels: The Sensory Interface
Channels are independent processes that translate between messaging platform protocols and the Gateway's unified message format. Think of them as protocol adapters —WhatsApp speaks Baileys, Telegram speaks Bot API, but both present messages to the Gateway in identical JSON structure.
Diese Abstraktion ist leistungsstark: Das Hinzufügen einer neuen Messaging-Plattform erfordert das Schreiben eines Kanal-Plugins, nicht die Änderung des gesamten Systems. Jeder Kanal ist sandboxed – wenn er abstürzt, versucht das Gateway automatisch eine Wiederverbindung, ohne andere Kanäle zu beeinträchtigen.
🧠 AI Model Router: The Intelligence Backbone
clawbot doesn't lock you into a single AI provider. The model router implements dynamic provider selection : choose Claude for complex reasoning, GPT-4 for creative tasks, or local Ollama for privacy-critical operations—all within the same conversation.
How does this work technically? Each AI provider has a standardized interface (following the OpenAI Completion API pattern). The router maintains connection pools to all configured providers, routes requests based on configured preferences, and handles automatic failover if a provider is unavailable.
Advanced: Custom Model Routing Logic
You can configure custom routing rules in
~/.clawbot/clawbot.json
:
- Route coding tasks to Claude (better at programming)
- Route creative writing to GPT-4 (more imaginative)
- Route sensitive data processing to local Ollama (zero external transmission)
- Automatic fallback to secondary provider if primary fails
💾 Persistent Memory: Conversation State Management
Unlike stateless AI APIs that forget everything between requests, clawbot maintains
durable conversation history
stored in Markdown files at
~/.clawbot/conversations/
. Each conversation is a complete log of messages,
tool executions, and AI responses.
Why Markdown instead of a database? Three reasons:
- Human-Readable : You can grep, search, and version control your AI conversations
- Portable : Move your entire conversation history by copying a folder
- AI-Friendly : AI models can natively understand Markdown formatting for context retrieval
Das Gateway verwaltet automatisch Kontextfenster – wenn eine Konversation das Token-Limit des Modells überschreitet, fasst es ältere Nachrichten intelligent zusammen und bewahrt dabei kritischen Kontext. Dies ermöglicht Konversationen, die sich über Wochen erstrecken, ohne Qualitätsverlust.
⚙️ Execution Engine: Safe System Control
This is where clawbot differentiates from chatbots: genuine task execution . When the AI decides a shell command is needed, the execution engine handles it safely through multiple protection layers:
- Sandboxing : Commands run in restricted environments with limited file system access
- Permission Gates : User-configurable allowlists/denylists for command patterns
- Confirmation Prompts : Destructive operations require explicit user approval
- Audit Logging : Every executed command is logged with timestamp, user, and result
- Timeout Protection : Commands automatically terminate after configurable duration
🔌 Skills System: Extensible Capabilities
Skills are clawbot's plugin system—folders containing
SKILL.md
files that teach the AI new capabilities.
How does a Markdown file extend functionality?
The AI reads the skill definition and learns:
- What the skill does and when to use it
- What parameters it accepts
- Example commands that trigger it
- Expected behavior and edge cases
Skills können Shell-Skripte, Node.js-Module oder API-Integrationscode enthalten. Die KI ruft diese Tools über strukturierte Funktionsaufrufe auf, empfängt Ergebnisse und integriert sie in Antworten. So kann clawbot Smart Homes steuern, Cloud-Infrastrukturen verwalten oder sich in proprietäre interne Systeme integrieren – jeder kann einen Skill schreiben.
Der Technologie-Stack: Was clawbot antreibt
Runtime: Node.js 22+
Moderne JavaScript-Laufzeitumgebung mit exzellenter asynchroner I/O-Leistung für Echtzeitkommunikation. Native Unterstützung für WebSockets, HTTP/2 und Worker-Threads ermöglicht parallele Task-Ausführung.
Language: TypeScript
Typsichere Entwicklung verhindert ganze Kategorien von Fehlern. Starke Typisierung für WebSocket-Nachrichten, KI-Antworten und Konfiguration gewährleistet eine robuste Fehlerbehandlung.
Communication: WebSocket Protocol
Bidirektionale, persistente Verbindungen zwischen Gateway und allen Clients. Ermöglicht Echtzeit-Nachrichten-Streaming, sofortige Benachrichtigungen und Latenzzeiten unter einer Sekunde für KI-Antworten.
Storage: File-Based State
Konversationen als Markdown gespeichert, Konfiguration als JSON, Skills als strukturierte Ordner. Keine Datenbankabhängigkeit – einfachere Bereitstellung, einfachere Backups, grep-freundliches Debugging.
WhatsApp: Baileys Library
Reverse-Engineerte WhatsApp Web Protokollimplementierung. Hält eine persistente Verbindung mit demselben Protokoll aufrecht, das Ihr Browser verwendet – keine inoffiziellen APIs oder Weitergabe von Telefonnummern.
Telegram: grammY Framework
Offizieller Telegram Bot API Wrapper mit TypeScript-Unterstützung. Long-Polling und Webhook-Unterstützung für flexible Bereitstellung, Datei-Uploads, Inline-Tastaturen und volle Bot-Funktionalität.
AI Integration: Provider Abstraction
Einheitliche Schnittstelle, die Anthropic Claude, OpenAI GPT-4, lokale Ollama-Modelle und Google Gemini unterstützt. Automatische Konvertierung zwischen verschiedenen API-Formaten für nahtlosen Anbieterwechsel.
Security: Sandboxed Execution
Shell-Befehle werden in eingeschränkten Umgebungen mit konfigurierbaren Berechtigungen ausgeführt. Benutzerdefinierte Vertrauensgrenzen verhindern versehentliche Systemschäden oder unbefugte Operationen.
Nachrichtenfluss: Eine Anfrage durch das System verfolgen
Let's trace what happens when you send: "Remind me to call Mom in 2 hours" via WhatsApp.
{"from": "user", "text": "Remind...", "channel": "whatsapp"}
schedule_reminder(time="+2h", message="Call Mom")
Diese 19-stufige Choreografie findet in weniger als 2 Sekunden statt. Die verteilte Architektur ermöglicht es jeder Komponente, unabhängig zu arbeiten – der WhatsApp-Kanal kennt Claude nicht, Claude kennt WhatsApp nicht, doch sie koordinieren sich nahtlos durch die Orchestrierung des Gateways.
Warum diese Architektur wichtig ist
Die meisten KI-Assistenten sind monolithisch – die gesamte Logik in einer Anwendung, eng gekoppelt an spezifische Plattformen. Das verteilte Design von clawbot ermöglicht Fähigkeiten, die in traditionellen Architekturen unmöglich sind:
- Hot-Swappable Components : Upgrade AI models without restarting channels. Replace WhatsApp with Telegram without touching the Gateway.
- Horizontal Scaling : Run multiple channel instances across different machines, all connecting to one Gateway.
- Fault Tolerance : If one channel crashes, others continue operating. If the Gateway restarts, channels automatically reconnect.
- Multi-Tenancy : One Gateway can serve multiple users with isolated conversation spaces—perfect for family deployments.
- Extensibility : Community members can build new channels, skills, or tools without access to core code.
🔐 Security Through Architecture
Das verteilte Design ist nicht nur Flexibilität – es ist eine Sicherheitsgrenze. Kanäle laufen in separaten Prozessen mit begrenzten Berechtigungen. Wenn ein Kanal kompromittiert wird, erhalten Angreifer nur Zugriff auf diese Messaging-Plattform, nicht auf Ihr gesamtes System. Das Gateway erzwingt die Authentifizierung, und die Ausführungs-Engine wendet zusätzliche Sandboxing an, bevor Systembefehle ausgeführt werden.
Technische Entscheidungen und Kompromisse
Warum WebSockets statt HTTP REST?
HTTP is request-response: client asks, server answers. AI responses often take 5-15 seconds. Without WebSockets, you'd need polling (wasteful) or long-polling (complex). WebSockets enable streaming responses —the AI begins sending words the moment it generates them, creating the perception of instant responsiveness.
Warum Dateispeicher statt einer Datenbank?
Databases add deployment complexity—installation, configuration, backup strategies. For personal AI (1-10 users), files provide sufficient performance while remaining portable, inspectable, and version-controllable . You can grep your conversation history, back it up with Dropbox, or track changes with Git.
Warum Node.js statt Python/Go/Rust?
Node.js eignet sich hervorragend für I/O-gebundene Aufgaben (Echtzeitkommunikation, API-Aufrufe). Das asynchrone/await-Modell von JavaScript passt natürlich zu KI-Workflows (Anfrage senden, auf Antwort warten, Ergebnis verarbeiten). Das npm-Ökosystem bietet ausgereifte Bibliotheken für jede Messaging-Plattform. TypeScript fügt Sicherheit hinzu, ohne die Entwicklungsgeschwindigkeit zu beeinträchtigen.
Bereit, Ihr eigenes zu implementieren?
Das Verständnis der Architektur ist der erste Schritt. Der zweite Schritt ist der Aufbau.