From 96fd9cb98eb12f3c3d5a4103b40967383e4419ef Mon Sep 17 00:00:00 2001 From: Dillon DuPont Date: Thu, 17 Jul 2025 11:25:34 -0700 Subject: [PATCH] Fixed OS type that gets passed to OAI --- .../agent/providers/openai/api_handler.py | 26 ++++++++++++++++--- .../agent/agent/providers/openai/loop.py | 2 ++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/libs/python/agent/agent/providers/openai/api_handler.py b/libs/python/agent/agent/providers/openai/api_handler.py index f1056cee..e4b5de75 100644 --- a/libs/python/agent/agent/providers/openai/api_handler.py +++ b/libs/python/agent/agent/providers/openai/api_handler.py @@ -3,7 +3,7 @@ import logging import requests import os -from typing import Any, Dict, List, Optional, TYPE_CHECKING +from typing import Any, Dict, List, Literal, Optional, TYPE_CHECKING from datetime import datetime if TYPE_CHECKING: @@ -45,6 +45,7 @@ class OpenAIAPIHandler: display_width: str, display_height: str, previous_response_id: Optional[str] = None, + os_type: str, ) -> Dict[str, Any]: """Send an initial request to the OpenAI API with a screenshot. @@ -57,6 +58,15 @@ class OpenAIAPIHandler: Returns: API response """ + # Convert from our internal OS types to the ones OpenAI expects + if os_type == "macos": + os_type = "mac" + elif os_type == "linux": + os_type = "ubuntu" + + if os_type not in ["mac", "windows", "ubuntu", "browser"]: + raise ValueError(f"Invalid OS type: {os_type}") + # Convert display dimensions to integers try: width = int(display_width) @@ -128,7 +138,7 @@ class OpenAIAPIHandler: "type": "computer_use_preview", "display_width": width, "display_height": height, - "environment": "mac", # We're on macOS + "environment": os_type, # We're on macOS } ], "input": input_array, @@ -180,6 +190,7 @@ class OpenAIAPIHandler: display_width: str, display_height: str, previous_response_id: str, + os_type: str, ) -> Dict[str, Any]: """Send a request to the OpenAI API with computer_call_output. @@ -193,6 +204,15 @@ class OpenAIAPIHandler: Returns: API response """ + # Convert from our internal OS types to the ones OpenAI expects + if os_type == "macos": + os_type = "mac" + elif os_type == "linux": + os_type = "ubuntu" + + if os_type not in ["mac", "windows", "ubuntu", "browser"]: + raise ValueError(f"Invalid OS type: {os_type}") + # Convert display dimensions to integers try: width = int(display_width) @@ -256,7 +276,7 @@ class OpenAIAPIHandler: "type": "computer_use_preview", "display_width": width, "display_height": height, - "environment": "mac", # We're on macOS + "environment": os_type, # We're on macOS } ], "input": [ diff --git a/libs/python/agent/agent/providers/openai/loop.py b/libs/python/agent/agent/providers/openai/loop.py index 4095cdc0..cc9a07db 100644 --- a/libs/python/agent/agent/providers/openai/loop.py +++ b/libs/python/agent/agent/providers/openai/loop.py @@ -280,6 +280,7 @@ class OpenAILoop(BaseLoop): display_width=str(screen_size["width"]), display_height=str(screen_size["height"]), previous_response_id=self.last_response_id, + os_type=self.computer.os_type, ) # Store response ID for next request @@ -401,6 +402,7 @@ class OpenAILoop(BaseLoop): display_width=str(screen_size["width"]), display_height=str(screen_size["height"]), previous_response_id=self.last_response_id, # Use instance variable + os_type=self.computer.os_type, ) # Store response ID for next request