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: 热更新后无法使用general-purpose subagent

weixin_5592859419b9e352999e
diff --git a/jiuwenswarm/server/runtime/agent_adapter/interface_deep.py b/jiuwenswarm/server/runtime/agent_adapter/interface_deep.py
index bd136a1795..af9ae35074 100644
--- a/jiuwenswarm/server/runtime/agent_adapter/interface_deep.py
+++ b/jiuwenswarm/server/runtime/agent_adapter/interface_deep.py
@@ -57,7 +57,10 @@ from openjiuwen.harness import (
DeepAgentConfig,
VisionModelConfig,
)
-from openjiuwen.harness.factory import create_deep_agent
+from openjiuwen.harness.factory import (
+ _inject_general_purpose_subagent,
+ create_deep_agent,
+)
from openjiuwen.harness.prompts import resolve_language
from openjiuwen.harness.rails import (
LLMRetryRail,
@@ -7361,6 +7364,22 @@ class JiuWenSwarmDeepAdapter:
tool.card if hasattr(tool, "card") else tool for tool in (tool_cards or [])
]
configured_subagents, should_add_general_agent = self._build_configured_subagents(model, config, config_base)
+ # Hot reload uses configure(); factory inject does not run again.
+ configured_subagents = _inject_general_purpose_subagent(
+ configured_subagents,
+ add_general_purpose_agent=should_add_general_agent,
+ resolved_language=resolved_language,
+ rails=rails,
+ system_prompt=build_agent_identity_prompt(
+ language=self._resolve_prompt_language(),
+ ),
+ tools=normalized_tool_cards,
+ mcps=None,
+ model=model,
+ skills=None,
+ workspace=workspace_obj,
+ sys_operation=self._sys_operation,
+ ) or None
return DeepAgentConfig(
model=model,
card=agent_card,
diff --git a/tests/unit_tests/agentserver/test_deep_adapter_hot_reload_subagent_inherits_parent_env.py b/tests/unit_tests/agentserver/test_deep_adapter_hot_reload_subagent_inherits_parent_env.py
new file mode 100644
index 0000000000..9c6f9a66d3
--- /dev/null
+++ b/tests/unit_tests/agentserver/test_deep_adapter_hot_reload_subagent_inherits_parent_env.py
@@ -0,0 +1,105 @@
+# Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved.
+
+"""Regression: hot-reload inject must carry the parent agent's workspace and
+``sys_operation`` into the general-purpose subagent spec.
+
+The hot-reload path ``JiuWenSwarmDeepAdapter._make_deep_agent_config`` builds a
+``DeepAgentConfig`` directly (it does not re-enter ``create_deep_agent``), so the
+factory's ``_inject_general_purpose_subagent`` is invoked explicitly at the call
+site. The cold-start path (``resolve_deep_agent_parts``) passes the parent's
+``workspace`` and ``sys_operation`` into that call so the injected spec stays
+inside the parent's filesystem boundary — otherwise
+``DeepAgent.create_subagent`` mints a fresh LOCAL ``SysOperation`` for the
+general-purpose subagent and it escapes the parent's sandbox / remote
+filesystem boundary.
+
+This locks down that the hot-reload call site passes both fields and that they
+land on the injected spec as the *same instance* the parent ``DeepAgentConfig``
+carries — removing the two kwargs at the call site makes both assertions fail.
+"""
+
+from __future__ import annotations
+
+import pytest
+
+from jiuwenswarm.server.runtime.agent_adapter import interface_deep as interface_module
+from jiuwenswarm.server.runtime.agent_adapter.interface_deep import (
+ JiuWenSwarmDeepAdapter,
+)
+from openjiuwen.core.single_agent.schema.agent_card import AgentCard
+from openjiuwen.harness.schema.config import SubAgentConfig
+
+
+# general_agent on (so should_add_general_agent=True), browser/research off so
+# _build_configured_subagents does not try to build a browser subagent.
+_CFG = {
+ "max_iterations": 15,
+ "subagents": {
+ "general_agent": {"enabled": True},
+ "research_agent": {"enabled": False},
+ "browser_agent": {"enabled": False},
+ },
+ "models": {"default": {"model_client_config": {"model_name": "stub"}}},
+}
+
+
+def _general_purpose_spec(cfg):
+ specs = [
+ s
+ for s in (cfg.subagents or [])
+ if getattr(getattr(s, "agent_card", None), "name", None) == "general-purpose"
+ ]
+ assert len(specs) == 1, f"expected one injected general-purpose spec, got {len(specs)}"
+ spec = specs[0]
+ assert isinstance(spec, SubAgentConfig)
+ return spec
+
+
+def test_hot_reload_injected_spec_carries_parent_workspace_and_sys_operation(
+ monkeypatch: pytest.MonkeyPatch, tmp_path
+) -> None:
+ """The hot-reload injected general-purpose spec must carry the parent
+ agent's resolved ``workspace`` and ``sys_operation`` — same instances the
+ parent ``DeepAgentConfig`` carries, not fresh LOCAL substitutes.
+ """
+ adapter = JiuWenSwarmDeepAdapter()
+
+ # Sentinel sys_operation: identity probe. If the call site drops the
+ # ``sys_operation=`` kwarg, the spec falls back to None (a fresh LOCAL
+ # SysOperation at create_subagent time) and this identity check fails.
+ sentinel_sysop = object()
+ adapter._sys_operation = sentinel_sysop
+ adapter._workspace_dir = str(tmp_path)
+
+ # Keep _build_configured_subagents from reaching for a browser runtime or
+ # the on-disk config (we feed our own CFG as config_base).
+ monkeypatch.setattr(interface_module, "get_config", lambda *a, **k: _CFG)
+ adapter._sync_browser_runtime_environment = lambda *a, **k: None # type: ignore[assignment]
+ adapter._browser_runtime_enabled = lambda *a, **k: False # type: ignore[assignment]
+
+ cfg = adapter._make_deep_agent_config(
+ model=object(),
+ config=_CFG,
+ config_base=_CFG,
+ agent_card=AgentCard(name="main_agent", description="verify"),
+ tool_cards=[],
+ rails=None,
+ )
+
+ spec = _general_purpose_spec(cfg)
+
+ # Parent DeepAgentConfig must itself carry both resolved values.
+ assert cfg.workspace is not None
+ assert cfg.sys_operation is sentinel_sysop
+
+ # [P1] The injected spec inherits the SAME workspace instance (not a new
+ # one) and the SAME sys_operation instance (not a fresh LOCAL one).
+ assert spec.workspace is cfg.workspace, (
+ "hot-reload inject dropped parent workspace; general-purpose subagent "
+ "would escape the parent filesystem boundary"
+ )
+ assert spec.sys_operation is sentinel_sysop, (
+ "hot-reload inject dropped parent sys_operation; create_subagent would "
+ "mint a fresh LOCAL SysOperation for the general-purpose subagent"
+ )
+ assert getattr(spec.workspace, "root_path", None) == str(tmp_path)