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(auto_harness): 取消激活技能时性能模型未生效问题修复
ray_le93032dc44b2e
diff --git a/jiuwenswarm/agents/harness/common/auto_harness/service.py b/jiuwenswarm/agents/harness/common/auto_harness/service.pyindex 3251250fb3..637b626631 100644--- a/jiuwenswarm/agents/harness/common/auto_harness/service.py+++ b/jiuwenswarm/agents/harness/common/auto_harness/service.py@@ -173,10 +173,20 @@ class AutoHarnessService:Instantiated as member variable of JiuWenClawDeepAdapter for proper lifecycle management."""- def __init__(self, rail: Any, agent: Any | None = None) -> None:+ def __init__(+ self,+ rail: Any,+ agent: Any | None = None,+ agent_manager: Any | None = None,+ ) -> None:"""Initialize service - load base config, create data directories.Per §5.6.2: config.yaml is bootstrapped if not exists.++ Args:+ rail: Stream event rail for output.+ agent: DeepAgent instance for load/unload harness config.+ agent_manager: AgentManager for broadcasting package changes to all agent instances."""# Directory paths (per §5.6.4)self.data_dir = _AUTO_HARNESS_DATA_DIR@@ -187,6 +197,7 @@ class AutoHarnessService:self._stream_event_rail = railself._agent = agent+ self._agent_manager = agent_manager# Active runs tracked by session_id (per §5.2)self._active_runs: dict[str, ActiveAutoHarnessRun] = {}@@ -2105,15 +2116,21 @@ class AutoHarnessService:"""Get packages info for frontend API."""return self.load_packages()- async def activate_package(self, package_id: str) -> dict[str, Any]:+ async def activate_package(+ self,+ package_id: str,+ channel_id: str | None = None,+ ) -> dict[str, Any]:"""Activate a harness package by loading its config (stacking on existing).Stacked activation flow:1. Load the new package config (stack on any existing active packages)2. Update metadata: add package_id to active_package_ids list+ 3. Broadcast to all agent.fast/agent.plan instances in the channelArgs:package_id: The package ID to activate+ channel_id: Optional channel ID to limit broadcast scopeReturns:Payload for frontend response with activation details@@ -2165,6 +2182,17 @@ class AutoHarnessService:try:loaded_resources = await self._agent.load_harness_config(config_path)self.update_active_status(package_id, "add")++ # Broadcast to all agent.fast/agent.plan instances (skip current, already loaded)+ if self._agent_manager:+ await self._agent_manager.broadcast_package_change_to_single_agents(+ package_id,+ config_path,+ "activate",+ channel_id=channel_id,+ skip_instance=self._agent,+ )+logger.info("[AutoHarnessService] Activated package %s, loaded resources: %s",package_id,@@ -2176,7 +2204,7 @@ class AutoHarnessService:"runtime_path": package.get("runtime_path", ""),"config_path": config_path,"loaded_resources": loaded_resources,- "message": f"扩展已热生效,加载资源: {len(loaded_resources)} 项",+ "message": f"扩展已热生效(规划与性能模式),加载资源: {len(loaded_resources)} 项",}except FileNotFoundError as exc:raise ValueError(f"配置文件不存在: {exc}") from exc@@ -2186,11 +2214,21 @@ class AutoHarnessService:logger.exception("[AutoHarnessService] Activate package %s failed: %s", package_id, exc)raise ValueError(f"激活扩展失败: {exc}") from exc- async def deactivate_package(self, package_id: str) -> dict[str, Any]:+ async def deactivate_package(+ self,+ package_id: str,+ channel_id: str | None = None,+ ) -> dict[str, Any]:"""Deactivate a harness package by unloading its config.+ Deactivation flow:+ 1. Unload from current agent instance+ 2. Broadcast to all agent.fast/agent.plan instances in the channel+ 3. Update metadata: remove package_id from active_package_ids list+Args:package_id: The package ID to deactivate+ channel_id: Optional channel ID to limit broadcast scopeReturns:Payload for frontend response with deactivation details@@ -2242,13 +2280,23 @@ class AutoHarnessService:exc,)+ # Broadcast to all agent.fast/agent.plan instances before updating status+ if self._agent_manager and config_path and Path(config_path).exists():+ await self._agent_manager.broadcast_package_change_to_single_agents(+ package_id,+ config_path,+ "deactivate",+ channel_id=channel_id,+ skip_instance=self._agent,+ )+self.update_active_status(package_id, "remove")logger.info("[AutoHarnessService] Package %s deactivated", package_id)return {"deactivated_package_id": package_id,"extension_name": extension_name,- "message": f"扩展 {extension_name} 已去激活",+ "message": f"扩展 {extension_name} 已取消激活",}def delete_package(self, package_id: str) -> dict[str, Any]:diff --git a/jiuwenswarm/channels/web/frontend/src/i18n/locales/zh.json b/jiuwenswarm/channels/web/frontend/src/i18n/locales/zh.jsonindex 6f7237879c..a309419a03 100644--- a/jiuwenswarm/channels/web/frontend/src/i18n/locales/zh.json+++ b/jiuwenswarm/channels/web/frontend/src/i18n/locales/zh.json@@ -335,12 +335,12 @@"invalidZipFormat": "无效的 zip 文件格式","missingHarnessConfig": "Zip 文件必须包含 harness_config.yaml","selectZipFile": "选择 .zip 文件导入",- "deactivate": "去激活",- "deactivating": "正在去激活...",- "deactivateFailed": "去激活失败",- "deactivateSuccess": "去激活成功",- "deactivateAll": "全部去激活",- "allDeactivated": "所有扩展已去激活",+ "deactivate": "取消激活",+ "deactivating": "正在取消激活...",+ "deactivateFailed": "取消激活失败",+ "deactivateSuccess": "取消激活成功",+ "deactivateAll": "全部取消激活",+ "allDeactivated": "所有扩展已取消激活","activePackages": "已激活扩展"},"todoList": {diff --git a/jiuwenswarm/server/agent_ws_server.py b/jiuwenswarm/server/agent_ws_server.pyindex 7969636db8..e4714cf364 100644--- a/jiuwenswarm/server/agent_ws_server.py+++ b/jiuwenswarm/server/agent_ws_server.py@@ -4862,8 +4862,12 @@ class AgentWebSocketServer:hasattr(agent_instance, "load_harness_config") if agent_instance else False,)- service = AutoHarnessService(rail=None, agent=agent_instance)- payload = await service.activate_package(package_id)+ service = AutoHarnessService(+ rail=None,+ agent=agent_instance,+ agent_manager=self._agent_manager,+ )+ payload = await service.activate_package(package_id, channel_id=channel_id)resp = AgentResponse(request_id=request.request_id,channel_id=request.channel_id,@@ -4912,7 +4916,7 @@ class AgentWebSocketServer:try:# Get or create the agent instance (auto-create if not exists)- channel_id = request.channel_id or "default"+ channel_id = request.channel_id or "web"mode, sub_mode = _apply_resolved_mode_to_request(request)agent_mode = "agent" if mode == "auto_harness" else modeagent = await self._agent_manager.get_agent(@@ -4925,8 +4929,12 @@ class AgentWebSocketServer:if agent is not None:agent_instance = agent.get_instance()- service = AutoHarnessService(rail=None, agent=agent_instance)- payload = await service.deactivate_package(package_id)+ service = AutoHarnessService(+ rail=None,+ agent=agent_instance,+ agent_manager=self._agent_manager,+ )+ payload = await service.deactivate_package(package_id, channel_id=channel_id)resp = AgentResponse(request_id=request.request_id,channel_id=request.channel_id,diff --git a/jiuwenswarm/server/runtime/agent_manager.py b/jiuwenswarm/server/runtime/agent_manager.pyindex 60a7ba56ac..2db023a606 100644--- a/jiuwenswarm/server/runtime/agent_manager.py+++ b/jiuwenswarm/server/runtime/agent_manager.py@@ -305,6 +305,78 @@ class AgentManager:return next(iter(channel_agents.values()), None)return None+ async def broadcast_package_change_to_single_agents(+ self,+ package_id: str,+ config_path: str,+ operation: str,+ channel_id: str | None = None,+ skip_instance: Any | None = None,+ ) -> None:+ """Broadcast package change to agent.fast and agent.plan instances only.++ This ensures deactivation affects all relevant agent instances, not just the current one.+ Does NOT affect team mode agents.++ Args:+ package_id: The package ID being activated/deactivated.+ config_path: Absolute path to harness_config.yaml.+ operation: "activate" or "deactivate".+ channel_id: Optional channel ID to limit broadcast scope.+ skip_instance: Optional agent instance to skip (already processed by caller).+ """+ target_modes = {"agent", "agent.fast", "agent.plan"}++ for channel_key, channel_agents in self.agents.items():+ # Limit to specific channel if provided+ if channel_id and channel_key != _normalize_channel_id(channel_id):+ continue++ for cache_key, agent in channel_agents.items():+ # Parse mode from cache_key: "mode:sub_mode:project"+ mode = cache_key.split(":")[0] if ":" in cache_key else ""+ if mode not in target_modes:+ continue # Skip team and other modes++ instance = agent.get_instance()+ if instance is None:+ continue++ # Skip the instance that was already processed by the caller+ if skip_instance is not None and instance is skip_instance:+ logger.debug(+ "[AgentManager] Skipping already processed agent %s for package %s",+ cache_key,+ package_id,+ )+ continue++ try:+ if operation == "deactivate":+ await instance.unload_harness_config(config_path)+ logger.info(+ "[AgentManager] Unloaded package %s from agent %s (channel=%s)",+ package_id,+ cache_key,+ channel_key,+ )+ elif operation == "activate":+ await instance.load_harness_config(config_path)+ logger.info(+ "[AgentManager] Loaded package %s to agent %s (channel=%s)",+ package_id,+ cache_key,+ channel_key,+ )+ except Exception as exc:+ logger.warning(+ "[AgentManager] Failed to %s package %s on agent %s: %s",+ operation,+ package_id,+ cache_key,+ exc,+ )+async def reload_agents_config(self, config, env) -> None:"""reload agent config"""self._latest_env_overrides = dict(env) if isinstance(env, dict) else {}