Cannot Use Gemini 3 with Agent Engine
** Please make sure you read the contribution guide and file the issues in the right place. ** Contribution guide.
Describe the bug A clear and concise description of what the bug is.
Only Global endpoint is currently available for gemini 3, so GOOGLE_CLOUD_LOCATION needs to be set to global in order to use model (model=gemini-3-pro-preview). However, i believe GOOGLE_CLOUD_LOCATION is also used to determine the region for establishing a agent engine session. This is causing conflicts and failing as im not able to set my Gemini region to global and agent engine session to us-central1.
To Reproduce Please share a minimal code and data to reproduce your problem.
Deploy host in cloudrun and configure get_fast_api_app to use agent engine for sessions. (I used agent starter pack for deployment https://github.com/GoogleCloudPlatform/agent-starter-pack)
Steps to reproduce the behavior: session_service_uri = "agentengine://<agent_engine_id>"
app: FastAPI = get_fast_api_app( agents_dir=AGENT_DIR, web=True, artifact_service_uri=bucket_name, allow_origins=allow_origins, session_service_uri=session_service_uri, )
Set GOOGLE_CLOUD_LOCATION=global and deploy to cloudrun . Try to create a new session or run a query.
Note: This works fine setting region to global when running locally since agent engine isnt involved (adk web)
Expected behavior There should be an option to set the region used for the LLM separately from agent engine
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: [e.g. macOS, Linux, Windows] Cloud Run
- Python version(python -V): 3.13
- ADK version(pip show google-adk): 1.19
Model Information:
- Are you using LiteLLM: No
- Which model is being used(e.g. gemini-2.5-pro) : gemini-3-pro-preview
Additional context Add any other context about the problem here. I tried using litellm w/ vertex ai as a workaround but that also failed for a separate reason . created a separate issue for that here https://github.com/google/adk-python/issues/3627 . In the meantime im still looking for a way to use gemini 3 in our gcp env
Hi @lambda72453 , could you do something like this:
root_agent = LlmAgent( name='orchestrator_agent', model='projects/cloud-llm-preview1/locations/global/publishers/google/models/gemini-2.5-flash', description="""Cool dude""", tools=[], )
- @yeesian
@DeanChensj That worked for gemini-2.5-flash . But not for gemini-3-pro-preview . I got the following :
{"error": "404 NOT_FOUND. {'error': {'code': 404, 'message': 'Publisher Model projects/<my_project>/locations/global/publishers/google/models/gemini-3-pro-preview was not found or your project does not have access to it. Please ensure you are using a valid model version. For more information, see: https://cloud.google.com/vertex-ai/generative-ai/docs/learn/model-versions', 'status': 'NOT_FOUND'}}"}
In the mean time I have a work around by using an AI Studio API key
same
Same for me,
- Gemini 3 models require
GOOGLE_CLOUD_LOCATION=global(only available on global endpoint) - Agent Engine requires
GOOGLE_CLOUD_LOCATION=us-central1(or other regional deployment) - Same environment variable controls both LLM routing and Agent Engine session region
- Agent Engine reserves and overrides
GOOGLE_CLOUD_LOCATIONto deployment region
Attempted Workarounds (All Failed)
-
Full resource path format
model = "projects/PROJECT_ID/locations/global/publishers/google/models/gemini-3-pro-preview" Result: 404 NOT_FOUND - Full resource path format doesn't work for Gemini foundation models (even locally) -
Custom BaseLlm wrapper with genai.Client(location="global")
class GlobalGemini(BaseLlm):
def _get_client(self):
return genai.Client(vertexai=True, location="global")
- Result: ModuleNotFoundError during unpickling in Agent Engine (custom classes that import project modules fail)
- Environment variable override in deployment Result: Agent Engine reserves GOOGLE_CLOUD_LOCATION - cannot be overridden via env_vars parameter
✅ Works locally: GOOGLE_CLOUD_LOCATION=global model = "gemini-3-pro-preview"
❌ Fails with 404 (even locally): model = "projects/.../locations/global/.../gemini-3-pro-preview"
Conclusion: Cannot deploy agents using Gemini 3 models to Agent Engine until either:
- ADK supports separate location parameters for LLM vs Agent Engine
- Gemini 3 models are available on regional endpoints (us-central1, etc.)
I would like to suggest a workaround by subclassing the Gemini model class to override the api_client property.
The standard initialization might rely on default location logic that doesn't align with specific model availability (e.g., models requiring the global endpoint) or might miss specific HttpOptions. By explicitly instantiating google.genai.Client within a subclass, we can enforce location="global" and ensure that _tracking_headers and retry_options are correctly propagated.
Here is a sample implementation demonstrating how to inject the custom client configuration:
from functools import cached_property
import os
from google.adk.models import Gemini
from google.genai import Client, types
class Gemini3(Gemini):
@cached_property
def api_client(self) -> Client:
"""Provides the api client with explicit configuration.
Returns:
The api client initialized with specific location and http_options.
"""
# Ensure project ID is retrieved, falling back to a placeholder or raising an error if needed.
project = os.getenv("GOOGLE_CLOUD_PROJECT", "xxxxx")
# Explicitly setting location to 'global' to avoid regional endpoint resolution issues
location = "global"
return Client(
project=project,
location=location,
http_options=types.HttpOptions(
headers=self._tracking_headers,
retry_options=self.retry_options,
)
)
# Example usage within an LlmAgent
agent = LlmAgent(
name="image_generation_agent",
# Instantiate the customized model class
model=Gemini3(model="gemini-3-pro-image-preview"),
description="AI agent that generates images based on text prompts",
)
This approach provides granular control over the Client instantiation, which should resolve connectivity or configuration issues related to the underlying API client.