This commit is contained in:
@@ -28,10 +28,21 @@ import httpx
|
||||
from cloud.internal_api.models import PlannerDecisionError, PlannerDecisionResponse
|
||||
from host_agent.config import HostAgentConfig
|
||||
from host_agent.planner_context import current_planner_execution_context
|
||||
from runtime.tool_calling_client import ToolCallDecision, ToolCallUnavailable, ToolCallUsage
|
||||
from runtime.tool_calling_client import (
|
||||
ToolCallDecision,
|
||||
ToolCallUnavailable,
|
||||
ToolCallUsage,
|
||||
)
|
||||
from runtime.tool_specs import ToolSpec
|
||||
|
||||
|
||||
_CLOUD_PROVIDER_MAX_TIMEOUT_SECONDS = 120.0
|
||||
_CLOUD_PROXY_TRANSPORT_GRACE_SECONDS = 5.0
|
||||
_CLOUD_PROXY_HTTP_TIMEOUT_SECONDS = (
|
||||
_CLOUD_PROVIDER_MAX_TIMEOUT_SECONDS + _CLOUD_PROXY_TRANSPORT_GRACE_SECONDS
|
||||
)
|
||||
|
||||
|
||||
class CloudProxyToolCallingClient:
|
||||
def __init__(
|
||||
self,
|
||||
@@ -69,7 +80,9 @@ class CloudProxyToolCallingClient:
|
||||
}
|
||||
for spec in tools
|
||||
],
|
||||
"timeout_seconds": timeout,
|
||||
# Legacy Cloud API versions use this field. Current Cloud API versions
|
||||
# resolve the provider timeout from the active Provider profile.
|
||||
"timeout_seconds": min(timeout, _CLOUD_PROVIDER_MAX_TIMEOUT_SECONDS),
|
||||
}
|
||||
context = current_planner_execution_context()
|
||||
if context is not None:
|
||||
@@ -85,7 +98,7 @@ class CloudProxyToolCallingClient:
|
||||
f"/internal/v1/hosts/{self.config.host_id}/planner/decide",
|
||||
json=payload,
|
||||
headers={"Authorization": f"Bearer {self.config.token}"},
|
||||
timeout=timeout + 5,
|
||||
timeout=_CLOUD_PROXY_HTTP_TIMEOUT_SECONDS,
|
||||
)
|
||||
except httpx.HTTPError as exc:
|
||||
raise ToolCallUnavailable(str(exc)) from exc
|
||||
|
||||
@@ -5,7 +5,10 @@ import json
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from host_agent.cloud_planner_client import CloudProxyToolCallingClient
|
||||
from host_agent.cloud_planner_client import (
|
||||
_CLOUD_PROXY_HTTP_TIMEOUT_SECONDS,
|
||||
CloudProxyToolCallingClient,
|
||||
)
|
||||
from host_agent.config import HostAgentConfig
|
||||
from host_agent.planner_context import PlannerExecutionContext, _context
|
||||
from runtime.tool_calling_client import ToolCallDecision, ToolCallUnavailable
|
||||
@@ -79,6 +82,29 @@ def test_decide_base64_encodes_screenshot() -> None:
|
||||
assert body["screenshot_base64"] == "aGVsbG8="
|
||||
|
||||
|
||||
def test_decide_clamps_legacy_timeout_and_waits_for_cloud_profile_timeout() -> None:
|
||||
seen_requests: list[httpx.Request] = []
|
||||
|
||||
def handler(request: httpx.Request) -> httpx.Response:
|
||||
seen_requests.append(request)
|
||||
return httpx.Response(200, json={"tool_name": "tap", "arguments": {}})
|
||||
|
||||
client = _client(handler)
|
||||
|
||||
client.decide(
|
||||
system_prompt="sp",
|
||||
user_prompt="up",
|
||||
screenshot=None,
|
||||
tools=_TOOLS,
|
||||
timeout=180.0,
|
||||
)
|
||||
|
||||
request = seen_requests[0]
|
||||
body = json.loads(request.content)
|
||||
assert body["timeout_seconds"] == 120.0
|
||||
assert request.extensions["timeout"]["read"] == _CLOUD_PROXY_HTTP_TIMEOUT_SECONDS
|
||||
|
||||
|
||||
def test_decide_includes_bound_assignment_context() -> None:
|
||||
seen_requests: list[httpx.Request] = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user