feat: multi-instance support with --config parameter#1581
Conversation
Add support for running multiple nanobot instances with complete isolation: - Add --config parameter to gateway command for custom config file path - Implement set_config_path() in config/loader.py for dynamic config path - Derive data directory from config file location (e.g., ~/.nanobot-xxx/) - Update get_data_path() to use unified data directory from config loader - Ensure cron jobs use instance-specific data directory This enables running multiple isolated nanobot instances by specifying different config files, with each instance maintaining separate: - Configuration files - Workspace (memory, sessions, skills) - Cron jobs - Logs and media Example usage: nanobot gateway --config ~/.nanobot-instance2/config.json --port 18791
|
Good choice! Would you like to update the |
Of course!Let me do it right now. |
- Add detailed setup examples with directory structure - Document complete isolation mechanism (config, workspace, cron, logs, media) - Include use cases and production deployment patterns - Add management scripts for systemd (Linux) and launchd (macOS) - Provide step-by-step configuration examples
Done! |
Thanks! I will review it soon :) |
Hi there, Thank you so much for reviewing and merging this PR! I'm really glad to be able to contribute to this awesome project. I just wanted to leave a quick note: I noticed I didn't appear in the GitHub Contributors list. After checking my local environment, I realized I made a beginner's mistake and forgot to configure my local git user.email properly before making these commits, so GitHub couldn't link them to my account. I completely understand that since the code is already merged into the main branch, the commit history shouldn't be rewritten to fix this. However, if it's convenient, would it be possible to give me a quick mention in the next Release Notes or the README? If not, no worries at all! I'm just happy my code is helpful. Thanks again for your time and for maintaining this project! Best, |
Add a read-only tool that enables agents in multi-instance deployments
to discover and read memory, history, sessions, and skills from sibling
instances on the same machine.
Key features:
- Auto-discover instances via ~/.nanobot[-{name}]/ convention
- Permission control via memorySharing config (enabled/allowFrom whitelist)
- Five scopes: memory, history, sessions, skills, all
- Keyword search for history and session logs
- Read-only by design: the tool fetches data, the agent decides what to persist
Iterates on HKUDS#1581.
|
Hello, I have a question about the multi-user architecture. Why is multi-user support implemented using a multi-instance approach? Would it be possible to extend a single instance to support multiple users by modifying the source code? My understanding is that this might be achievable with a database and a web layer, where each user’s messages are handled in an independent agent loop, and each workspace is isolated as well. In that case, a single instance could potentially support many users. Would this design be feasible? @shenchengtsi |
Hi, that's a really sharp observation — your proposed architecture is genuinely the right approach for multi-user scenarios. A database + web layer + isolated agent loops per user is exactly how a proper multi-tenant system should be designed. It scales well, manages resources efficiently, and keeps things operationally clean. The reason nanobot currently uses a multi-instance approach comes down to its design goals: it's a lightweight personal assistant, and the multi-instance model lets each user have a completely different configuration — different models, different skills, different system prompts — with zero shared state and no database dependency. For small-scale personal or team use, it's the simplest path to full isolation. That said, if you're building toward a product that serves many users, your instinct is exactly right. The main effort would be refactoring the current file-based workspace, cron, and session layout into a per-user data model — doable, but a meaningful undertaking. Would love to see that explored. Happy to discuss further if you want to dig into the design! @winter1215 |
🎯 Problem & Motivation
When deploying AI assistants at scale, you often need to run multiple instances with different configurations:
Currently, this requires either:
✨ Solution
This PR adds native multi-instance support with complete isolation through a simple
--configparameter.Key Features
Usage
Each instance can use:
📦 Changes
Core Implementation (3 files)
1. Config Path Management (
nanobot/config/loader.py)set_config_path(path: Path)function to set custom config file locationget_config_path()to return custom path if set, otherwise default~/.nanobot/config.jsonget_data_dir()to derive data directory from config file location~/.nanobot-instance2/config.json→ data dir is~/.nanobot-instance2/2. Data Path Resolution (
nanobot/utils/helpers.py)get_data_path()to use unified data directory from config loader3. Gateway Command (
nanobot/cli/commands.py)--configparameter togateway()commandget_data_dir()get_data_dir()instead ofconfig.workspace_path🏗️ Architecture
Data directory is automatically derived from config file location - no manual path configuration needed.
Isolation Table
<data_dir>/config.json<data_dir>/workspace/<data_dir>/workspace/memory/<data_dir>/workspace/sessions/<data_dir>/workspace/skills/<data_dir>/cron/jobs.json<data_dir>/logs/<data_dir>/media/✅ Backward Compatibility
Existing single-instance setups work without any changes. Default config path remains
~/.nanobot/config.json.Zero Breaking Changes - Default behavior unchanged, fully backward compatible.
🎬 Real-World Use Cases
1. Multiple Teams
2. Multi-Tenant SaaS
3. Testing & Production
🔍 Testing
Tested on macOS with 3 concurrent instances:
~/.nanobot/(port 18790)~/.nanobot-zhangjuzheng/(port 18791)~/.nanobot-lvfang/(port 18792)All instances running independently with:
🙏 Benefits to Community
This addresses a common pain point in real-world deployments while keeping nanobot's lightweight philosophy intact.
Related Issues: N/A (new feature)
Breaking Changes: None
Documentation: Usage examples included in PR description