Yapay Zekanın İçinde: clawbot Nasıl Çalışır

Dil modellerini konuşma araçlarından gerçek otomasyon ajanlarına dönüştüren mühendisliği anlamak—benzetmelerle açıklanmış, mimariyle anlaşılır hale getirilmiş.

Merkezi Sinir Sistemi Benzetmesi

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).

Bu dağıtılmış mimari, clawbot'un WhatsApp'ı aynı anda dinlemesini, Telegram aracılığıyla yanıt vermesini, bir kabuk komutunu yürütmesini ve belleğini güncellemesini—tümünü paralel olarak—sağlar. Geleneksel monolitik yapay zeka bunu yapamaz çünkü her yetenek sıkı sıkıya bağlıdır. clawbot'un modüler tasarımı, her bileşeni iyi tanımlanmış protokoller aracılığıyla iletişim kuran bağımsız bir hizmet olarak ele alır.

clawbot Sistem Mimarisi

Input Layer: Communication Channels
💬
WhatsApp
Baileys Protocol
📱
Telegram
grammY Bot API
🎮
Discord
discord.js
💼
Slack
Bolt Framework
Orchestration Layer: The Gateway
🌐
Gateway Hub
WebSocket Server @ :18789
Intelligence Layer: AI Models
🧠
Claude
Anthropic API
GPT-4
OpenAI API
🏠
Ollama
Local Models
Execution Layer: System Control
⚙️
Shell Tools
Command Execution
📁
File System
Read/Write Ops
🌐
Browser
Web Automation
🔌
Integrations
API Connectors

Bileşen Derinlemesine İnceleme: Her Parça Nasıl İşlev Görür

🌐 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.

1. Channel connects to ws://127.0.0.1:18789
2. Authenticates with JWT token or local trust
3. Declares role: "channel:whatsapp"
4. Subscribes to message stream for specific user/group
5. Maintains heartbeat: ping every 30s

💬 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.

Bu soyutlama güçlüdür: yeni bir mesajlaşma platformu eklemek, tüm sistemi değiştirmek yerine tek bir kanal eklentisi yazmayı gerektirir. Her kanal sanal ortama alınmıştır—çökmesi durumunda, Ağ Geçidi diğer kanalları etkilemeden otomatik olarak yeniden bağlanmayı dener.

User: Sends "Check my calendar" via WhatsApp
Channel: Receives WhatsApp protobuf, converts to JSON
Gateway: Routes to AI model with context
AI: Generates response + tool call to calendar API
Gateway: Executes tool, streams result back
Channel: Converts JSON to WhatsApp format, delivers

🧠 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

Ağ Geçidi, bağlam pencerelerini otomatik olarak yönetir—bir konuşma modelin token sınırını aştığında, kritik bağlamı korurken eski mesajları akıllıca özetler. Bu, haftalar süren konuşmaların bozulmadan devam etmesini sağlar.

⚙️ 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
1. AI suggests: rm ~/Documents/old-file.txt
2. Execution engine checks permission policy
3. Destructive operation detected → user confirmation required
4. User approves via messaging channel
5. Command executes in sandbox with 30s timeout
6. Result logged: [SUCCESS] File deleted

🔌 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

Yetenekler kabuk betikleri, Node.js modülleri veya API entegrasyon kodu içerebilir. Yapay zeka bu araçları yapılandırılmış fonksiyon çağrıları aracılığıyla çağırır, sonuçları alır ve yanıtlarına dahil eder. clawbot'un akıllı evleri kontrol etmesi, bulut altyapısını yönetmesi veya özel dahili sistemlerle entegre olması bu şekilde olur—herkes bir yetenek yazabilir.

Teknoloji Yığını: clawbot'u Ne Güçlendiriyor

Runtime: Node.js 22+

Gerçek zamanlı iletişim için mükemmel asenkron G/Ç performansına sahip modern JavaScript çalışma zamanı. WebSocket'ler, HTTP/2 ve worker thread'ler için yerel destek, paralel görev yürütmeyi mümkün kılar.

Language: TypeScript

Tür güvenli geliştirme, hataların tüm kategorilerini önler. WebSocket mesajları, yapay zeka yanıtları ve yapılandırma için güçlü yazım, sağlam hata işlemeyi sağlar.

Communication: WebSocket Protocol

Ağ Geçidi ve tüm istemciler arasında çift yönlü, kalıcı bağlantılar. Gerçek zamanlı mesaj akışı, anında bildirimler ve yapay zeka yanıtları için saniyenin altında gecikme sağlar.

Storage: File-Based State

Konuşmalar Markdown olarak, yapılandırma JSON olarak, yetenekler yapılandırılmış klasörler olarak saklanır. Veritabanı bağımlılığı yok—daha basit dağıtım, daha kolay yedeklemeler, grep dostu hata ayıklama.

WhatsApp: Baileys Library

Tersine mühendislikle geliştirilmiş WhatsApp Web protokol uygulaması. Tarayıcınızın kullandığı protokolü kullanarak kalıcı bağlantıyı korur—resmi olmayan API'ler veya telefon numarası paylaşımı yok.

Telegram: grammY Framework

TypeScript desteğiyle resmi Telegram Bot API sarmalayıcısı. Esnek dağıtım, dosya yüklemeleri, satır içi klavyeler ve tam bot yetenekleri için uzun yoklama ve webhook desteği.

AI Integration: Provider Abstraction

Anthropic Claude, OpenAI GPT-4, Ollama yerel modeller ve Google Gemini'yi destekleyen birleşik arayüz. Sağlayıcı değiştirmeyi sorunsuz hale getirmek için farklı API formatları arasında otomatik dönüştürme.

Security: Sandboxed Execution

Kabuk komutları yapılandırılabilir izinlere sahip kısıtlı ortamlarda çalıştırılır. Kullanıcı tanımlı güven sınırları, kazara sistem hasarını veya yetkisiz işlemleri önler.

Mesaj Akışı: Sistemde Bir İstek Takibi

Let's trace what happens when you send: "Remind me to call Mom in 2 hours" via WhatsApp.

1. WhatsApp Server → Your phone receives message
2. Your Phone → Forwards to linked devices (including clawbot)
3. WhatsApp Channel → Decodes protobuf, extracts message text
4. Channel → Converts to JSON: {"from": "user", "text": "Remind...", "channel": "whatsapp"}
5. Gateway → Receives message via WebSocket
6. Gateway → Loads conversation history from Markdown file
7. Gateway → Appends new message to context
8. AI Router → Routes to configured AI model (e.g., Claude)
9. Claude API → Processes request, identifies "reminder" intent
10. Claude → Calls schedule_reminder(time="+2h", message="Call Mom")
11. Gateway → Executes tool, creates scheduled task
12. Gateway → Receives confirmation from scheduler
13. Claude → Generates human-friendly response
14. Gateway → Streams response back to WhatsApp channel
15. Channel → Converts JSON to WhatsApp format
16. Channel → Sends to WhatsApp servers
17. WhatsApp → Delivers to your phone
18. Scheduler → Waits 2 hours, then triggers reminder
19. Gateway → Sends proactive message: "Time to call Mom!"

Bu 19 adımlık koreografi 2 saniyenin altında gerçekleşir. Dağıtılmış mimari, her bileşenin bağımsız çalışmasına olanak tanır—WhatsApp kanalı Claude'u bilmez, Claude WhatsApp'ı bilmez, ancak Ağ Geçidi'nin orkestrasyonu aracılığıyla sorunsuz bir şekilde koordine olurlar.

Bu Mimari Neden Önemli

Çoğu yapay zeka asistanı monolitiktir—tüm mantık tek bir uygulamada, belirli platformlara sıkı sıkıya bağlıdır. clawbot'un dağıtılmış tasarımı, geleneksel mimarilerde imkansız olan yetenekleri mümkün kılar:

  • 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

Dağıtılmış tasarım sadece esneklik için değil—bir güvenlik sınırıdır. Kanallar sınırlı izinlere sahip ayrı işlemler halinde çalışır. Bir kanal ele geçirilirse, saldırganlar yalnızca o mesajlaşma platformuna erişebilir, tüm sisteminize değil. Ağ Geçidi kimlik doğrulamayı zorlar ve yürütme motoru herhangi bir sistem komutu çalıştırılmadan önce ek sanal ortam uygulaması yapar.

Teknik Kararlar ve Ödünleşimler

Neden HTTP REST Yerine WebSockets?

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.

Neden Veritabanı Yerine Dosya Depolama?

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.

Neden Python/Go/Rust Yerine Node.js?

Node.js, G/Ç'ye bağlı görevlerde (gerçek zamanlı iletişim, API çağrıları) mükemmeldir. JavaScript'in asenkron/bekleme modeli yapay zeka iş akışlarına doğal olarak uyar (istek gönder, yanıt bekle, sonucu işle). npm ekosistemi her mesajlaşma platformu için olgun kütüphaneler sağlar. TypeScript, geliştirme hızından ödün vermeden güvenlik ekler.

Kendi Sistemini Kurmaya Hazır Mısın?

Mimarinin anlaşılması ilk adımdır. İkinci adım onu inşa etmektir.

Installation Guide Security Best Practices Browse Source Code