Implements all 19 tasks of the cloud-planner-proxy OpenSpec change:
- Cloud API: cloud.planner_config (CloudPlannerConfig, load/build helpers)
reusing runtime.tool_calling_client provider clients (no new dependency
needed -- device-cloud-platform already depends on device-agent-runtime).
- Cloud API: new host-scoped POST /internal/v1/hosts/{host_id}/planner/decide
internal endpoint, reusing existing bearer auth; logs only metadata
(host id, tool name, latency, error class), never prompt/screenshot
content.
- Host Agent: new AI_PLANNER_TRANSPORT config (direct default | cloud) and
host_agent/cloud_planner_client.py::CloudProxyToolCallingClient, a
synchronous ToolCallingClient implementation (structural, not importing
runtime) that calls the new endpoint via its own httpx.Client -- avoids
bridging the async HostAgentClient across the worker-thread boundary
that AIPlanner.plan() runs in (asyncio.to_thread in lease.py).
- Host Agent wiring: create_execution_factories()/_host_agent_planner()
select the cloud-proxy client only when AI_PLANNER_TRANSPORT=cloud;
direct/unset transport is unchanged (still the default).
- Tests: 22 new tests across Cloud API config, the new endpoint, the new
client, and transport-selection wiring; full non-integration suite
(492 tests) passes with no regressions.
- Docs: docs/CLOUD_DEPLOYMENT.md documents the cloud transport, its
trade-offs, and the credential split between Host Agent and Cloud API.
proposal.md/design.md were corrected during implementation to reflect two
findings: no new anthropic/openai dependency is actually needed, and
CloudProxyToolCallingClient uses its own sync httpx.Client rather than a
new HostAgentClient method, per the thread-boundary reasoning above.
124 lines
3.2 KiB
Python
124 lines
3.2 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from typing import Any, Literal
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class HostEnrollmentRequest(BaseModel):
|
|
agent_instance_id: str = Field(min_length=1, max_length=256)
|
|
host_token: str = Field(min_length=32, max_length=512)
|
|
display_name: str | None = Field(default=None, max_length=256)
|
|
|
|
|
|
class HostEnrollmentResponse(BaseModel):
|
|
host_id: str
|
|
|
|
|
|
class DeviceEnrollmentRequest(BaseModel):
|
|
local_device_id: str = Field(min_length=1, max_length=256)
|
|
driver_type: str = Field(min_length=1, max_length=128)
|
|
name: str | None = Field(default=None, max_length=256)
|
|
capability_tags: list[str] = Field(default_factory=list)
|
|
|
|
|
|
class DeviceEnrollmentResponse(BaseModel):
|
|
device_id: str
|
|
|
|
|
|
class DeviceSnapshotModel(BaseModel):
|
|
device_id: str = Field(min_length=1)
|
|
driver_type: str = Field(min_length=1)
|
|
status: Literal["idle", "busy", "offline", "error"]
|
|
capability_tags: list[str] = Field(default_factory=list)
|
|
|
|
|
|
class HeartbeatRequest(BaseModel):
|
|
host_id: str = Field(min_length=1)
|
|
address: str | None = None
|
|
devices: list[DeviceSnapshotModel] = Field(default_factory=list)
|
|
|
|
|
|
class HeartbeatResponse(BaseModel):
|
|
host_id: str
|
|
accepted_devices: int
|
|
received_at: datetime
|
|
|
|
|
|
class ClaimRequest(BaseModel):
|
|
host_id: str = Field(min_length=1)
|
|
timeout_seconds: float = Field(default=20.0, ge=0, le=60)
|
|
|
|
|
|
class AssignmentModel(BaseModel):
|
|
task_id: str
|
|
attempt: int = Field(ge=1)
|
|
lease_id: str
|
|
lease_expires_at: datetime
|
|
host_id: str
|
|
device_id: str
|
|
goal: str | None = None
|
|
workflow_definition_id: str | None = None
|
|
|
|
|
|
class ClaimResponse(BaseModel):
|
|
assignment: AssignmentModel | None = None
|
|
timed_out: bool = False
|
|
|
|
|
|
class LeaseRenewalRequest(BaseModel):
|
|
host_id: str = Field(min_length=1)
|
|
task_id: str = Field(min_length=1)
|
|
attempt: int = Field(ge=1)
|
|
lease_id: str = Field(min_length=1)
|
|
|
|
|
|
class LeaseRenewalResponse(BaseModel):
|
|
status: Literal["renewed"]
|
|
lease_expires_at: datetime
|
|
|
|
|
|
class TerminalResultRequest(BaseModel):
|
|
host_id: str = Field(min_length=1)
|
|
task_id: str = Field(min_length=1)
|
|
attempt: int = Field(ge=1)
|
|
lease_id: str = Field(min_length=1)
|
|
status: Literal["done", "failed"]
|
|
failure_reason: str | None = None
|
|
result: dict[str, Any] | None = None
|
|
|
|
|
|
class TerminalResultResponse(BaseModel):
|
|
status: Literal["recorded", "already_recorded"]
|
|
|
|
|
|
class StaleLeaseConflict(BaseModel):
|
|
code: Literal["stale_lease"] = "stale_lease"
|
|
detail: str
|
|
|
|
|
|
class PlannerToolSpecModel(BaseModel):
|
|
name: str = Field(min_length=1)
|
|
description: str = ""
|
|
parameters: dict[str, Any] = Field(default_factory=dict)
|
|
|
|
|
|
class PlannerDecisionRequest(BaseModel):
|
|
host_id: str = Field(min_length=1)
|
|
system_prompt: str
|
|
user_prompt: str
|
|
screenshot_base64: str | None = None
|
|
tools: list[PlannerToolSpecModel] = Field(default_factory=list)
|
|
timeout_seconds: float = Field(default=30.0, gt=0, le=120)
|
|
|
|
|
|
class PlannerDecisionResponse(BaseModel):
|
|
tool_name: str
|
|
arguments: dict[str, Any] = Field(default_factory=dict)
|
|
|
|
|
|
class PlannerDecisionError(BaseModel):
|
|
code: Literal["planner_unavailable"] = "planner_unavailable"
|
|
detail: str
|