Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix(config): 修复删除多agent 配置时报错

openJiuwen-bote44fe14c9a03
diff --git a/jiuwenswarm/common/config.py b/jiuwenswarm/common/config.py
index 4b9ca1e862..5251d4f3ad 100644
--- a/jiuwenswarm/common/config.py
+++ b/jiuwenswarm/common/config.py
@@ -973,10 +973,23 @@ def replace_teams_in_config(front_payload: dict[str, Any]) -> None:
"""Replace ``modes.team`` using the frontend team-editor payload.
Keep legacy top-level ``team`` config intact for backward compatibility.
+
+ If team array is empty, delete ``modes.team`` from config.
"""
if not isinstance(front_payload, dict):
raise ValueError("payload must be an object")
+ teams_raw = front_payload.get("team")
+
+ # 空数组:删除 modes.team 配置项
+ if isinstance(teams_raw, list) and not teams_raw:
+ data = _load_yaml_round_trip(_CONFIG_YAML_PATH)
+ if "modes" in data and isinstance(data["modes"], dict) and "team" in data["modes"]:
+ del data["modes"]["team"]
+ _dump_yaml_round_trip(_CONFIG_YAML_PATH, data)
+ return
+
+ # 非空数组:正常构建并保存
team_mapping = _build_modes_team_mapping(front_payload)
data = _load_yaml_round_trip(_CONFIG_YAML_PATH)
diff --git a/tests/unit_tests/test_config.py b/tests/unit_tests/test_config.py
index 8102788b76..0f632984e2 100644
--- a/tests/unit_tests/test_config.py
+++ b/tests/unit_tests/test_config.py
@@ -349,3 +349,52 @@ modes:
with pytest.raises(ValueError, match="duplicate member_name"):
replace_teams_in_config(payload)
+
+ @staticmethod
+ def test_replace_teams_in_config_deletes_modes_team_when_empty(
+ monkeypatch: pytest.MonkeyPatch,
+ temp_config_file: Path,
+ ):
+ temp_config_file.write_text(
+ """
+channels:
+ web:
+ enabled: true
+modes:
+ team:
+ existing_team:
+ team_name: existing_team
+""",
+ encoding="utf-8",
+ )
+ monkeypatch.setattr("jiuwenswarm.common.config._CONFIG_YAML_PATH", temp_config_file)
+
+ # 空 team 数组应该删除 modes.team 配置项
+ replace_teams_in_config({"agents": {}, "team": []})
+
+ raw = yaml.safe_load(temp_config_file.read_text(encoding="utf-8"))
+ assert "team" not in raw["modes"]
+
+ @staticmethod
+ def test_replace_teams_in_config_no_change_when_modes_team_missing(
+ monkeypatch: pytest.MonkeyPatch,
+ temp_config_file: Path,
+ ):
+ temp_config_file.write_text(
+ """
+channels:
+ web:
+ enabled: true
+modes:
+ agent:
+ fast: {}
+""",
+ encoding="utf-8",
+ )
+ monkeypatch.setattr("jiuwenswarm.common.config._CONFIG_YAML_PATH", temp_config_file)
+
+ # 空 team 数组,且 modes.team 不存在,不应报错
+ replace_teams_in_config({"agents": {}, "team": []})
+
+ raw = yaml.safe_load(temp_config_file.read_text(encoding="utf-8"))
+ assert "team" not in raw["modes"]