Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion google/genai/_gaos/types/interactions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -414,6 +419,7 @@
"DeepResearchAgentConfig",
"DeepResearchAgentConfigParam",
"Disabled",
"DisabledSafetyPolicy",
"DocumentContent",
"DocumentContentMimeType",
"DocumentContentParam",
Expand Down Expand Up @@ -726,6 +732,7 @@
"CodeExecutionResultStepParam": ".codeexecutionresultstep",
"ComputerUse": ".computeruse",
"ComputerUseParam": ".computeruse",
"DisabledSafetyPolicy": ".computeruse",
"EnvironmentEnum": ".computeruse",
"Content": ".content",
"ContentParam": ".content",
Expand Down
20 changes: 20 additions & 0 deletions google/genai/_gaos/types/interactions/computeruse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand All @@ -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):
Expand All @@ -72,13 +88,17 @@ 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(
[
"environment",
"excluded_predefined_functions",
"enable_prompt_injection_detection",
"disabled_safety_policies",
]
)
serialized = handler(self)
Expand Down
2 changes: 1 addition & 1 deletion google/genai/_gaos/types/interactions/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
URLContextParam,
GoogleSearchParam,
FunctionParam,
ComputerUseParam,
FileSearchParam,
GoogleMapsParam,
ComputerUseParam,
MCPServerParam,
RetrievalParam,
],
Expand Down
21 changes: 21 additions & 0 deletions google/genai/tests/models/test_generate_content_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 16 additions & 0 deletions google/genai/tests/types/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

28 changes: 28 additions & 0 deletions google/genai/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down Expand Up @@ -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):
Expand All @@ -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]

Expand Down
Loading