Description
Affected Files:
Description:
When constructing the Agent Engine session URI, the ADK fast_api.py
module incorrectly assumes that the Agent Engine's location can be reliably derived from os.environ["GOOGLE_CLOUD_LOCATION"]
. This assumption leads to issues when the default global region (often associated with Gemini, which uses GOOGLE_CLOUD_LOCATION
as a default) does not match the specific region where the Agent Engine session or memory is actually deployed.
Context:
This issue was identified during the integration of AE Managed sessions into Cloud Run ADK deployments.
Current Behavior:
The current implementation implicitly uses os.environ["GOOGLE_CLOUD_LOCATION"]
to build parts of the session_service_uri
. This forces developers to manually extract the Agent Engine's bare ID from its full resource name when trying to use it, like so:
agent_engine = agent_engines.create(display_name=agent_name)
session_service_uri = f"agentengine://{agent_engine.resource_name.split('/')[-1]}"
Expected Behavior:
ADK should allow developers to directly pass the full Agent Engine resource name (e.g., projects/PROJECT_ID/locations/LOCATION/agents/AGENT_ID
) to the session_service_uri
without relying on os.environ["GOOGLE_CLOUD_LOCATION"]
for its internal construction.
Ideally, the code should allow:
session_service_uri = f"agentengine://{agent_engine.resource_name}"
And fetch the location from the full ID
Proposed Solution:
Modify the fast_api.py
module (specifically around lines 293 and 311) to accept and utilize the full Agent Engine resource name when constructing the session_service_uri
, rather than attempting to derive parts of it from os.environ["GOOGLE_CLOUD_LOCATION"]
.