Skip to content

Commit 68221f0

Browse files
haranrkcopybara-github
authored andcommitted
feat(core): migrate core and CLI to enterprise parameters
Co-authored-by: Haran Rajkumar <haranrk@google.com> PiperOrigin-RevId: 930100568
1 parent bc08f46 commit 68221f0

12 files changed

Lines changed: 34 additions & 37 deletions

File tree

src/google/adk/cli/cli_create.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ def _generate_files(
9292
with open(dotenv_file_path, "w", encoding="utf-8") as f:
9393
lines = []
9494
if google_cloud_project and google_cloud_region:
95-
lines.append("GOOGLE_GENAI_USE_VERTEXAI=1")
95+
lines.append("GOOGLE_GENAI_USE_ENTERPRISE=1")
9696
elif google_api_key:
97-
lines.append("GOOGLE_GENAI_USE_VERTEXAI=0")
97+
lines.append("GOOGLE_GENAI_USE_ENTERPRISE=0")
9898
if google_api_key:
9999
lines.append(f"GOOGLE_API_KEY={google_api_key}")
100100
if google_cloud_project:

src/google/adk/cli/cli_deploy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def _ensure_agent_engine_dependency(requirements_txt_path: str) -> None:
7777
# Set up environment variables - Start
7878
ENV PATH="/home/myuser/.local/bin:$PATH"
7979
80-
ENV GOOGLE_GENAI_USE_VERTEXAI=1
80+
ENV GOOGLE_GENAI_USE_ENTERPRISE=1
8181
ENV GOOGLE_CLOUD_PROJECT={gcp_project_id}
8282
ENV GOOGLE_CLOUD_LOCATION={gcp_region}
8383
@@ -854,7 +854,7 @@ def to_agent_engine(
854854
Google Cloud.
855855
api_key (str): Optional. The API key to use for Express Mode. If not
856856
provided, the API key from the GOOGLE_API_KEY environment variable will be
857-
used. It will only be used if GOOGLE_GENAI_USE_VERTEXAI is true.
857+
used. It will only be used if GOOGLE_GENAI_USE_ENTERPRISE is true.
858858
adk_app_object (str): Deprecated. This argument is no longer required or
859859
used.
860860
agent_engine_id (str): Optional. The ID of the Agent Runtime instance to
@@ -1060,7 +1060,7 @@ def to_agent_engine(
10601060
fg='yellow',
10611061
)
10621062
else:
1063-
env_vars['GOOGLE_GENAI_USE_VERTEXAI'] = '1'
1063+
env_vars['GOOGLE_GENAI_USE_ENTERPRISE'] = '1'
10641064
env_vars['GOOGLE_API_KEY'] = api_key
10651065
elif not project:
10661066
if 'GOOGLE_API_KEY' in env_vars:

src/google/adk/cli/cli_tools_click.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2289,7 +2289,7 @@ def cli_migrate_session(
22892289
help=(
22902290
"Optional. The API key to use for Express Mode. If not"
22912291
" provided, the API key from the GOOGLE_API_KEY environment variable"
2292-
" will be used. It will only be used if GOOGLE_GENAI_USE_VERTEXAI is"
2292+
" will be used. It will only be used if GOOGLE_GENAI_USE_ENTERPRISE is"
22932293
" true. (It will override GOOGLE_API_KEY in the .env file if it"
22942294
" exists.)"
22952295
),

src/google/adk/memory/vertex_ai_memory_bank_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def __init__(
194194
``agent_engine.api_resource.name.split('/')[-1]``
195195
express_mode_api_key: The API key to use for Express Mode. If not
196196
provided, the API key from the GOOGLE_API_KEY environment variable will
197-
be used. It will only be used if GOOGLE_GENAI_USE_VERTEXAI is true. Do
197+
be used. It will only be used if GOOGLE_GENAI_USE_ENTERPRISE is true. Do
198198
not use Google AI Studio API key for this field. For more details, visit
199199
https://cloud.google.com/vertex-ai/generative-ai/docs/start/express-mode/overview
200200
"""

src/google/adk/models/apigee_llm.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import tenacity
3636
from typing_extensions import override
3737

38-
from ..utils.env_utils import is_env_enabled
38+
from ..utils.env_utils import is_enterprise_mode_enabled
3939
from .google_llm import Gemini
4040
from .llm_response import LlmResponse
4141

@@ -49,7 +49,6 @@
4949
logger = logging.getLogger('google_adk.' + __name__)
5050

5151
_APIGEE_PROXY_URL_ENV_VARIABLE_NAME = 'APIGEE_PROXY_URL'
52-
_GOOGLE_GENAI_USE_VERTEXAI_ENV_VARIABLE_NAME = 'GOOGLE_GENAI_USE_VERTEXAI'
5352
_PROJECT_ENV_VARIABLE_NAME = 'GOOGLE_CLOUD_PROJECT'
5453
_LOCATION_ENV_VARIABLE_NAME = 'GOOGLE_CLOUD_LOCATION'
5554

@@ -104,9 +103,9 @@ def __init__(
104103
105104
Components
106105
`provider` (optional): `vertex_ai` or `gemini`. If omitted, behavior
107-
depends on the `GOOGLE_GENAI_USE_VERTEXAI` environment variable. If
106+
depends on the `GOOGLE_GENAI_USE_ENTERPRISE` environment variable. If
108107
that is not set to TRUE or 1, it defaults to `gemini`. `provider`
109-
takes precedence over `GOOGLE_GENAI_USE_VERTEXAI`.
108+
takes precedence over `GOOGLE_GENAI_USE_ENTERPRISE`.
110109
`version` (optional): The API version (e.g., `v1`, `v1beta`). If
111110
omitted, the default version for the provider is used.
112111
`model_id` (required): The model identifier (e.g.,
@@ -243,7 +242,7 @@ def api_client(self) -> Client:
243242
)
244243

245244
kwargs_for_client = {}
246-
kwargs_for_client['vertexai'] = self._isvertexai
245+
kwargs_for_client['enterprise'] = self._isvertexai
247246
if self._isvertexai:
248247
kwargs_for_client['project'] = self._project
249248
kwargs_for_client['location'] = self._location
@@ -265,8 +264,8 @@ def _identify_vertexai(model: str, api_type: ApigeeLlm.ApiType) -> bool:
265264
"""Returns if a model is Vertex AI.
266265
267266
1. The api_type is GENAI or UNKNOWN.
268-
2. The model is provider is Vertex AI model or the
269-
GOOGLE_GENAI_USE_VERTEXAI environment variable is set to TRUE or 1.
267+
2. The model provider is a Vertex AI model or the
268+
enterprise mode is enabled.
270269
271270
Args:
272271
model: The model string.
@@ -278,9 +277,7 @@ def _identify_vertexai(model: str, api_type: ApigeeLlm.ApiType) -> bool:
278277
return False
279278
if model.startswith('apigee/openai/'):
280279
return False
281-
return model.startswith('apigee/vertex_ai/') or is_env_enabled(
282-
_GOOGLE_GENAI_USE_VERTEXAI_ENV_VARIABLE_NAME
283-
)
280+
return model.startswith('apigee/vertex_ai/') or is_enterprise_mode_enabled()
284281

285282

286283
def _identify_api_version(model: str) -> str:

src/google/adk/models/google_llm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class Gemini(BaseLlm):
104104
class GlobalGemini(Gemini):
105105
@cached_property
106106
def api_client(self) -> Client:
107-
return Client(vertexai=True, location="global")
107+
return Client(enterprise=True, location="global")
108108
109109
agent = Agent(model=GlobalGemini(model="gemini-3-pro-preview"))
110110
@@ -345,7 +345,7 @@ def api_client(self) -> Client:
345345
'http_options': types.HttpOptions(**kwargs_for_http_options),
346346
}
347347
if self.model.startswith('projects/'):
348-
kwargs['vertexai'] = True
348+
kwargs['enterprise'] = True
349349

350350
return Client(**kwargs)
351351

@@ -390,7 +390,7 @@ def _live_api_client(self) -> Client:
390390
)
391391
}
392392
if self.model.startswith('projects/'):
393-
kwargs['vertexai'] = True
393+
kwargs['enterprise'] = True
394394

395395
return Client(**kwargs)
396396

src/google/adk/sessions/vertex_ai_session_service.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,8 @@ def __init__(
100100
agent_engine_id: The resource ID of the agent engine to use.
101101
express_mode_api_key: The API key to use for Express Mode. If not
102102
provided, the API key from the GOOGLE_API_KEY environment variable will
103-
be used. It will only be used if GOOGLE_GENAI_USE_VERTEXAI is true.
104-
Do not use Google AI Studio API key for this field. For more details,
105-
visit
103+
be used. It will only be used if GOOGLE_GENAI_USE_ENTERPRISE is true. Do
104+
not use Google AI Studio API key for this field. For more details, visit
106105
https://cloud.google.com/vertex-ai/generative-ai/docs/start/express-mode/overview
107106
"""
108107
try:

src/google/adk/telemetry/tracing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
from typing_extensions import deprecated
6666

6767
from .. import version
68+
from ..utils.env_utils import is_enterprise_mode_enabled
6869
from ..utils.model_name_utils import is_gemini_model
6970
from ._experimental_semconv import is_experimental_semconv
7071
from ._experimental_semconv import maybe_log_completion_details
@@ -986,6 +987,6 @@ def trace_inference_result(
986987
def _guess_gemini_system_name() -> str:
987988
return (
988989
GenAiSystemValues.VERTEX_AI.name.lower()
989-
if os.getenv('GOOGLE_GENAI_USE_VERTEXAI', '').lower() in ('true', '1')
990+
if is_enterprise_mode_enabled()
990991
else GenAiSystemValues.GEMINI.name.lower()
991992
)

src/google/adk/tools/google_maps_grounding_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class GoogleMapsGroundingTool(BaseTool):
3636
local code execution.
3737
3838
Only available for use with the VertexAI Gemini API (e.g.
39-
GOOGLE_GENAI_USE_VERTEXAI=TRUE)
39+
GOOGLE_GENAI_USE_ENTERPRISE=TRUE)
4040
"""
4141

4242
def __init__(self):

tests/unittests/cli/utils/test_cli_create.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_generate_files_with_api_key(agent_folder: Path) -> None:
6868

6969
env_content = (agent_folder / ".env").read_text()
7070
assert "GOOGLE_API_KEY=dummy-key" in env_content
71-
assert "GOOGLE_GENAI_USE_VERTEXAI=0" in env_content
71+
assert "GOOGLE_GENAI_USE_ENTERPRISE=0" in env_content
7272
assert (agent_folder / "agent.py").exists()
7373
assert (agent_folder / "__init__.py").exists()
7474

@@ -86,7 +86,7 @@ def test_generate_files_with_gcp(agent_folder: Path) -> None:
8686
env_content = (agent_folder / ".env").read_text()
8787
assert "GOOGLE_CLOUD_PROJECT=proj" in env_content
8888
assert "GOOGLE_CLOUD_LOCATION=us-central1" in env_content
89-
assert "GOOGLE_GENAI_USE_VERTEXAI=1" in env_content
89+
assert "GOOGLE_GENAI_USE_ENTERPRISE=1" in env_content
9090

9191

9292
def test_generate_files_with_express_mode(agent_folder: Path) -> None:
@@ -101,7 +101,7 @@ def test_generate_files_with_express_mode(agent_folder: Path) -> None:
101101
)
102102

103103
env_content = (agent_folder / ".env").read_text()
104-
assert "GOOGLE_GENAI_USE_VERTEXAI=1" in env_content
104+
assert "GOOGLE_GENAI_USE_ENTERPRISE=1" in env_content
105105
assert "GOOGLE_API_KEY=express-api-key" in env_content
106106
assert "GOOGLE_CLOUD_PROJECT=express-project-id" in env_content
107107

@@ -145,7 +145,7 @@ def test_generate_files_no_params(agent_folder: Path) -> None:
145145
"GOOGLE_API_KEY",
146146
"GOOGLE_CLOUD_PROJECT",
147147
"GOOGLE_CLOUD_LOCATION",
148-
"GOOGLE_GENAI_USE_VERTEXAI",
148+
"GOOGLE_GENAI_USE_ENTERPRISE",
149149
):
150150
assert key not in env_content
151151

0 commit comments

Comments
 (0)