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
1 change: 0 additions & 1 deletion contributing/samples/gepa/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
from tau_bench.types import EnvRunResult
from tau_bench.types import RunConfig
import tau_bench_agent as tau_bench_agent_lib

import utils


Expand Down
1 change: 0 additions & 1 deletion contributing/samples/gepa/run_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from absl import flags
import experiment
from google.genai import types

import utils

_OUTPUT_DIR = flags.DEFINE_string(
Expand Down
17 changes: 17 additions & 0 deletions src/google/adk/cli/cli_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,7 @@ def to_agent_engine(
useful when the local environment does not have the same dependencies as
the deployment environment.
"""
ADK_APP_OBJECT_NAME = 'adk_app'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better code organization and adherence to Python conventions (like PEP 8), constants should be defined at the module level rather than inside a function. Please consider moving ADK_APP_OBJECT_NAME to the top of the file with other module-level constants like _AGENT_ENGINE_REQUIREMENT.

app_name = os.path.basename(agent_folder)
display_name = display_name or app_name
parent_folder = os.path.dirname(agent_folder)
Expand Down Expand Up @@ -1075,6 +1076,22 @@ def to_agent_engine(
return
click.echo('Vertex AI initialized.')

click.echo(f'Using adk_app: {adk_app}')

if not os.path.exists(os.path.join(agent_src_path, f'{adk_app}.py')):
adk_app_file = os.path.join(temp_folder, f'{adk_app}.py')
with open(adk_app_file, 'w', encoding='utf-8') as f:
f.write(
_AGENT_ENGINE_APP_TEMPLATE.format(
app_name=app_name,
trace_to_cloud_option=trace_to_cloud,
)
)
click.echo(f'Created {adk_app_file}')
else:
shutil.copy(os.path.join(agent_src_path, f'{adk_app}.py'), temp_folder)
click.echo(f'Using existing {adk_app}.py')
Comment on lines +1081 to +1093
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This block introduces two critical issues:

  1. Bug: The if block starting at line 1081 will raise a KeyError. The _AGENT_ENGINE_APP_TEMPLATE.format(...) call is missing several required keys (e.g., is_config_agent, adk_app_object, express_mode).
  2. Redundancy: The file created or copied by this block is unconditionally overwritten by the code at lines 1117-1129, which also creates a file named {adk_app}.py. This makes the logic here ineffective.

To fix this, I recommend removing this entire if/else block (lines 1081-1093). The logic for handling a user-provided adk_app.py should be integrated with the file creation logic that starts at line 1106.

Here's the suggested approach:

# (Code from lines 1095-1116)
...
is_config_agent = ...
adk_app_file = os.path.join(temp_folder, f'{adk_app}.py')
user_adk_app_path = os.path.join(agent_src_path, f'{adk_app}.py')

if os.path.exists(user_adk_app_path):
    shutil.copy(user_adk_app_path, adk_app_file)
    click.echo(f'Using existing {adk_app}.py')
else:
    # This is the existing logic from lines 1107-1129
    if adk_app_object == 'root_agent':
        adk_app_type = 'agent'
    # ... (rest of the logic to generate the file)
    with open(adk_app_file, 'w', encoding='utf-8') as f:
        f.write(
            _AGENT_ENGINE_APP_TEMPLATE.format(...)
        )
    click.echo(f'Created {adk_app_file}')

This ensures the user's file is used if it exists, and a new one is correctly generated otherwise, without any errors or redundant operations.


is_config_agent = False
config_root_agent_file = os.path.join(agent_src_path, 'root_agent.yaml')
if os.path.exists(config_root_agent_file):
Expand Down
4 changes: 2 additions & 2 deletions src/google/adk/cli/cli_tools_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -1865,8 +1865,8 @@ def cli_migrate_session(
type=str,
default="agent_engine_app",
help=(
"Optional. Python file for defining the ADK application"
" (default: a file named agent_engine_app.py)"
"Optional. The module name (without .py) for the Python file defining"
" the ADK Application (default: 'agent_engine_app')."
),
)
@click.option(
Expand Down
Loading