Skip to content
2 changes: 1 addition & 1 deletion python/agents/data-science/data_science/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def setup_before_agent_call(callback_context: CallbackContext):


root_agent = Agent(
model=os.getenv("ROOT_AGENT_MODEL"),
model=os.getenv("ROOT_AGENT_MODEL", "gemini-2.5-flash"),
name="db_ds_multiagent",
instruction=return_instructions_root(),
global_instruction=(
Expand Down
104 changes: 66 additions & 38 deletions python/agents/data-science/deployment/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def create(env_vars: dict[str, str]) -> None:
adk_app,
requirements=[AGENT_WHL_FILE],
extra_packages=[AGENT_WHL_FILE],
env_vars=env_vars
env_vars=env_vars,
)
logger.info("Created remote agent: %s", remote_agent.resource_name)
print(f"\nSuccessfully created agent: {remote_agent.resource_name}")
Expand All @@ -156,7 +156,6 @@ def delete(resource_id: str) -> None:
print(f"\nSuccessfully deleted agent: {resource_id}")
except google_exceptions.NotFound:
logger.error("Agent with resource ID %s not found.", resource_id)
print(f"\nAgent{resource_id} not found.")
print(f"\nAgent not found: {resource_id}")
except Exception as e:
logger.error(
Expand Down Expand Up @@ -187,56 +186,88 @@ def main(argv: list[str]) -> None: # pylint: disable=unused-argument
)
# Don't set "GOOGLE_CLOUD_PROJECT" or "GOOGLE_CLOUD_LOCATION"
# when deploying to Agent Engine. Those are set by the backend.
env_vars["ROOT_AGENT_MODEL"] = os.getenv("ROOT_AGENT_MODEL")
env_vars["ANALYTICS_AGENT_MODEL"] = os.getenv("ANALYTICS_AGENT_MODEL")
env_vars["BASELINE_NL2SQL_MODEL"] = os.getenv("BASELINE_NL2SQL_MODEL")
env_vars["BIGQUERY_AGENT_MODEL"] = os.getenv("BIGQUERY_AGENT_MODEL")
env_vars["BQML_AGENT_MODEL"] = os.getenv("BQML_AGENT_MODEL")
env_vars["CHASE_NL2SQL_MODEL"] = os.getenv("CHASE_NL2SQL_MODEL")
env_vars["BQ_DATASET_ID"] = os.getenv("BQ_DATASET_ID")
env_vars["BQ_DATA_PROJECT_ID"] = os.getenv("BQ_DATA_PROJECT_ID")
env_vars["BQ_COMPUTE_PROJECT_ID"] = os.getenv("BQ_COMPUTE_PROJECT_ID")
env_vars["BQML_RAG_CORPUS_NAME"] = os.getenv("BQML_RAG_CORPUS_NAME")
env_vars["CODE_INTERPRETER_EXTENSION_NAME"] = os.getenv(
"CODE_INTERPRETER_EXTENSION_NAME")
env_vars["NL2SQL_METHOD"] = os.getenv("NL2SQL_METHOD")
# Collect environment variables, filtering out None, empty, and whitespace-only values
env_var_keys = [
"ROOT_AGENT_MODEL",
"ANALYTICS_AGENT_MODEL",
"ROOT_AGENT_MODEL",
"ANALYTICS_AGENT_MODEL",
"BASELINE_NL2SQL_MODEL",
"BIGQUERY_AGENT_MODEL",
"BQML_AGENT_MODEL",
"CHASE_NL2SQL_MODEL",
"BQ_DATASET_ID",
"BQ_DATA_PROJECT_ID",
"BQ_COMPUTE_PROJECT_ID",
"BQML_RAG_CORPUS_NAME",
"CODE_INTERPRETER_EXTENSION_NAME",
"NL2SQL_METHOD"
]

for key in env_var_keys:
value = os.getenv(key)
# Only add to env_vars if the value has actual content (not None, empty, or whitespace-only)
if value and value.strip():
env_vars[key] = value
logger.info("Including environment variable: %s", key)
else:
logger.info("Skipping empty/None/whitespace-only environment variable: %s (value: %s)", key, repr(value))

logger.info("Environment variables to be passed to agent: %s", list(env_vars.keys()))

skipped_vars: list[str] = []
for key in env_var_keys:
value = os.getenv(key)
# Only add to env_vars if the value is not None/empty and not just
# whitespace
if value and value.strip():
env_vars[key] = value
else:
skipped_vars.append(key)

if skipped_vars:
logger.info(
"Skipped empty/None/whitespace environment variables: %s",
skipped_vars,
)

logger.info(
"Environment variables to be passed to agent: %s", list(env_vars.keys())
)
Comment on lines +205 to +234
Copy link

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

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

The environment variable processing logic is duplicated. The first loop (lines 207-214) and second loop (lines 219-226) perform identical filtering. Remove the duplication by keeping only one loop and consolidating the logging.

Copilot uses AI. Check for mistakes.


logger.info("Using PROJECT: %s", project_id)
logger.info("Using LOCATION: %s", location)
logger.info("Using BUCKET NAME: %s", bucket_name)

# --- Input Validation ---
if not project_id:
print("\nError: Missing required GCP Project ID.")
print(
"Set the GOOGLE_CLOUD_PROJECT environment variable or use --project_id flag."
raise app.UsageError(
"Missing required GCP Project ID. Set GOOGLE_CLOUD_PROJECT or "
"use --project_id flag."
)
return
if not location:
print("\nError: Missing required GCP Location.")
print(
"Set the GOOGLE_CLOUD_LOCATION environment variable or use --location flag."
raise app.UsageError(
"Missing required GCP Location. Set GOOGLE_CLOUD_LOCATION or use "
"--location flag."
)
return
if not bucket_name:
print("\nError: Missing required GCS Bucket Name.")
print(
"Set the GOOGLE_CLOUD_STORAGE_BUCKET environment variable or use --bucket flag."
raise app.UsageError(
"Missing required GCS Bucket Name. Set GOOGLE_CLOUD_STORAGE_BUCKET "
"or use --bucket flag."
)
return
if not FLAGS.create and not FLAGS.delete:
print("\nError: You must specify either --create or --delete flag.")
return
raise app.UsageError(
"You must specify either --create or --delete flag."
)
if FLAGS.delete and not FLAGS.resource_id:
print(
"\nError: --resource_id is required when using the --delete flag."
raise app.UsageError(
"--resource_id is required when using the --delete flag."
)
return
# --- End Input Validation ---

try:
# Setup staging bucket
staging_bucket_uri=None
staging_bucket_uri = None
if FLAGS.create:
staging_bucket_uri = setup_staging_bucket(
project_id, location, bucket_name
Expand All @@ -246,7 +277,7 @@ def main(argv: list[str]) -> None: # pylint: disable=unused-argument
vertexai.init(
project=project_id,
location=location,
staging_bucket=staging_bucket_uri, # Staging bucket is passed directly to create/update methods now
staging_bucket=staging_bucket_uri,
)

if FLAGS.create:
Expand All @@ -269,11 +300,8 @@ def main(argv: list[str]) -> None: # pylint: disable=unused-argument
)
except Exception as e:
print(f"\nAn unexpected error occurred: {e}")
logger.exception(
"Unhandled exception in main:"
) # Log the full traceback
logger.exception("Unhandled exception in main:")


if __name__ == "__main__":

app.run(main)