From 3e0760a15762b3f5572735946b9ac49134eeca32 Mon Sep 17 00:00:00 2001 From: ailuntz Date: Tue, 10 Mar 2026 16:54:11 +0800 Subject: [PATCH] fix(config): accept allowAgents in agent list --- scripts/sync_agent_config.py | 6 ++++- tests/test_sync_agent_config.py | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 tests/test_sync_agent_config.py diff --git a/scripts/sync_agent_config.py b/scripts/sync_agent_config.py index 698bb0be..90f3cf5e 100644 --- a/scripts/sync_agent_config.py +++ b/scripts/sync_agent_config.py @@ -99,6 +99,10 @@ def main(): continue meta = ID_LABEL[ag_id] workspace = ag.get('workspace', str(pathlib.Path.home() / f'.openclaw/workspace-{ag_id}')) + if 'allowAgents' in ag: + allow_agents = ag.get('allowAgents', []) or [] + else: + allow_agents = ag.get('subagents', {}).get('allowAgents', []) result.append({ 'id': ag_id, 'label': meta['label'], 'role': meta['role'], 'duty': meta['duty'], 'emoji': meta['emoji'], @@ -106,7 +110,7 @@ def main(): 'defaultModel': default_model, 'workspace': workspace, 'skills': get_skills(workspace), - 'allowAgents': ag.get('subagents', {}).get('allowAgents', []), + 'allowAgents': allow_agents, }) seen_ids.add(ag_id) diff --git a/tests/test_sync_agent_config.py b/tests/test_sync_agent_config.py new file mode 100644 index 00000000..ca28aeb5 --- /dev/null +++ b/tests/test_sync_agent_config.py @@ -0,0 +1,41 @@ +import json +import importlib.util +from pathlib import Path + + +def _load_sync_agent_config(): + root = Path(__file__).resolve().parents[1] + script_path = root / "scripts" / "sync_agent_config.py" + spec = importlib.util.spec_from_file_location("sync_agent_config", script_path) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +def test_sync_agent_config_accepts_allow_agents_key(tmp_path, monkeypatch): + sync_agent_config = _load_sync_agent_config() + + cfg = { + "agents": { + "defaults": {"model": "openai/gpt-4o"}, + "list": [ + { + "id": "taizi", + "workspace": str(tmp_path / "ws-taizi"), + "allowAgents": ["zhongshu"] + } + ] + } + } + + cfg_path = tmp_path / "openclaw.json" + cfg_path.write_text(json.dumps(cfg, ensure_ascii=False)) + + monkeypatch.setattr(sync_agent_config, "OPENCLAW_CFG", cfg_path) + monkeypatch.setattr(sync_agent_config, "DATA", tmp_path / "data") + + sync_agent_config.main() + + out = json.loads((tmp_path / "data" / "agent_config.json").read_text()) + taizi = next(agent for agent in out["agents"] if agent["id"] == "taizi") + assert taizi["allowAgents"] == ["zhongshu"]