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
Merge branch 'main' into pr-1635
Re-binfb4f69608531
diff --cc README.mdindex 86869a2d4,0bb6efe01..bc11cc897--- a/README.md+++ b/README.md@@@ -900,37 -911,88 +914,96 @@@ Run multiple nanobot instances simultan```bash# Instance A - Telegram bot- nanobot gateway -w ~/.nanobot/botA -p 18791+ nanobot gateway --config ~/.nanobot-telegram/config.json- # Instance B - Discord bot- nanobot gateway -w ~/.nanobot/botB -p 18792+ # Instance B - Discord bot+ nanobot gateway --config ~/.nanobot-discord/config.json- # Instance C - Using custom config file- nanobot gateway -w ~/.nanobot/botC -c ~/.nanobot/botC/config.json -p 18793+ # Instance C - Feishu bot with custom port+ nanobot gateway --config ~/.nanobot-feishu/config.json --port 18792```- | Option | Short | Description |- |--------|-------|-------------|- | `--workspace` | `-w` | Workspace directory (default: `~/.nanobot/workspace`) |- | `--config` | `-c` | Config file path (default: `~/.nanobot/config.json`) |- | `--port` | `-p` | Gateway port (default: `18790`) |+ ### Path Resolution- Each instance has its own:- - Workspace directory (MEMORY.md, HEARTBEAT.md, session files)- - Cron jobs storage (`workspace/cron/jobs.json`)- - Configuration (if using `--config`)+ When using `--config`, nanobot derives its runtime data directory from the config file location. The workspace still comes from `agents.defaults.workspace` unless you override it with `--workspace`.+To open a CLI session against one of these instances locally:++```bash+nanobot agent -w ~/.nanobot/botA -m "Hello from botA"+nanobot agent -w ~/.nanobot/botC -c ~/.nanobot/botC/config.json+```++> `nanobot agent` starts a local CLI agent using the selected workspace/config. It does not attach to or proxy through an already running `nanobot gateway` process.+ | Component | Resolved From | Example |+ |-----------|---------------|---------|+ | **Config** | `--config` path | `~/.nanobot-A/config.json` |+ | **Workspace** | `--workspace` or config | `~/.nanobot-A/workspace/` |+ | **Cron Jobs** | config directory | `~/.nanobot-A/cron/` |+ | **Media / runtime state** | config directory | `~/.nanobot-A/media/` |++ ### How It Works++ - `--config` selects which config file to load+ - By default, the workspace comes from `agents.defaults.workspace` in that config+ - If you pass `--workspace`, it overrides the workspace from the config file++ ### Minimal Setup++ 1. Copy your base config into a new instance directory.+ 2. Set a different `agents.defaults.workspace` for that instance.+ 3. Start the instance with `--config`.++ Example config:++ ```json+ {+ "agents": {+ "defaults": {+ "workspace": "~/.nanobot-telegram/workspace",+ "model": "anthropic/claude-sonnet-4-6"+ }+ },+ "channels": {+ "telegram": {+ "enabled": true,+ "token": "YOUR_TELEGRAM_BOT_TOKEN"+ }+ },+ "gateway": {+ "port": 18790+ }+ }+ ```++ Start separate instances:++ ```bash+ nanobot gateway --config ~/.nanobot-telegram/config.json+ nanobot gateway --config ~/.nanobot-discord/config.json+ ```++ Override workspace for one-off runs when needed:++ ```bash+ nanobot gateway --config ~/.nanobot-telegram/config.json --workspace /tmp/nanobot-telegram-test+ ```++ ### Common Use Cases++ - Run separate bots for Telegram, Discord, Feishu, and other platforms+ - Keep testing and production instances isolated+ - Use different models or providers for different teams+ - Serve multiple tenants with separate configs and runtime data++ ### Notes+ - Each instance must use a different port if they run at the same time+ - Use a different workspace per instance if you want isolated memory, sessions, and skills+ - `--workspace` overrides the workspace defined in the config file+ - Cron jobs and runtime media/state are derived from the config directory- ## CLI Reference+ ## 💻 CLI Reference| Command | Description ||---------|-------------|diff --cc nanobot/cli/commands.pyindex 5987796ae,da8906d2d..d03ef938d--- a/nanobot/cli/commands.py+++ b/nanobot/cli/commands.py@@@ -274,6 -291,8 +301,7 @@@ def gatewayfrom 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.paths import get_cron_dirfrom nanobot.cron.service import CronServicefrom nanobot.cron.types import CronJobfrom nanobot.heartbeat.service import HeartbeatService@@@ -464,10 -482,11 +491,10 @@@ def agentfrom nanobot.agent.loop import AgentLoopfrom nanobot.bus.queue import MessageBus- from nanobot.config.loader import get_data_dir- from nanobot.config.loader import load_config+ from nanobot.config.paths import get_cron_dirfrom nanobot.cron.service import CronService- config = load_config()+ config = _load_runtime_config(config, workspace)sync_workspace_templates(config.workspace_path)bus = MessageBus()diff --cc tests/test_commands.pyindex 46ee7d0a9,a27665327..e3709daf8--- a/tests/test_commands.py+++ b/tests/test_commands.py@@@ -130,94 -134,92 +134,185 @@@ def test_openai_codex_strip_prefix_suppassert _strip_model_prefix("openai_codex/gpt-5.1-codex") == "gpt-5.1-codex"+def mock_agent_runtime(tmp_path):+ """Mock agent command dependencies for focused CLI tests."""+ config = Config()+ config.agents.defaults.workspace = str(tmp_path / "default-workspace")- data_dir = tmp_path / "data"++ cron_dir = tmp_path / "data" / "cron"++ with patch("nanobot.config.loader.load_config", return_value=config) as mock_load_config, \- patch("nanobot.config.loader.get_data_dir", return_value=data_dir), \++ patch("nanobot.config.paths.get_cron_dir", return_value=cron_dir), \+ patch("nanobot.cli.commands.sync_workspace_templates") as mock_sync_templates, \+ patch("nanobot.cli.commands._make_provider", return_value=object()), \+ patch("nanobot.cli.commands._print_agent_response") as mock_print_response, \+ patch("nanobot.bus.queue.MessageBus"), \+ patch("nanobot.cron.service.CronService"), \+ patch("nanobot.agent.loop.AgentLoop") as mock_agent_loop_cls:++ agent_loop = MagicMock()+ agent_loop.channels_config = None+ agent_loop.process_direct = AsyncMock(return_value="mock-response")+ agent_loop.close_mcp = AsyncMock(return_value=None)+ mock_agent_loop_cls.return_value = agent_loop++ yield {+ "config": config,+ "load_config": mock_load_config,+ "sync_templates": mock_sync_templates,+ "agent_loop_cls": mock_agent_loop_cls,+ "agent_loop": agent_loop,+ "print_response": mock_print_response,+ }+++def test_agent_help_shows_workspace_and_config_options():+ result = runner.invoke(app, ["agent", "--help"])++ assert result.exit_code == 0+ assert "--workspace" in result.stdout+ assert "-w" in result.stdout+ assert "--config" in result.stdout+ assert "-c" in result.stdout+++def test_agent_uses_default_config_when_no_workspace_or_config_flags(mock_agent_runtime):+ result = runner.invoke(app, ["agent", "-m", "hello"])++ assert result.exit_code == 0+ assert mock_agent_runtime["load_config"].call_args.args == (None,)+ assert mock_agent_runtime["sync_templates"].call_args.args == (+ mock_agent_runtime["config"].workspace_path,+ )+ assert mock_agent_runtime["agent_loop_cls"].call_args.kwargs["workspace"] == (+ mock_agent_runtime["config"].workspace_path+ )+ mock_agent_runtime["agent_loop"].process_direct.assert_awaited_once()+ mock_agent_runtime["print_response"].assert_called_once_with("mock-response", render_markdown=True)+++def test_agent_uses_explicit_config_path(mock_agent_runtime):+ config_path = Path("/tmp/agent-config.json")++ result = runner.invoke(app, ["agent", "-m", "hello", "-c", str(config_path)])++ assert result.exit_code == 0+ assert mock_agent_runtime["load_config"].call_args.args == (config_path,)+++def test_agent_overrides_workspace_path(mock_agent_runtime):+ workspace_path = Path("/tmp/agent-workspace")++ result = runner.invoke(app, ["agent", "-m", "hello", "-w", str(workspace_path)])++ assert result.exit_code == 0+ assert mock_agent_runtime["config"].agents.defaults.workspace == str(workspace_path)+ assert mock_agent_runtime["sync_templates"].call_args.args == (workspace_path,)+ assert mock_agent_runtime["agent_loop_cls"].call_args.kwargs["workspace"] == workspace_path+++def test_agent_workspace_override_wins_over_config_workspace(mock_agent_runtime):+ config_path = Path("/tmp/agent-config.json")+ workspace_path = Path("/tmp/agent-workspace")++ result = runner.invoke(+ app,+ ["agent", "-m", "hello", "-c", str(config_path), "-w", str(workspace_path)],+ )++ assert result.exit_code == 0+ assert mock_agent_runtime["load_config"].call_args.args == (config_path,)+ assert mock_agent_runtime["config"].agents.defaults.workspace == str(workspace_path)+ assert mock_agent_runtime["sync_templates"].call_args.args == (workspace_path,)+ assert mock_agent_runtime["agent_loop_cls"].call_args.kwargs["workspace"] == workspace_path+++++ def test_gateway_uses_workspace_from_config_by_default(monkeypatch, tmp_path: Path) -> None:+ config_file = tmp_path / "instance" / "config.json"+ config_file.parent.mkdir(parents=True)+ config_file.write_text("{}")++ config = Config()+ config.agents.defaults.workspace = str(tmp_path / "config-workspace")+ seen: dict[str, Path] = {}++ monkeypatch.setattr(+ "nanobot.config.loader.set_config_path",+ lambda path: seen.__setitem__("config_path", path),+ )- monkeypatch.setattr("nanobot.config.loader.load_config", lambda: config)++ monkeypatch.setattr("nanobot.config.loader.load_config", lambda _path=None: config)+ monkeypatch.setattr(+ "nanobot.cli.commands.sync_workspace_templates",+ lambda path: seen.__setitem__("workspace", path),+ )+ monkeypatch.setattr(+ "nanobot.cli.commands._make_provider",+ lambda _config: (_ for _ in ()).throw(_StopGateway("stop")),+ )++ result = runner.invoke(app, ["gateway", "--config", str(config_file)])++ assert isinstance(result.exception, _StopGateway)+ assert seen["config_path"] == config_file.resolve()+ assert seen["workspace"] == Path(config.agents.defaults.workspace)+++ def test_gateway_workspace_option_overrides_config(monkeypatch, tmp_path: Path) -> None:+ config_file = tmp_path / "instance" / "config.json"+ config_file.parent.mkdir(parents=True)+ config_file.write_text("{}")++ config = Config()+ config.agents.defaults.workspace = str(tmp_path / "config-workspace")+ override = tmp_path / "override-workspace"+ seen: dict[str, Path] = {}++ monkeypatch.setattr("nanobot.config.loader.set_config_path", lambda _path: None)- monkeypatch.setattr("nanobot.config.loader.load_config", lambda: config)++ monkeypatch.setattr("nanobot.config.loader.load_config", lambda _path=None: config)+ monkeypatch.setattr(+ "nanobot.cli.commands.sync_workspace_templates",+ lambda path: seen.__setitem__("workspace", path),+ )+ monkeypatch.setattr(+ "nanobot.cli.commands._make_provider",+ lambda _config: (_ for _ in ()).throw(_StopGateway("stop")),+ )++ result = runner.invoke(+ app,+ ["gateway", "--config", str(config_file), "--workspace", str(override)],+ )++ assert isinstance(result.exception, _StopGateway)+ assert seen["workspace"] == override+ assert config.workspace_path == override+++ def test_gateway_uses_config_directory_for_cron_store(monkeypatch, tmp_path: Path) -> None:+ config_file = tmp_path / "instance" / "config.json"+ config_file.parent.mkdir(parents=True)+ config_file.write_text("{}")++ config = Config()+ config.agents.defaults.workspace = str(tmp_path / "config-workspace")+ seen: dict[str, Path] = {}++ monkeypatch.setattr("nanobot.config.loader.set_config_path", lambda _path: None)- monkeypatch.setattr("nanobot.config.loader.load_config", lambda: config)++ monkeypatch.setattr("nanobot.config.loader.load_config", lambda _path=None: config)+ monkeypatch.setattr("nanobot.config.paths.get_cron_dir", lambda: config_file.parent / "cron")+ monkeypatch.setattr("nanobot.cli.commands.sync_workspace_templates", lambda _path: None)+ monkeypatch.setattr("nanobot.cli.commands._make_provider", lambda _config: object())+ monkeypatch.setattr("nanobot.bus.queue.MessageBus", lambda: object())+ monkeypatch.setattr("nanobot.session.manager.SessionManager", lambda _workspace: object())++ class _StopCron:+ def __init__(self, store_path: Path) -> None:+ seen["cron_store"] = store_path+ raise _StopGateway("stop")++ monkeypatch.setattr("nanobot.cron.service.CronService", _StopCron)++ result = runner.invoke(app, ["gateway", "--config", str(config_file)])++ assert isinstance(result.exception, _StopGateway)+ assert seen["cron_store"] == config_file.parent / "cron" / "jobs.json"