-
Notifications
You must be signed in to change notification settings - Fork 3k
fix: Update adk_app handling to use custom module without .py extension #2374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
b38ad28
db822a7
93764b5
592196f
24847ab
a4e1aa2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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' | ||
| app_name = os.path.basename(agent_folder) | ||
| display_name = display_name or app_name | ||
| parent_folder = os.path.dirname(agent_folder) | ||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block introduces two critical issues:
To fix this, I recommend removing this entire 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): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_NAMEto the top of the file with other module-level constants like_AGENT_ENGINE_REQUIREMENT.