diff --git a/google/genai/_gaos/types/interactions/__init__.py b/google/genai/_gaos/types/interactions/__init__.py index f4a711f23..96db0954d 100644 --- a/google/genai/_gaos/types/interactions/__init__.py +++ b/google/genai/_gaos/types/interactions/__init__.py @@ -53,7 +53,12 @@ CodeExecutionResultStep, CodeExecutionResultStepParam, ) - from .computeruse import ComputerUse, ComputerUseParam, EnvironmentEnum + from .computeruse import ( + ComputerUse, + ComputerUseParam, + DisabledSafetyPolicy, + EnvironmentEnum, + ) from .content import Content, ContentParam, UnknownContent from .createagentinteraction import ( CreateAgentInteraction, @@ -414,6 +419,7 @@ "DeepResearchAgentConfig", "DeepResearchAgentConfigParam", "Disabled", + "DisabledSafetyPolicy", "DocumentContent", "DocumentContentMimeType", "DocumentContentParam", @@ -726,6 +732,7 @@ "CodeExecutionResultStepParam": ".codeexecutionresultstep", "ComputerUse": ".computeruse", "ComputerUseParam": ".computeruse", + "DisabledSafetyPolicy": ".computeruse", "EnvironmentEnum": ".computeruse", "Content": ".content", "ContentParam": ".content", diff --git a/google/genai/_gaos/types/interactions/computeruse.py b/google/genai/_gaos/types/interactions/computeruse.py index 3069c7a2b..7a49e4238 100644 --- a/google/genai/_gaos/types/interactions/computeruse.py +++ b/google/genai/_gaos/types/interactions/computeruse.py @@ -37,6 +37,20 @@ r"""The environment being operated.""" +DisabledSafetyPolicy = Union[ + Literal[ + "financial_transactions", + "sensitive_data_modification", + "communication_tool", + "account_creation", + "data_modification", + "user_consent_management", + "legal_terms_and_agreements", + ], + UnrecognizedStr, +] + + class ComputerUseParam(TypedDict): r"""A tool that can be used by the model to interact with the computer.""" @@ -49,6 +63,8 @@ class ComputerUseParam(TypedDict): r"""Whether enable the prompt injection detection check on computer-use request. """ + disabled_safety_policies: NotRequired[List[DisabledSafetyPolicy]] + r"""Optional. Disabled safety policies for computer use.""" class ComputerUse(BaseModel): @@ -72,6 +88,9 @@ class ComputerUse(BaseModel): request. """ + disabled_safety_policies: Optional[List[DisabledSafetyPolicy]] = None + r"""Optional. Disabled safety policies for computer use.""" + @model_serializer(mode="wrap") def serialize_model(self, handler): optional_fields = set( @@ -79,6 +98,7 @@ def serialize_model(self, handler): "environment", "excluded_predefined_functions", "enable_prompt_injection_detection", + "disabled_safety_policies", ] ) serialized = handler(self) diff --git a/google/genai/_gaos/types/interactions/tool.py b/google/genai/_gaos/types/interactions/tool.py index d23322bfb..b9075d1ce 100644 --- a/google/genai/_gaos/types/interactions/tool.py +++ b/google/genai/_gaos/types/interactions/tool.py @@ -42,9 +42,9 @@ URLContextParam, GoogleSearchParam, FunctionParam, - ComputerUseParam, FileSearchParam, GoogleMapsParam, + ComputerUseParam, MCPServerParam, RetrievalParam, ], diff --git a/google/genai/tests/models/test_generate_content_tools.py b/google/genai/tests/models/test_generate_content_tools.py index 4c48c6c73..b932725e0 100644 --- a/google/genai/tests/models/test_generate_content_tools.py +++ b/google/genai/tests/models/test_generate_content_tools.py @@ -501,6 +501,27 @@ def divide_floats(a: float, b: float) -> float: ), exception_if_vertex='404', ), + pytest_helper.TestTableItem( + name='test_computer_use_with_disabled_safety_policies', + parameters=types._GenerateContentParameters( + model='gemini-2.5-computer-use-preview-10-2025', + contents=t.t_contents('Go to google and search nano banana'), + config={ + 'tools': [ + { + 'computer_use': { + 'environment': 'ENVIRONMENT_BROWSER', + 'disabled_safety_policies': [ + 'FINANCIAL_TRANSACTIONS', + 'COMMUNICATION_TOOL', + ], + } + } + ] + }, + ), + exception_if_vertex='404', + ), pytest_helper.TestTableItem( name='test_computer_use_multi_turn', parameters=types._GenerateContentParameters( diff --git a/google/genai/tests/types/test_types.py b/google/genai/tests/types/test_types.py index 099ff2a2d..5fdde3e9b 100644 --- a/google/genai/tests/types/test_types.py +++ b/google/genai/tests/types/test_types.py @@ -2925,3 +2925,19 @@ def test_instantiate_response_from_batch_json(): parsed.candidates[0].citation_metadata.citations[0].uri == 'http://someurl.com' ) + + +def test_computer_use_types(): + c = types.ComputerUse( + environment=types.Environment.ENVIRONMENT_MOBILE, + enable_prompt_injection_detection=True, + disabled_safety_policies=[ + types.SafetyPolicy.FINANCIAL_TRANSACTIONS, + types.SafetyPolicy.COMMUNICATION_TOOL, + ], + ) + assert c.environment == types.Environment.ENVIRONMENT_MOBILE + assert c.enable_prompt_injection_detection is True + assert len(c.disabled_safety_policies) == 2 + assert types.SafetyPolicy.FINANCIAL_TRANSACTIONS in c.disabled_safety_policies + diff --git a/google/genai/types.py b/google/genai/types.py index 5efe172fc..676f2c781 100644 --- a/google/genai/types.py +++ b/google/genai/types.py @@ -923,6 +923,27 @@ class FeatureSelectionPreference(_common.CaseInSensitiveEnum): PRIORITIZE_COST = 'PRIORITIZE_COST' +class SafetyPolicy(_common.CaseInSensitiveEnum): + """Disabled safety policies for computer use.""" + + SAFETY_POLICY_UNSPECIFIED = 'SAFETY_POLICY_UNSPECIFIED' + """Unspecified safety policy. This value should not be used.""" + FINANCIAL_TRANSACTIONS = 'FINANCIAL_TRANSACTIONS' + """Financial transactions safety policy.""" + SENSITIVE_DATA_MODIFICATION = 'SENSITIVE_DATA_MODIFICATION' + """Sensitive data modification safety policy.""" + COMMUNICATION_TOOL = 'COMMUNICATION_TOOL' + """Communication tool safety policy.""" + ACCOUNT_CREATION = 'ACCOUNT_CREATION' + """Account creation safety policy.""" + DATA_MODIFICATION = 'DATA_MODIFICATION' + """Data modification safety policy.""" + USER_CONSENT_MANAGEMENT = 'USER_CONSENT_MANAGEMENT' + """User consent management safety policy.""" + LEGAL_TERMS_AND_AGREEMENTS = 'LEGAL_TERMS_AND_AGREEMENTS' + """Legal terms and agreements safety policy.""" + + class EmbeddingApiType(_common.CaseInSensitiveEnum): """Enum representing the Gemini Enterprise Agent Platform embedding API to use.""" @@ -3348,6 +3369,10 @@ class ComputerUse(_common.BaseModel): description="""Optional. Whether enable the prompt injection detection check on computer-use request. """, ) + disabled_safety_policies: Optional[list[SafetyPolicy]] = Field( + default=None, + description="""Optional. Disabled safety policies for computer use.""", + ) class ComputerUseDict(TypedDict, total=False): @@ -3367,6 +3392,9 @@ class ComputerUseDict(TypedDict, total=False): """Optional. Whether enable the prompt injection detection check on computer-use request. """ + disabled_safety_policies: Optional[list[SafetyPolicy]] + """Optional. Disabled safety policies for computer use.""" + ComputerUseOrDict = Union[ComputerUse, ComputerUseDict]