-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
🔴 Required Information
Describe the Bug:
When running adk web with --session_service_uri agentengine://<id> (short-form ID), _load_gcp_config() loads .env using envs.load_dotenv_for_agent("", agents_dir).
If agents_dir is the CLI working directory (default), .env in the actual agent directory is not found, so GOOGLE_CLOUD_PROJECT/LOCATION are missing and Agent Engine config fails.
adk-python/src/google/adk/cli/service_registry.py
Lines 324 to 341 in 7cf1e44
| def _load_gcp_config( | |
| agents_dir: Optional[str], service_name: str | |
| ) -> tuple[str, str]: | |
| """Loads GCP project and location from environment.""" | |
| if not agents_dir: | |
| raise ValueError(f"agents_dir must be provided for {service_name}") | |
| from .utils import envs | |
| envs.load_dotenv_for_agent("", agents_dir) | |
| project = os.environ.get("GOOGLE_CLOUD_PROJECT") | |
| location = os.environ.get("GOOGLE_CLOUD_LOCATION") | |
| if not project or not location: | |
| raise ValueError("GOOGLE_CLOUD_PROJECT or GOOGLE_CLOUD_LOCATION not set.") | |
| return project, location |
Steps to Reproduce:
- Clone this repository
cd contributing/samples- Write
hello_world/.env
GOOGLE_GENAI_USE_VERTEXAI=true
GOOGLE_CLOUD_PROJECT=my-project
GOOGLE_CLOUD_LOCATION=global
4.adk web --session_service_uri agentengine://67... raises ValueError: GOOGLE_CLOUD_PROJECT or GOOGLE_CLOUD_LOCATION not set.
Expected Behavior:
For short-form Agent Engine IDs, the config should be resolved from the agent directory’s .env (or otherwise from the agent that is being loaded), not just from the server’s cwd.
Observed Behavior:
.env is not found because load_dotenv_for_agent("", agents_dir) starts from the agents_dir (cwd (e.g. adk-python/contributing/samples/)) and walks upward, not downward into agent subdirectories. _load_gcp_config() raises:
ValueError: GOOGLE_CLOUD_PROJECT or GOOGLE_CLOUD_LOCATION not set.
Workaround:
GOOGLE_CLOUD_PROJECT=... GOOGLE_CLOUD_LOCATION=... adk web --session_service_uri agentengine://67...- OR
adk web --session_service_uri agentengine://<full resource name>
Environment Details:
- ADK Library Version (pip show google-adk): 1.23.0
- Desktop OS: macOS
- Python Version (python -V): 3.13.8
Model Information:
- Are you using LiteLLM: No
- Which model is being used: (this is not related with model)
🟡 Optional Information
Providing this information greatly speeds up the resolution process.
Regression:
Did this work in a previous version of ADK? If so, which one?
Logs:
2026-01-31 13:05:11,106 - INFO - service_factory.py:266 - Using in-memory memory service
2026-01-31 13:05:11,107 - INFO - service_factory.py:189 - Using session service URI: agentengine://67...
2026-01-31 13:05:11,107 - INFO - envs.py:90 - No .env file found for
Traceback (most recent call last):
File "/.../adk-python/.venv/bin/adk", line 10, in <module>
sys.exit(main())
~~~~^^
File "/.../adk-python/.venv/lib/python3.13/site-packages/click/core.py", line 1485, in __call__
return self.main(*args, **kwargs)
~~~~~~~~~^^^^^^^^^^^^^^^^^
File "/.../adk-python/.venv/lib/python3.13/site-packages/click/core.py", line 1406, in main
rv = self.invoke(ctx)
File "/.../adk-python/.venv/lib/python3.13/site-packages/click/core.py", line 1873, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
File "/.../adk-python/.venv/lib/python3.13/site-packages/click/core.py", line 1269, in invoke
return ctx.invoke(self.callback, **ctx.params)
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.../adk-python/.venv/lib/python3.13/site-packages/click/core.py", line 824, in invoke
return callback(*args, **kwargs)
File "/.../adk-python/src/google/adk/cli/cli_tools_click.py", line 126, in wrapper
return func(*args, **kwargs)
File "/.../adk-python/.venv/lib/python3.13/site-packages/click/decorators.py", line 34, in new_func
return f(get_current_context(), *args, **kwargs)
File "/.../adk-python/src/google/adk/cli/cli_tools_click.py", line 1257, in wrapper
return func(*args, **kwargs)
File "/.../adk-python/src/google/adk/cli/cli_tools_click.py", line 1081, in wrapper
return func(*args, **kwargs)
File "/.../adk-python/src/google/adk/cli/cli_tools_click.py", line 528, in wrapper
return func(*args, **kwargs)
File "/.../adk-python/src/google/adk/cli/cli_tools_click.py", line 1131, in wrapper
return func(*args, **kwargs)
File "/.../adk-python/src/google/adk/cli/cli_tools_click.py", line 1335, in cli_web
app = get_fast_api_app(
agents_dir=agents_dir,
...<17 lines>...
logo_image_url=logo_image_url,
)
File "/.../adk-python/src/google/adk/cli/fast_api.py", line 122, in get_fast_api_app
session_service = create_session_service_from_options(
base_dir=agents_dir,
...<2 lines>...
use_local_storage=use_local_storage,
)
File "/.../adk-python/src/google/adk/cli/utils/service_factory.py", line 193, in create_session_service_from_options
service = registry.create_session_service(session_service_uri, **kwargs)
File "/.../adk-python/src/google/adk/cli/service_registry.py", line 132, in create_session_service
return self._session_factories[scheme](uri, **kwargs)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
File "/.../adk-python/src/google/adk/cli/service_registry.py", line 231, in agentengine_session_factory
params = _parse_agent_engine_kwargs(
parsed.netloc + parsed.path, kwargs.get("agents_dir")
)
File "/.../adk-python/src/google/adk/cli/service_registry.py", line 355, in _parse_agent_engine_kwargs
project, location = _load_gcp_config(
~~~~~~~~~~~~~~~~^
agents_dir, "short-form agent engine IDs"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/.../adk-python/src/google/adk/cli/service_registry.py", line 339, in _load_gcp_config
raise ValueError("GOOGLE_CLOUD_PROJECT or GOOGLE_CLOUD_LOCATION not set.")
ValueError: GOOGLE_CLOUD_PROJECT or GOOGLE_CLOUD_LOCATION not set.
How often has this issue occurred?:
- Always (100%)