Skip to content

Commit 96b79b3

Browse files
google-genai-botcopybara-github
authored andcommitted
feat(environments): introduce self-hosted BYOS mode, system_instruction, custom_config, and environment_key in SDKs and CLI
PiperOrigin-RevId: 1018553620
1 parent b1631d3 commit 96b79b3

11 files changed

Lines changed: 219 additions & 7 deletions

File tree

‎google/genai/_gaos/environments.py‎

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,17 @@
2727
from .types.environments import (
2828
createenvironmentrequest as environments_createenvironmentrequest,
2929
)
30-
from .types.interactions import source as interactions_source
30+
from .types.interactions import (
31+
environmentmode as interactions_environmentmode,
32+
source as interactions_source,
33+
)
3134
from .utils import get_security_from_env, response_helpers
3235
from .utils.unmarshal_json_response import unmarshal_json_response
3336
try:
3437
import httpx
3538
except ImportError:
3639
import httpx2 as httpx
37-
from typing import Any, Iterable, List, Mapping, Optional, Union, cast
40+
from typing import Any, Dict, Iterable, List, Mapping, Optional, Union, cast
3841

3942

4043
class Environments(BaseSDK):
@@ -64,6 +67,7 @@ def list_environments(
6467
self,
6568
*,
6669
api_version: Optional[str] = None,
70+
mode: Optional[interactions_environmentmode.EnvironmentMode] = None,
6771
page_size: Optional[int] = None,
6872
page_token: Optional[str] = None,
6973
extra_headers: Optional[Mapping[str, str]] = None,
@@ -73,6 +77,7 @@ def list_environments(
7377
r"""Lists environments.
7478
7579
:param api_version: API version for request routing.
80+
:param mode: Optional. Filter environments by compute lifecycle mode.
7681
:param page_size: Optional. Maximum number of environments to return.
7782
If unspecified, defaults to 50. Maximum is 1000.
7883
:param page_token: Optional. Pagination token.
@@ -96,6 +101,7 @@ def list_environments(
96101

97102
request = models.ListEnvironmentsRequest(
98103
api_version=api_version,
104+
mode=mode,
99105
page_size=page_size,
100106
page_token=page_token,
101107
)
@@ -218,7 +224,9 @@ def create_environment(
218224
self,
219225
*,
220226
api_version: Optional[str] = None,
227+
custom_config: Optional[Mapping[str, Any]] = None,
221228
from_environment: Optional[str] = None,
229+
mode: Optional[interactions_environmentmode.EnvironmentMode] = None,
222230
network: Optional[
223231
Union[
224232
environments_createenvironmentrequest.CreateEnvironmentRequestNetworkUnion,
@@ -231,6 +239,7 @@ def create_environment(
231239
Iterable[interactions_source.SourceParam],
232240
]
233241
] = None,
242+
system_instruction: Optional[str] = None,
234243
extra_headers: Optional[Mapping[str, str]] = None,
235244
extra_query: Optional[Mapping[str, Any]] = None,
236245
extra_body: Optional[Mapping[str, Any]] = None,
@@ -239,11 +248,18 @@ def create_environment(
239248
r"""Creates an environment.
240249
241250
:param api_version: API version for request routing.
251+
:param custom_config: Optional. Arbitrary customer-defined JSON configuration passed through
252+
to the self-hosted environment poller. Only supported when `mode` is
253+
`SELF_HOSTED`.
242254
:param from_environment: Optional. The source environment to copy/fork from.
243255
Format: `environments/{environment_id}` or `{environment_id}`.
244256
When specified, `sources` and `env` must be empty.
257+
:param mode: The compute lifecycle mode for an environment.
245258
:param network: Network configuration for the environment.
246259
:param sources: Sources to be mounted into the environment.
260+
:param system_instruction: Optional. System instruction applied to interactions running in this
261+
environment. Only supported for `SELF_HOSTED` environments, where it is
262+
recommended.
247263
:param extra_headers: Additional headers to set or replace on requests.
248264
:param extra_query: Additional query parameters to append to requests.
249265
:param extra_body: Additional JSON object fields to merge into request bodies.
@@ -266,13 +282,16 @@ def create_environment(
266282
request = models.CreateEnvironmentRequest(
267283
api_version=api_version,
268284
body=environments.CreateEnvironmentRequest(
285+
custom_config=utils.unmarshal(custom_config, Optional[Dict[str, Any]]),
269286
from_environment=from_environment,
287+
mode=mode,
270288
network=utils.get_pydantic_model(
271289
network, Optional[environments.CreateEnvironmentRequestNetworkUnion]
272290
),
273291
sources=utils.get_pydantic_model(
274292
sources, Optional[List[interactions.Source]]
275293
),
294+
system_instruction=system_instruction,
276295
),
277296
)
278297

@@ -780,6 +799,7 @@ async def list_environments(
780799
self,
781800
*,
782801
api_version: Optional[str] = None,
802+
mode: Optional[interactions_environmentmode.EnvironmentMode] = None,
783803
page_size: Optional[int] = None,
784804
page_token: Optional[str] = None,
785805
extra_headers: Optional[Mapping[str, str]] = None,
@@ -789,6 +809,7 @@ async def list_environments(
789809
r"""Lists environments.
790810
791811
:param api_version: API version for request routing.
812+
:param mode: Optional. Filter environments by compute lifecycle mode.
792813
:param page_size: Optional. Maximum number of environments to return.
793814
If unspecified, defaults to 50. Maximum is 1000.
794815
:param page_token: Optional. Pagination token.
@@ -812,6 +833,7 @@ async def list_environments(
812833

813834
request = models.ListEnvironmentsRequest(
814835
api_version=api_version,
836+
mode=mode,
815837
page_size=page_size,
816838
page_token=page_token,
817839
)
@@ -937,7 +959,9 @@ async def create_environment(
937959
self,
938960
*,
939961
api_version: Optional[str] = None,
962+
custom_config: Optional[Mapping[str, Any]] = None,
940963
from_environment: Optional[str] = None,
964+
mode: Optional[interactions_environmentmode.EnvironmentMode] = None,
941965
network: Optional[
942966
Union[
943967
environments_createenvironmentrequest.CreateEnvironmentRequestNetworkUnion,
@@ -950,6 +974,7 @@ async def create_environment(
950974
Iterable[interactions_source.SourceParam],
951975
]
952976
] = None,
977+
system_instruction: Optional[str] = None,
953978
extra_headers: Optional[Mapping[str, str]] = None,
954979
extra_query: Optional[Mapping[str, Any]] = None,
955980
extra_body: Optional[Mapping[str, Any]] = None,
@@ -958,11 +983,18 @@ async def create_environment(
958983
r"""Creates an environment.
959984
960985
:param api_version: API version for request routing.
986+
:param custom_config: Optional. Arbitrary customer-defined JSON configuration passed through
987+
to the self-hosted environment poller. Only supported when `mode` is
988+
`SELF_HOSTED`.
961989
:param from_environment: Optional. The source environment to copy/fork from.
962990
Format: `environments/{environment_id}` or `{environment_id}`.
963991
When specified, `sources` and `env` must be empty.
992+
:param mode: The compute lifecycle mode for an environment.
964993
:param network: Network configuration for the environment.
965994
:param sources: Sources to be mounted into the environment.
995+
:param system_instruction: Optional. System instruction applied to interactions running in this
996+
environment. Only supported for `SELF_HOSTED` environments, where it is
997+
recommended.
966998
:param extra_headers: Additional headers to set or replace on requests.
967999
:param extra_query: Additional query parameters to append to requests.
9681000
:param extra_body: Additional JSON object fields to merge into request bodies.
@@ -985,13 +1017,16 @@ async def create_environment(
9851017
request = models.CreateEnvironmentRequest(
9861018
api_version=api_version,
9871019
body=environments.CreateEnvironmentRequest(
1020+
custom_config=utils.unmarshal(custom_config, Optional[Dict[str, Any]]),
9881021
from_environment=from_environment,
1022+
mode=mode,
9891023
network=utils.get_pydantic_model(
9901024
network, Optional[environments.CreateEnvironmentRequestNetworkUnion]
9911025
),
9921026
sources=utils.get_pydantic_model(
9931027
sources, Optional[List[interactions.Source]]
9941028
),
1029+
system_instruction=system_instruction,
9951030
),
9961031
)
9971032

‎google/genai/_gaos/models/listenvironments.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
current_filtered_dump,
2525
current_serialization_methods_dump,
2626
)
27+
from ..types.interactions import environmentmode as interactions_environmentmode
2728
from ..utils import FieldMetadata, PathParamMetadata, QueryParamMetadata
2829
from pydantic import model_serializer
2930
from typing import Optional
@@ -79,6 +80,8 @@ def serialize_model(self, handler):
7980
class ListEnvironmentsRequestParam(TypedDict):
8081
api_version: NotRequired[str]
8182
r"""API version for request routing."""
83+
mode: NotRequired[interactions_environmentmode.EnvironmentMode]
84+
r"""Optional. Filter environments by compute lifecycle mode."""
8285
page_size: NotRequired[int]
8386
r"""Optional. Maximum number of environments to return.
8487
If unspecified, defaults to 50. Maximum is 1000.
@@ -94,6 +97,12 @@ class ListEnvironmentsRequest(BaseModel):
9497
] = None
9598
r"""API version for request routing."""
9699

100+
mode: Annotated[
101+
Optional[interactions_environmentmode.EnvironmentMode],
102+
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
103+
] = None
104+
r"""Optional. Filter environments by compute lifecycle mode."""
105+
97106
page_size: Annotated[
98107
Optional[int],
99108
FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
@@ -113,7 +122,7 @@ def _serialize_model_with_info(self, handler, info):
113122
return serialize_with_info(self.serialize_model, handler, info)
114123

115124
def serialize_model(self, handler):
116-
optional_fields = set(["api_version", "page_size", "page_token"])
125+
optional_fields = set(["api_version", "mode", "page_size", "page_token"])
117126
exclude_none = current_exclude_none()
118127
by_alias = current_by_alias()
119128
use_field_names = by_alias is False

‎google/genai/_gaos/resources/environments/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
)
2626
from ...types.environments.listenvironmentsresponse import ListEnvironmentsResponse
2727
from ...types.interactions.empty import Empty as EnvironmentDeleteResponse
28+
from ...types.interactions.environmentmode import EnvironmentMode
2829

2930
EnvironmentListResponse = ListEnvironmentsResponse
3031
__all__ = [
@@ -33,6 +34,7 @@
3334
"EnvironmentDeleteResponse",
3435
"EnvironmentFile",
3536
"EnvironmentListResponse",
37+
"EnvironmentMode",
3638
"GetEnvironmentFilesResponse",
3739
"ListEnvironmentsResponse",
3840
]

‎google/genai/_gaos/resources/interactions/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
from ...types.interactions.dynamicagentconfig import DynamicAgentConfig
5151
from ...types.interactions.empty import Empty as InteractionDeleteResponse
5252
from ...types.interactions.environment import Environment
53+
from ...types.interactions.environmentmode import EnvironmentMode
5354
from ...types.interactions.error import Error
5455
from ...types.interactions.errorevent import ErrorEvent
5556
from ...types.interactions.filecitation import FileCitation
@@ -156,6 +157,7 @@
156157
"DocumentContent",
157158
"DynamicAgentConfig",
158159
"Environment",
160+
"EnvironmentMode",
159161
"Error",
160162
"ErrorEvent",
161163
"FileCitation",

‎google/genai/_gaos/types/environments/createenvironmentrequest.py‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525
current_serialization_methods_dump,
2626
)
2727
from ..interactions import (
28+
environmentmode as interactions_environmentmode,
2829
environmentnetworkegressallowlist as interactions_environmentnetworkegressallowlist,
2930
source as interactions_source,
3031
)
3132
from pydantic import model_serializer
32-
from typing import List, Literal, Optional, Union
33+
from typing import Any, Dict, List, Literal, Optional, Union
3334
from typing_extensions import NotRequired, TypeAliasType, TypedDict
3435

3536

@@ -59,38 +60,74 @@
5960
class CreateEnvironmentRequestParam(TypedDict):
6061
r"""Request for `CreateEnvironment`."""
6162

63+
custom_config: NotRequired[Dict[str, Any]]
64+
r"""Optional. Arbitrary customer-defined JSON configuration passed through
65+
to the self-hosted environment poller. Only supported when `mode` is
66+
`SELF_HOSTED`.
67+
"""
6268
from_environment: NotRequired[str]
6369
r"""Optional. The source environment to copy/fork from.
6470
Format: `environments/{environment_id}` or `{environment_id}`.
6571
When specified, `sources` and `env` must be empty.
6672
"""
73+
mode: NotRequired[interactions_environmentmode.EnvironmentMode]
74+
r"""The compute lifecycle mode for an environment."""
6775
network: NotRequired[CreateEnvironmentRequestNetworkUnionParam]
6876
r"""Network configuration for the environment."""
6977
sources: NotRequired[List[interactions_source.SourceParam]]
7078
r"""Sources to be mounted into the environment."""
79+
system_instruction: NotRequired[str]
80+
r"""Optional. System instruction applied to interactions running in this
81+
environment. Only supported for `SELF_HOSTED` environments, where it is
82+
recommended.
83+
"""
7184

7285

7386
class CreateEnvironmentRequest(BaseModel):
7487
r"""Request for `CreateEnvironment`."""
7588

89+
custom_config: Optional[Dict[str, Any]] = None
90+
r"""Optional. Arbitrary customer-defined JSON configuration passed through
91+
to the self-hosted environment poller. Only supported when `mode` is
92+
`SELF_HOSTED`.
93+
"""
94+
7695
from_environment: Optional[str] = None
7796
r"""Optional. The source environment to copy/fork from.
7897
Format: `environments/{environment_id}` or `{environment_id}`.
7998
When specified, `sources` and `env` must be empty.
8099
"""
81100

101+
mode: Optional[interactions_environmentmode.EnvironmentMode] = None
102+
r"""The compute lifecycle mode for an environment."""
103+
82104
network: Optional[CreateEnvironmentRequestNetworkUnion] = None
83105
r"""Network configuration for the environment."""
84106

85107
sources: Optional[List[interactions_source.Source]] = None
86108
r"""Sources to be mounted into the environment."""
87109

110+
system_instruction: Optional[str] = None
111+
r"""Optional. System instruction applied to interactions running in this
112+
environment. Only supported for `SELF_HOSTED` environments, where it is
113+
recommended.
114+
"""
115+
88116
@model_serializer(mode="wrap")
89117
def _serialize_model_with_info(self, handler, info):
90118
return serialize_with_info(self.serialize_model, handler, info)
91119

92120
def serialize_model(self, handler):
93-
optional_fields = set(["from_environment", "network", "sources"])
121+
optional_fields = set(
122+
[
123+
"custom_config",
124+
"from_environment",
125+
"mode",
126+
"network",
127+
"sources",
128+
"system_instruction",
129+
]
130+
)
94131
exclude_none = current_exclude_none()
95132
by_alias = current_by_alias()
96133
use_field_names = by_alias is False

0 commit comments

Comments
 (0)