Repository navigation
Description
Required Information
Describe the Bug:
When the agent folder has no .env, adk deploy agent_engine --otel_to_cloud replaces the env_vars from .agent_engine_config.json (or the file passed to --agent_engine_config_file) with the two variables the flag adds. The instance boots without the user's variables.
to_agent_engine writes GOOGLE_CLOUD_AGENT_ENGINE_ENABLE_TELEMETRY and ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS into the dict it read from .env (cli_deploy.py#L1862-L1871). With no .env, that dict holds only those two variables. It is not empty, so the next block (#L1882-L1890) treats it as .env content and overwrites agent_config['env_vars'] with it.
Steps to Reproduce:
pip install google-adk==2.13.0- Save the script under Minimal Reproduction Code as
repro.py. It stubs the Agent Platform client, so it needs no GCP project and creates nothing. python repro.py
The script calls to_agent_engine with a config of {"env_vars": {"MY_SETTING": "keep-me"}}, no .env, and otel_to_cloud=True, which is what adk deploy agent_engine --project=my-project --region=us-central1 --otel_to_cloud my_agent passes for that folder.
Expected Behavior:
The flag adds its two variables to the config's env_vars, as it already does for variables read from .env:
{'MY_SETTING': 'keep-me', 'GOOGLE_CLOUD_AGENT_ENGINE_ENABLE_TELEMETRY': 'true', 'ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS': 'false'}
An ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS the user set in the config is kept.
Observed Behavior:
Overriding env_vars in agent platform config with ['ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS', 'GOOGLE_CLOUD_AGENT_ENGINE_ENABLE_TELEMETRY']
google-adk 2.13.0 -> {'GOOGLE_CLOUD_AGENT_ENGINE_ENABLE_TELEMETRY': 'true', 'ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS': 'false'}
MY_SETTING is gone. A config that sets "ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS": "true" is deployed with false.
Environment Details:
- ADK Library Version (pip show google-adk): 2.13.0 (latest on PyPI, released 2026-10-23); also 2.9.2, 2.11.0 and main at 3565ad3 (2026-11-02)
- Desktop OS: macOS
- Python Version (python -V): 3.11.14
Model Information:
- Are you using LiteLLM: N/A (deploy CLI)
- Which model is being used: N/A
Optional Information
Regression:
No. It has behaved this way since --otel_to_cloud was added to adk deploy agent_engine in 1.23.0 (21f63f6).
Additional Context:
We keep a config directory path in env_vars, so our deploy script refuses --otel_to_cloud until this is fixed.
--api_key has the same shape (#L1848-L1857): with no .env, the two variables it adds also replace the config's env_vars. I kept this report to --otel_to_cloud.
I have a fix with tests and will open a PR. It settles which env_vars get deployed first, with .env still winning over the config file, and then adds the telemetry variables to that map.
Minimal Reproduction Code:
import json
import pathlib
import sys
import tempfile
import types
import google.adk
deployed = {}
class _Runtimes:
def create(self, **kwargs):
return types.SimpleNamespace(
api_resource=types.SimpleNamespace(
name='projects/p/locations/us-central1/reasoningEngines/1'
)
)
def update(self, *, name, config):
deployed.update(config)
def delete(self, *, name):
pass
# Stub the Agent Platform client so nothing is created in GCP. ADK 2.12+
# imports `agentplatform` and calls `client.runtimes`; older releases import
# `vertexai` and call `client.agent_engines`.
def _client(*args, **kwargs):
return types.SimpleNamespace(runtimes=_Runtimes(), agent_engines=_Runtimes())
for name in ('agentplatform', 'vertexai'):
stub = types.ModuleType(name)
stub.Client = _client
sys.modules[name] = stub
from google.adk.cli import cli_deploy
agent = pathlib.Path(tempfile.mkdtemp()) / 'my_agent'
agent.mkdir()
(agent / 'agent.py').write_text('root_agent = None\n')
(agent / '.agent_engine_config.json').write_text(
json.dumps({'env_vars': {'MY_SETTING': 'keep-me'}})
)
cli_deploy.to_agent_engine(
agent_folder=str(agent),
project='my-project',
region='us-central1',
otel_to_cloud=True,
)
print('google-adk', google.adk.__version__, '->', deployed['env_vars'])How often has this issue occurred?:
- Always (100%), whenever the config sets
env_vars, the folder has no.envand--otel_to_cloudis passed.
Activity