|
60 | 60 | """ |
61 | 61 |
|
62 | 62 | _AGENT_ENGINE_APP_TEMPLATE = """ |
63 | | -from {app_name}.agent import root_agent |
64 | 63 | from vertexai.preview.reasoning_engines import AdkApp |
65 | 64 |
|
| 65 | +if {is_config_agent}: |
| 66 | + from google.adk.agents import config_agent_utils |
| 67 | + try: |
| 68 | + # This path is for local loading. |
| 69 | + root_agent = config_agent_utils.from_config("{agent_folder}/root_agent.yaml") |
| 70 | + except FileNotFoundError: |
| 71 | + # This path is used to support the file structure in Agent Engine. |
| 72 | + root_agent = config_agent_utils.from_config("./{temp_folder}/{app_name}/root_agent.yaml") |
| 73 | +else: |
| 74 | + from {app_name}.agent import root_agent |
| 75 | +
|
66 | 76 | adk_app = AdkApp( |
67 | 77 | agent=root_agent, |
68 | 78 | enable_tracing={trace_to_cloud_option}, |
@@ -293,21 +303,26 @@ def to_agent_engine( |
293 | 303 | code. |
294 | 304 | temp_folder (str): The temp folder for the generated Agent Engine source |
295 | 305 | files. It will be replaced with the generated files if it already exists. |
296 | | - project (str): Google Cloud project id. |
297 | | - region (str): Google Cloud region. |
| 306 | + adk_app (str): The name of the file (without .py) containing the AdkApp |
| 307 | + instance. |
298 | 308 | staging_bucket (str): The GCS bucket for staging the deployment artifacts. |
299 | 309 | trace_to_cloud (bool): Whether to enable Cloud Trace. |
300 | | - agent_engine_id (str): The ID of the Agent Engine instance to update. If not |
301 | | - specified, a new Agent Engine instance will be created. |
302 | | - absolutize_imports (bool): Whether to absolutize imports. If True, all relative |
303 | | - imports will be converted to absolute import statements. Default is True. |
304 | | - requirements_file (str): The filepath to the `requirements.txt` file to use. |
305 | | - If not specified, the `requirements.txt` file in the `agent_folder` will |
306 | | - be used. |
307 | | - env_file (str): The filepath to the `.env` file for environment variables. |
308 | | - If not specified, the `.env` file in the `agent_folder` will be used. The |
309 | | - values of `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` will be |
310 | | - overridden by `project` and `region` if they are specified. |
| 310 | + agent_engine_id (str): Optional. The ID of the Agent Engine instance to |
| 311 | + update. If not specified, a new Agent Engine instance will be created. |
| 312 | + absolutize_imports (bool): Optional. Default is True. Whether to absolutize |
| 313 | + imports. If True, all relative imports will be converted to absolute |
| 314 | + import statements. |
| 315 | + project (str): Optional. Google Cloud project id. |
| 316 | + region (str): Optional. Google Cloud region. |
| 317 | + display_name (str): Optional. The display name of the Agent Engine. |
| 318 | + description (str): Optional. The description of the Agent Engine. |
| 319 | + requirements_file (str): Optional. The filepath to the `requirements.txt` |
| 320 | + file to use. If not specified, the `requirements.txt` file in the |
| 321 | + `agent_folder` will be used. |
| 322 | + env_file (str): Optional. The filepath to the `.env` file for environment |
| 323 | + variables. If not specified, the `.env` file in the `agent_folder` will be |
| 324 | + used. The values of `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` |
| 325 | + will be overridden by `project` and `region` if they are specified. |
311 | 326 | """ |
312 | 327 | app_name = os.path.basename(agent_folder) |
313 | 328 | agent_src_path = os.path.join(temp_folder, app_name) |
@@ -388,12 +403,21 @@ def to_agent_engine( |
388 | 403 | ) |
389 | 404 | click.echo('Vertex AI initialized.') |
390 | 405 |
|
| 406 | + is_config_agent = False |
| 407 | + config_root_agent_file = os.path.join(agent_src_path, 'root_agent.yaml') |
| 408 | + if os.path.exists(config_root_agent_file): |
| 409 | + click.echo('Config agent detected.') |
| 410 | + is_config_agent = True |
| 411 | + |
391 | 412 | adk_app_file = os.path.join(temp_folder, f'{adk_app}.py') |
392 | 413 | with open(adk_app_file, 'w', encoding='utf-8') as f: |
393 | 414 | f.write( |
394 | 415 | _AGENT_ENGINE_APP_TEMPLATE.format( |
395 | 416 | app_name=app_name, |
396 | 417 | trace_to_cloud_option=trace_to_cloud, |
| 418 | + is_config_agent=is_config_agent, |
| 419 | + temp_folder=temp_folder, |
| 420 | + agent_folder=agent_folder, |
397 | 421 | ) |
398 | 422 | ) |
399 | 423 | click.echo(f'Created {adk_app_file}') |
@@ -449,8 +473,8 @@ def to_agent_engine( |
449 | 473 | if not agent_engine_id: |
450 | 474 | agent_engines.create(**agent_config) |
451 | 475 | else: |
452 | | - name = f'projects/{project}/locations/{region}/reasoningEngines/{agent_engine_id}' |
453 | | - agent_engines.update(resource_name=name, **agent_config) |
| 476 | + resource_name = f'projects/{project}/locations/{region}/reasoningEngines/{agent_engine_id}' |
| 477 | + agent_engines.update(resource_name=resource_name, **agent_config) |
454 | 478 | finally: |
455 | 479 | click.echo(f'Cleaning up the temp folder: {temp_folder}') |
456 | 480 | shutil.rmtree(temp_folder) |
@@ -485,7 +509,10 @@ def to_gke( |
485 | 509 | cluster_name: The name of the GKE cluster. |
486 | 510 | service_name: The service name in GKE. |
487 | 511 | app_name: The name of the app, by default, it's basename of `agent_folder`. |
488 | | - temp_folder: The local directory to use as a temporary workspace for preparing deployment artifacts. The tool populates this folder with a copy of the agent's source code and auto-generates necessary files like a Dockerfile and deployment.yaml. |
| 512 | + temp_folder: The local directory to use as a temporary workspace for |
| 513 | + preparing deployment artifacts. The tool populates this folder with a copy |
| 514 | + of the agent's source code and auto-generates necessary files like a |
| 515 | + Dockerfile and deployment.yaml. |
489 | 516 | port: The port of the ADK api server. |
490 | 517 | trace_to_cloud: Whether to enable Cloud Trace. |
491 | 518 | with_ui: Whether to deploy with UI. |
|
0 commit comments