Usage
Description
Thegateway command starts the nanobot background service that handles:
- Message routing between channels and the agent
- Channel connections (WhatsApp, Telegram, Discord, etc.)
- Scheduled tasks (cron jobs)
- Heartbeat monitoring (proactive notifications)
- Session management (persistent conversations)
Options
Port number for the gateway service.Required: No
Default:
Default:
18790Workspace directory path. Overrides the workspace setting in config.json.Required: No
Default: From config.json or
Default: From config.json or
~/.nanobot/workspace/Path to configuration file.Required: No
Default:
Default:
~/.nanobot/config.jsonEnable verbose debug logging.Required: No
Default:
Default:
falseExamples
Basic Start
Custom Port
Debug Mode
Custom Workspace
Production Deployment
Gateway Components
1. Message Bus
Routes messages between channels and the agent:2. Agent Loop
Processes incoming messages:- Maintains conversation context
- Executes tools
- Generates responses
- Manages memory
3. Channel Manager
Manages active channel connections:- WhatsApp (WebSocket bridge)
- Telegram (polling)
- Discord (WebSocket gateway)
- Slack (Socket Mode)
- Email (IMAP/SMTP)
- DingTalk, Feishu, QQ, Mochat
4. Cron Service
Executes scheduled tasks:- Reminders
- Recurring reports
- Automated workflows
~/.nanobot/cron/jobs.json
5. Heartbeat Service
Proactive monitoring and notifications:- Checks system status
- Sends periodic updates
- Triggers alerts
6. Session Manager
Tracks active conversations:- Per-channel sessions
- Message history
- User context
- Agent memory
~/.nanobot/workspace/sessions/
Configuration
The gateway uses~/.nanobot/config.json:
Startup Sequence
- Load configuration from file
- Sync workspace templates (SOUL.md, TOOLS.md, etc.)
- Initialize message bus
- Create provider (API client)
- Start session manager
- Initialize cron service and load jobs
- Create agent loop with tools
- Start channel manager for enabled channels
- Start heartbeat service
- Begin event loop
Channel Status
On startup, the gateway displays enabled channels:Cron Status
If scheduled jobs exist:Heartbeat Configuration
Heartbeat interval is shown on startup:Graceful Shutdown
The gateway handles shutdown signals:- Stop agent loop
- Close MCP connections
- Stop heartbeat service
- Stop cron service
- Disconnect all channels
- Save session state
Signal Handling
- SIGINT (Ctrl+C): Graceful shutdown
- SIGTERM: Graceful shutdown
- SIGHUP: Graceful shutdown
Running as Service
systemd (Linux)
Create/etc/systemd/system/nanobot.service:
Docker
CreateDockerfile:
Docker Compose
Createdocker-compose.yml:
PM2 (Node.js Process Manager)
Monitoring
Check Status
Resource Usage
Health Check
Create a health check endpoint or use:Troubleshooting
Port Already in Use
Channel Connection Failed
- Check token in config.json
- Verify network connectivity
- Check API status
- Enable verbose logging:
--verbose
MCP Server Error
- Check MCP configuration
- Verify server binary exists
- Check permissions
- Review logs with
--verbose
Out of Memory
- Reduce memory_window in config
- Limit max_tokens
- Increase system memory
- Use lighter model
Performance Tuning
Reduce Memory Usage
Faster Response Times
Optimize Heartbeat
Exit Codes
- 0: Clean shutdown
- 1: Error (configuration, network, API)
- 130: Interrupted by user (Ctrl+C)
Related Commands
- agent - Direct CLI interaction
- channels - Manage channels
- status - Check configuration
- onboard - Initialize setup