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: preserve legacy team model selection fallback
FrancesShaw007b10c0b8d2fe2
diff --git a/jiuwenswarm/agents/harness/team/config_loader.py b/jiuwenswarm/agents/harness/team/config_loader.pyindex 8f8a700526..c70be65c2e 100644--- a/jiuwenswarm/agents/harness/team/config_loader.py+++ b/jiuwenswarm/agents/harness/team/config_loader.py@@ -4,8 +4,6 @@from __future__ import annotations-import hashlib-import jsonimport loggingfrom copy import deepcopyfrom pathlib import Path@@ -14,13 +12,16 @@ from typing import Anyfrom openjiuwen.agent_teams.paths import get_agent_teams_homefrom jiuwenswarm.common.config import get_config+from jiuwenswarm.common.model_identity import (+ MODEL_IDENTITY_REFERENCE_PREFIX,+ build_model_identity_reference,+)logger = logging.getLogger(__name__)_DEFAULT_MAX_ITERATIONS = 200_DEFAULT_COMPLETION_TIMEOUT = 600.0_DEFAULT_MAX_DEBATE_ROUNDS = 5-_MODEL_IDENTITY_REF_PREFIX = "model-identity-v1:"_DEFAULT_AGENT_WORKSPACE = {"stable_base": True}_DEFAULT_TEAM_WORKSPACE = {"enabled": True}_DEFAULT_TRANSPORT = {"type": "inprocess"}@@ -249,8 +250,15 @@ def _resolve_default_model_config(if len(matches) == 1:return matches[0]if len(matches) > 1:- raise ValueError(f"requested team model is ambiguous: {requested!r}")- raise ValueError(f"requested team model not found: {requested!r}")+ logger.warning(+ "[TeamConfigLoader] requested model name is ambiguous; using first match: %s",+ requested,+ )+ else:+ logger.warning(+ "[TeamConfigLoader] requested model name not found; using first default: %s",+ requested,+ )for item in defaults_raw:if isinstance(item, dict):@@ -336,32 +344,15 @@ def _build_agent_spec_dict(return merged-def _normalized_model_identity_text(value: Any) -> str:- return str(value or "").strip()---def build_model_identity_reference(model_name: Any, client_config: dict[str, Any]) -> str:- """Build a credential-free model identity that is independent of list order."""- identity = {- "api_base": _normalized_model_identity_text(client_config.get("api_base")).rstrip("/"),- "model_name": _normalized_model_identity_text(model_name),- "provider": _normalized_model_identity_text(client_config.get("client_provider")).lower(),- }- digest = hashlib.sha256(- json.dumps(identity, ensure_ascii=False, separators=(",", ":"), sort_keys=True).encode("utf-8")- ).hexdigest()- return f"{_MODEL_IDENTITY_REF_PREFIX}{digest}"--def resolve_model_identity_reference(model_ref: Any,config_base: dict[str, Any],) -> dict[str, Any]:"""Resolve one stable model identity to its unique tenant-owned model entry."""normalized_ref = str(model_ref or "").strip().lower()- digest = normalized_ref.removeprefix(_MODEL_IDENTITY_REF_PREFIX)+ digest = normalized_ref.removeprefix(MODEL_IDENTITY_REFERENCE_PREFIX)if (- not normalized_ref.startswith(_MODEL_IDENTITY_REF_PREFIX)+ not normalized_ref.startswith(MODEL_IDENTITY_REFERENCE_PREFIX)or len(digest) != 64or any(char not in "0123456789abcdef" for char in digest)):@@ -411,7 +402,7 @@ def resolve_legacy_index_model_reference(client_config = entry.get("model_client_config")if not isinstance(client_config, dict):raise ValueError(f"team model reference points to invalid entry: {normalized_ref!r}")- actual_name = _normalized_model_identity_text(client_config.get("model_name"))+ actual_name = str(client_config.get("model_name") or "").strip()if actual_name != model_name.strip():raise ValueError("team model reference name mismatch: "@@ -426,7 +417,7 @@ def resolve_team_model_reference() -> dict[str, Any]:"""Resolve stable identities and legacy index references during transition."""normalized_ref = str(model_ref or "").strip()- if normalized_ref.lower().startswith(_MODEL_IDENTITY_REF_PREFIX):+ if normalized_ref.lower().startswith(MODEL_IDENTITY_REFERENCE_PREFIX):return resolve_model_identity_reference(normalized_ref, config_base)return resolve_legacy_index_model_reference(normalized_ref, config_base)diff --git a/tests/unit_tests/agentserver/test_team_config_loader.py b/tests/unit_tests/agentserver/test_team_config_loader.pyindex 3b2df29cb4..505d9b7ef9 100644--- a/tests/unit_tests/agentserver/test_team_config_loader.py+++ b/tests/unit_tests/agentserver/test_team_config_loader.py@@ -222,7 +222,7 @@ def test_requested_model_overrides_every_team_agent_model_and_preserves_other_fiassert spec["agents"]["teammate"]["max_iterations"] == 7-def test_requested_model_must_exist_in_models_defaults():+def test_requested_model_name_falls_back_to_first_default_when_missing():config = {"models": {"defaults": [@@ -237,8 +237,42 @@ def test_requested_model_must_exist_in_models_defaults():),}- with pytest.raises(ValueError, match="requested team model not found"):- load_team_spec_dict(config_base=config, requested_model_name="missing-model")+ spec = load_team_spec_dict(config_base=config, requested_model_name="missing-model")++ assert spec["agents"]["leader"]["model"]["model_client_config"]["model_name"] == "configured-model"+++def test_requested_model_name_uses_first_match_when_ambiguous():+ config = {+ "models": {+ "defaults": [+ {+ "model_client_config": {+ "model_name": "duplicate-model",+ "api_base": "https://first.example.test/v1",+ },+ "model_config_obj": {},+ },+ {+ "model_client_config": {+ "model_name": "duplicate-model",+ "api_base": "https://second.example.test/v1",+ },+ "model_config_obj": {},+ },+ ]+ },+ **_wrap_modes_team(+ {"demo_team": {"team_name": "demo_team", "agents": {"leader": {}, "teammate": {}}}}+ ),+ }++ spec = load_team_spec_dict(config_base=config, requested_model_name="duplicate-model")++ assert (+ spec["agents"]["leader"]["model"]["model_client_config"]["api_base"]+ == "https://first.example.test/v1"+ )def _model_identity_ref(*, model_name: str, provider: str, api_base: str) -> str: