Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
feat: multi-instance support with --config parameter
samsonchoi4e4d40ef3331
diff --git a/nanobot/cli/commands.py b/nanobot/cli/commands.pyindex aca0778de..097e41cfa 100644--- a/nanobot/cli/commands.py+++ b/nanobot/cli/commands.py@@ -244,15 +244,24 @@ def _make_provider(config: Config):@app.command()def gateway(port: int = typer.Option(18790, "--port", "-p", help="Gateway port"),- workspace: str | None = typer.Option(None, "--workspace", "-w", help="Workspace directory"),- config: str | None = typer.Option(None, "--config", "-c", help="Config file path"),verbose: bool = typer.Option(False, "--verbose", "-v", help="Verbose output"),+ config: str = typer.Option(None, "--config", "-c", help="Path to config file"),):"""Start the nanobot gateway."""+ # Set config path if provided (must be done before any imports that use get_data_dir)+ if config:+ from nanobot.config.loader import set_config_path+ config_path = Path(config).expanduser().resolve()+ if not config_path.exists():+ console.print(f"[red]Error: Config file not found: {config_path}[/red]")+ raise typer.Exit(1)+ set_config_path(config_path)+ console.print(f"[dim]Using config: {config_path}[/dim]")+from nanobot.agent.loop import AgentLoopfrom nanobot.bus.queue import MessageBusfrom nanobot.channels.manager import ChannelManager- from nanobot.config.loader import load_config+ from nanobot.config.loader import get_data_dir, load_configfrom nanobot.cron.service import CronServicefrom nanobot.cron.types import CronJobfrom nanobot.heartbeat.service import HeartbeatService@@ -262,20 +271,16 @@ def gateway(import logginglogging.basicConfig(level=logging.DEBUG)- config_path = Path(config) if config else None- config = load_config(config_path)- if workspace:- config.agents.defaults.workspace = workspace-console.print(f"{__logo__} Starting nanobot gateway on port {port}...")++ config = load_config()sync_workspace_templates(config.workspace_path)bus = MessageBus()provider = _make_provider(config)session_manager = SessionManager(config.workspace_path)# Create cron service first (callback set after agent creation)- # Use workspace path for per-instance cron store- cron_store_path = config.workspace_path / "cron" / "jobs.json"+ cron_store_path = get_data_dir() / "cron" / "jobs.json"cron = CronService(cron_store_path)# Create agent with cron servicediff --git a/nanobot/config/loader.py b/nanobot/config/loader.pyindex c789efdaf..4355bd3f7 100644--- a/nanobot/config/loader.py+++ b/nanobot/config/loader.py@@ -6,15 +6,29 @@ from pathlib import Pathfrom nanobot.config.schema import Config+# Global variable to store current config path (for multi-instance support)+_current_config_path: Path | None = None+++def set_config_path(path: Path) -> None:+ """Set the current config path (used to derive data directory)."""+ global _current_config_path+ _current_config_path = path++def get_config_path() -> Path:- """Get the default configuration file path."""+ """Get the configuration file path."""+ if _current_config_path:+ return _current_config_pathreturn Path.home() / ".nanobot" / "config.json"def get_data_dir() -> Path:- """Get the nanobot data directory."""- from nanobot.utils.helpers import get_data_path- return get_data_path()+ """Get the nanobot data directory (derived from config path)."""+ config_path = get_config_path()+ # If config is ~/.nanobot-xxx/config.json, data dir is ~/.nanobot-xxx/+ # If config is ~/.nanobot/config.json, data dir is ~/.nanobot/+ return config_path.parentdef load_config(config_path: Path | None = None) -> Config:diff --git a/nanobot/utils/helpers.py b/nanobot/utils/helpers.pyindex 3a8c8023f..e24482921 100644--- a/nanobot/utils/helpers.py+++ b/nanobot/utils/helpers.py@@ -12,8 +12,9 @@ def ensure_dir(path: Path) -> Path:def get_data_path() -> Path:- """~/.nanobot data directory."""- return ensure_dir(Path.home() / ".nanobot")+ """Get nanobot data directory (derived from config path)."""+ from nanobot.config.loader import get_data_dir+ return ensure_dir(get_data_dir())def get_workspace_path(workspace: str | None = None) -> Path: