Skip to content

Commit 38a30a4

Browse files
yeesiancopybara-github
authored andcommitted
fix: Handle overriding of requirements when deploying to agent engine
Co-authored-by: Yeesian Ng <ysian@google.com> PiperOrigin-RevId: 850423017
1 parent 26e77e1 commit 38a30a4

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/google/adk/cli/cli_deploy.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -771,25 +771,27 @@ def to_agent_engine(
771771
)
772772
agent_config['description'] = description
773773

774-
if not requirements_file:
774+
requirements_txt_path = os.path.join(agent_src_path, 'requirements.txt')
775+
if requirements_file:
776+
if os.path.exists(requirements_txt_path):
777+
click.echo(
778+
f'Overwriting {requirements_txt_path} with {requirements_file}'
779+
)
780+
shutil.copyfile(requirements_file, requirements_txt_path)
781+
elif 'requirements_file' in agent_config:
782+
if os.path.exists(requirements_txt_path):
783+
click.echo(
784+
f'Overwriting {requirements_txt_path} with'
785+
f' {agent_config["requirements_file"]}'
786+
)
787+
shutil.copyfile(agent_config['requirements_file'], requirements_txt_path)
788+
else:
775789
# Attempt to read requirements from requirements.txt in the dir (if any).
776-
requirements_txt_path = os.path.join(agent_src_path, 'requirements.txt')
777790
if not os.path.exists(requirements_txt_path):
778791
click.echo(f'Creating {requirements_txt_path}...')
779792
with open(requirements_txt_path, 'w', encoding='utf-8') as f:
780793
f.write('google-cloud-aiplatform[adk,agent_engines]')
781794
click.echo(f'Created {requirements_txt_path}')
782-
agent_config['requirements_file'] = agent_config.get(
783-
'requirements',
784-
requirements_txt_path,
785-
)
786-
else:
787-
if 'requirements_file' in agent_config:
788-
click.echo(
789-
'Overriding requirements in agent engine config with '
790-
f'{requirements_file}'
791-
)
792-
agent_config['requirements_file'] = requirements_file
793795
agent_config['requirements_file'] = f'{temp_folder}/requirements.txt'
794796

795797
env_vars = {}

0 commit comments

Comments
 (0)