feat(host-agent): default planner transport to cloud
Tests / Test passed: 794

This commit is contained in:
2026-07-14 20:42:27 +08:00
parent 6e511111c4
commit 30f09b6268
10 changed files with 98 additions and 78 deletions
+2 -2
View File
@@ -34,7 +34,7 @@ class HostAgentConfig:
console_allow_non_loopback: bool = False
console_session_ttl_seconds: float = 43200.0
console_history_limit: int = 200
ai_planner_transport: str = "direct"
ai_planner_transport: str = "cloud"
dependency_supervisor_enabled: bool = False
appium_supervised: bool = False
appium_host: str = "127.0.0.1"
@@ -175,7 +175,7 @@ def load_host_agent_config(
def _parse_ai_planner_transport(value: str | None) -> str:
if value is None:
return "direct"
return "cloud"
transport = value.strip().lower()
if transport not in _AI_PLANNER_TRANSPORTS:
raise HostAgentConfigurationError(
@@ -87,8 +87,7 @@ def _host_agent_planner(
instead of a local Anthropic/OpenAI SDK client.
Returns `None` (letting `TaskRunner` fall back to its own
`_default_planner()`) for the `direct` transport, which preserves the
existing default-enabled/direct-to-provider behavior unchanged.
`_default_planner()`) only for the explicit `direct` transport.
"""
planner_config = _host_agent_planner_config()
if not planner_config.enabled:
+11 -2
View File
@@ -11,11 +11,20 @@ from host_agent.config import (
)
def test_load_host_agent_config_uses_managed_cloud_default() -> None:
assert load_host_agent_config({}) == HostAgentConfig(
def test_load_host_agent_config_uses_managed_cloud_defaults() -> None:
config = load_host_agent_config({})
assert config == HostAgentConfig(
control_plane_url="https://amcp.home.jerryyan.top",
enrollment_managed=True,
)
assert config.ai_planner_transport == "cloud"
def test_load_host_agent_config_allows_explicit_direct_planner_transport() -> None:
config = load_host_agent_config({"AI_PLANNER_TRANSPORT": "direct"})
assert config.ai_planner_transport == "direct"
def test_load_host_agent_config_parses_poll_and_retry_values() -> None:
@@ -158,8 +158,9 @@ def test_created_task_runner_honors_explicit_ai_planner_opt_out(
assert type(task_runner.planner) is Planner
def test_cloud_transport_builds_ai_planner_with_cloud_proxy_client(
tmp_path, monkeypatch: pytest.MonkeyPatch
@pytest.mark.parametrize("transport", [None, "cloud"])
def test_default_and_explicit_cloud_transport_build_ai_planner_with_cloud_proxy_client(
tmp_path, monkeypatch: pytest.MonkeyPatch, transport: str | None
) -> None:
monkeypatch.delenv("AI_PLANNER_ENABLED", raising=False)
manager = DeviceManager()
@@ -167,7 +168,7 @@ def test_cloud_transport_builds_ai_planner_with_cloud_proxy_client(
control_plane_url="https://control-plane.example",
host_id="host-a",
token="token-a",
ai_planner_transport="cloud",
**({} if transport is None else {"ai_planner_transport": transport}),
)
factories = create_execution_factories(
manager,
@@ -182,9 +183,8 @@ def test_cloud_transport_builds_ai_planner_with_cloud_proxy_client(
assert task_runner.planner.client.config is host_agent_config
@pytest.mark.parametrize("transport", [None, "direct"])
def test_direct_transport_preserves_existing_local_provider_construction(
tmp_path, monkeypatch: pytest.MonkeyPatch, transport: str | None
def test_explicit_direct_transport_preserves_local_provider_construction(
tmp_path, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.delenv("AI_PLANNER_ENABLED", raising=False)
manager = DeviceManager()
@@ -192,7 +192,7 @@ def test_direct_transport_preserves_existing_local_provider_construction(
control_plane_url="https://control-plane.example",
host_id="host-a",
token="token-a",
**({} if transport is None else {"ai_planner_transport": transport}),
ai_planner_transport="direct",
)
factories = create_execution_factories(
manager,