Architecture
Core components
- Orchestrator (
src/index.ts) - State management, message loop, and agent invocation - Message Router (
src/router.ts) - Message formatting and outbound routing - Container Runner (
src/container-runner.ts) - Spawns agent containers with mounts - Task Scheduler (
src/task-scheduler.ts) - Runs scheduled tasks - Database (
src/db.ts) - SQLite operations for messages, groups, and tasks - Channels (
src/channels/) - Channel connections and message delivery
Key concepts
Groups
Groups are isolated workspaces for the agent. Each group has:- Unique folder in
groups/{name}/ - Isolated filesystem and memory
- Persistent session ID
- Optional trigger pattern (default: requires
@{ASSISTANT_NAME}mention)
Message flow
- Channel receives message and calls
onMessagecallback - Message is stored in database via
storeMessage() - Message loop detects new messages for registered groups
- Router formats messages as XML and passes to agent container
- Agent processes messages and returns output
- Output is stripped of
<internal>tags and sent back through channel
Sessions
Each group maintains a persistent session ID that preserves conversation context across container restarts. Sessions are stored in the database and loaded when spawning containers.Database schema
NanoClaw uses SQLite for persistent storage:chats- Chat metadata (JID, name, last activity)messages- Full message history for registered groupsregistered_groups- Group configuration and settingssessions- Session IDs by group folderscheduled_tasks- Task definitions and schedulestask_run_logs- Task execution historyrouter_state- Message cursor positions
Configuration files
See Configuration for detailed configuration options.Next steps
Configuration
Environment variables and config options
Message routing
Message formatting and routing API
Group management
Register and manage groups
Task scheduling
Schedule automated tasks