Default-enable AI Planner in Host Agent; propose cloud-planner-proxy
Tests / Test passed: 626

- Host Agent now defaults AI_PLANNER_ENABLED=true (opt-out via env),
  scoped to apps/device-host-agent/host_agent/execution.py only; the
  shared runtime.planner_config default (disabled) is unchanged.
- Add openspec proposal for cloud-planner-proxy: centralize LLM
  provider config/credentials on the Cloud Control Plane and let the
  Host Agent proxy AI Planner decisions through it instead of holding
  provider API keys locally. Proposal only, no implementation yet.
This commit is contained in:
2026-07-13 20:50:35 +08:00
parent 78ce788e2f
commit 1107ace89c
9 changed files with 537 additions and 5 deletions
+19 -1
View File
@@ -1,10 +1,12 @@
from __future__ import annotations
import os
from collections.abc import Callable
from dataclasses import dataclass
from dataclasses import dataclass, replace
from device.manager import DeviceManager
from runtime.executor import Executor, default_tool_registry
from runtime.planner_config import PlannerConfig, load_config as load_planner_config
from runtime.task import TaskRunner
from storage.task_metadata import TaskMetadataStore
from storage.timeline import Timeline
@@ -33,6 +35,7 @@ def create_execution_factories(
executor=Executor(tools=default_tool_registry(manager=manager)),
metadata_store=metadata_store,
timeline=timeline,
planner_config=_host_agent_planner_config(),
)
def create_workflow_runner() -> WorkflowRunner:
@@ -46,3 +49,18 @@ def create_execution_factories(
workflow_runner_factory=create_workflow_runner,
workflow_store=shared_workflow_store,
)
def _host_agent_planner_config() -> PlannerConfig:
"""Host Agent defaults to the AI planner unless an operator opts out.
`runtime.planner_config` defaults `enabled=False` for the shared Runtime
library (local dev/tests/cloud dispatcher keep the deterministic stub
planner unless asked). The Host Agent is the actual device-control path,
so it flips that default on here -- an explicit `AI_PLANNER_ENABLED=false`
still disables it.
"""
config = load_planner_config()
if os.environ.get("AI_PLANNER_ENABLED") is None:
config = replace(config, enabled=True)
return config
@@ -2,8 +2,12 @@ from __future__ import annotations
from pathlib import Path
import pytest
from device.manager import DeviceManager
from host_agent.execution import create_execution_factories
from runtime.ai_planner import AIPlanner
from runtime.planner import Planner
from runtime.task import TaskRunner
from workflow.runner import WorkflowRunner
from workflow.store import WorkflowStore
@@ -26,6 +30,34 @@ def test_execution_factories_compose_existing_runtime_and_workflow(tmp_path) ->
assert isinstance(workflow_runner.task_runner_factory(), TaskRunner)
def test_created_task_runner_defaults_to_ai_planner(
tmp_path, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.delenv("AI_PLANNER_ENABLED", raising=False)
manager = DeviceManager()
factories = create_execution_factories(
manager, workflow_store=WorkflowStore(tmp_path / "workflows.sqlite3")
)
task_runner = factories.task_runner_factory()
assert isinstance(task_runner.planner, AIPlanner)
def test_created_task_runner_honors_explicit_ai_planner_opt_out(
tmp_path, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setenv("AI_PLANNER_ENABLED", "false")
manager = DeviceManager()
factories = create_execution_factories(
manager, workflow_store=WorkflowStore(tmp_path / "workflows.sqlite3")
)
task_runner = factories.task_runner_factory()
assert type(task_runner.planner) is Planner
def test_runtime_owned_packages_do_not_import_host_or_cloud_concerns() -> None:
root = Path(__file__).resolve().parents[3]
forbidden = ("import cloud", "from cloud", "import host_agent", "from host_agent")