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(heartbeat): prevent LLM call failure on heartbeat due to placeholder model config
z2tng338265e9f5b4
diff --git a/jiuwenclaw/agentserver/deep_agent/interface_deep.py b/jiuwenclaw/agentserver/deep_agent/interface_deep.pyindex 3e84179cba..d191122c29 100644--- a/jiuwenclaw/agentserver/deep_agent/interface_deep.py+++ b/jiuwenclaw/agentserver/deep_agent/interface_deep.py@@ -219,6 +219,15 @@ _ACP_BLOCKED_DEFAULT_TOOL_NAMES = frozenset("code",})+_PLACEHOLDER_API_KEYS = frozenset({"sk-xxxxxxxxx", "your-api-key", "your_api_key", "YOUR_API_KEY"})+_PLACEHOLDER_API_BASES = frozenset({"https://example.com/compatible-mode/v1"})+++def _mcc_looks_usable(mcc: dict) -> bool:+ """检查 model_client_config 是否包含有效的 API 凭据(非占位符)。"""+ api_key = str(mcc.get("api_key", "") or "").strip()+ api_base = str(mcc.get("api_base", "") or "").strip()+ return bool(api_key) and api_key not in _PLACEHOLDER_API_KEYS and api_base not in _PLACEHOLDER_API_BASESdef parse_int(value: Any, default: int) -> int:@@ -2654,23 +2663,23 @@ class JiuWenClawDeepAdapter:)def _has_valid_model_config(self) -> bool:- """检查是否有有效的模型配置."""- # 检查环境变量中是否有 API_KEY- if os.getenv("API_KEY"):- return True-- # 检查实例的配置- if self._instance is not None and hasattr(self._instance, "_react_agent"):- react_agent = self._instance.react_agent- if react_agent is not None and hasattr(react_agent, "_config"):- config = react_agent._config- if hasattr(config, "model_client_config") and isinstance(- config.model_client_config, dict- ):- mcc = config.model_client_config- api_key = mcc.get("api_key", "")- if api_key:- return True+ """检查是否有有效的模型配置。++ 优先用已解析的 self._model,其次从 config.yaml 重新解析。+ 与 _create_model 同源,不独立读取环境变量。+ """+ if self._model is not None:+ mcc = getattr(self._model, "model_client_config", None)+ if isinstance(mcc, ModelClientConfig):+ if _mcc_looks_usable({"api_key": mcc.api_key, "api_base": getattr(mcc, "api_base", None)}):+ return True++ try:+ mcc = get_config().get("models", {}).get("default", {}).get("model_client_config", {})+ if isinstance(mcc, dict) and _mcc_looks_usable(mcc):+ return True+ except Exception as e:+ logger.warning("[JiuWenClawDeepAdapter] _has_valid_model_config config read failed: %s", e)return Falsediff --git a/tests/system_tests/test_a2x_client_runtime.py b/tests/system_tests/test_a2x_client_runtime.pyindex 07b25b413f..479b522474 100644--- a/tests/system_tests/test_a2x_client_runtime.py+++ b/tests/system_tests/test_a2x_client_runtime.py@@ -84,6 +84,14 @@ def _make_config(role: str, *, dataset: str = "", endpoint: str = "") -> dict:},},"permissions": {"enabled": True},+ "models": {+ "default": {+ "model_client_config": {+ "api_key": "system-test-key",+ "api_base": "http://fake-a2x.local/v1",+ }+ }+ },}