Skip to content

Commit 6419a2a

Browse files
yeesiancopybara-github
authored andcommitted
fix: Switch from agent_engine_name to agent_engine_id for updating instances
PiperOrigin-RevId: 787179405
1 parent b83b0a6 commit 6419a2a

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/google/adk/cli/cli_deploy.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ def to_agent_engine(
253253
temp_folder: str,
254254
adk_app: str,
255255
staging_bucket: str,
256-
agent_engine_name: str,
257256
trace_to_cloud: bool,
257+
agent_engine_id: Optional[str] = None,
258258
absolutize_imports: bool = True,
259259
project: Optional[str] = None,
260260
region: Optional[str] = None,
@@ -294,9 +294,9 @@ def to_agent_engine(
294294
project (str): Google Cloud project id.
295295
region (str): Google Cloud region.
296296
staging_bucket (str): The GCS bucket for staging the deployment artifacts.
297-
agent_engine_name (str): The name of the Agent Engine instance to update if
298-
it exists. Format: `projects/{project}/locations/{location}/reasoningEngines/{resource_id}`.
299297
trace_to_cloud (bool): Whether to enable Cloud Trace.
298+
agent_engine_id (str): The ID of the Agent Engine instance to update. If not
299+
specified, a new Agent Engine instance will be created.
300300
absolutize_imports (bool): Whether to absolutize imports. If True, all relative
301301
imports will be converted to absolute import statements. Default is True.
302302
requirements_file (str): The filepath to the `requirements.txt` file to use.
@@ -407,7 +407,7 @@ def to_agent_engine(
407407

408408
click.echo('Deploying to agent engine...')
409409
agent_engine = agent_engines.ModuleAgent(
410-
module_name='agent_engine_app',
410+
module_name=adk_app,
411411
agent_name='adk_app',
412412
register_operations={
413413
'': [
@@ -425,7 +425,7 @@ def to_agent_engine(
425425
'async_stream': ['async_stream_query'],
426426
'stream': ['stream_query', 'streaming_agent_run_with_events'],
427427
},
428-
sys_paths=[temp_folder],
428+
sys_paths=[temp_folder[1:]],
429429
)
430430
agent_config = dict(
431431
agent_engine=agent_engine,
@@ -436,10 +436,11 @@ def to_agent_engine(
436436
extra_packages=[temp_folder],
437437
)
438438

439-
if not agent_engine_name:
439+
if not agent_engine_id:
440440
agent_engines.create(**agent_config)
441441
else:
442-
agent_engines.update(resource_name=agent_engine_name, **agent_config)
442+
name = f'projects/{project}/locations/{region}/reasoningEngines/{agent_engine_id}'
443+
agent_engines.update(resource_name=name, **agent_config)
443444
finally:
444445
click.echo(f'Cleaning up the temp folder: {temp_folder}')
445446
shutil.rmtree(temp_folder)

src/google/adk/cli/cli_tools_click.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -947,14 +947,14 @@ def cli_deploy_cloud_run(
947947
help="Required. GCS bucket for staging the deployment artifacts.",
948948
)
949949
@click.option(
950-
"--agent_engine_name",
950+
"--agent_engine_id",
951951
type=str,
952952
default=None,
953953
help=(
954-
"Optional. Name of the Agent Engine instance to update if it exists"
954+
"Optional. ID of the Agent Engine instance to update if it exists"
955955
" (default: None, which means a new instance will be created)."
956-
" Format:"
957-
" `projects/{project}/locations/{location}/reasoningEngines/{resource_id}`."
956+
" The corresponding resource name in Agent Engine will be:"
957+
" `projects/{project}/locations/{region}/reasoningEngines/{agent_engine_id}`."
958958
),
959959
)
960960
@click.option(
@@ -1042,7 +1042,7 @@ def cli_deploy_agent_engine(
10421042
project: str,
10431043
region: str,
10441044
staging_bucket: str,
1045-
agent_engine_name: Optional[str],
1045+
agent_engine_id: Optional[str],
10461046
trace_to_cloud: bool,
10471047
display_name: str,
10481048
description: str,
@@ -1065,7 +1065,7 @@ def cli_deploy_agent_engine(
10651065
project=project,
10661066
region=region,
10671067
staging_bucket=staging_bucket,
1068-
agent_engine_name=agent_engine_name,
1068+
agent_engine_id=agent_engine_id,
10691069
trace_to_cloud=trace_to_cloud,
10701070
display_name=display_name,
10711071
description=description,

tests/unittests/cli/utils/test_cli_deploy.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,6 @@ def test_to_agent_engine_happy_path(
454454
temp_folder=str(temp_folder),
455455
adk_app="my_adk_app",
456456
staging_bucket="gs://my-staging-bucket",
457-
agent_engine_name="",
458457
trace_to_cloud=True,
459458
project="my-gcp-project",
460459
region="us-central1",

0 commit comments

Comments
 (0)