Repository navigation
Description
** 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 #3627 . In the meantime im still looking for a way to use gemini 3 in our gcp env
Activity
DeanChensj commentedon Nov 20, 2025
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=[], )DeanChensj commentedon Nov 20, 2025
lambda72453 commentedon Nov 21, 2025
@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-previewwas 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
kashirin-dm commentedon Nov 22, 2025
same
Infinnerty commentedon Nov 24, 2025
Same for me,
GOOGLE_CLOUD_LOCATION=global(only available on global endpoint)GOOGLE_CLOUD_LOCATION=us-central1(or other regional deployment)GOOGLE_CLOUD_LOCATIONto deployment regionAttempted Workarounds (All Failed)
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:
SatohJohn commentedon Dec 1, 2025
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:
This approach provides granular control over the Client instantiation, which should resolve connectivity or configuration issues related to the underlying API client.
eliasecchig commentedon Dec 17, 2025
You can also check out how it's done in goo.gle/agent-starter-pack
uvx agent-starter-pack create --adkThe issue is that the AdkApp template, when running the
set_upmethod, will override the GOOGLE_CLOUD_LOCATIONThe Fix:
You must capture the environment variable before initializing the app and manually restore it at the end of your
set_upoverride.Why this is necessary:
The parent
AdkApp.set_up()call resets the environment to match the Agent Engine's deployment region. By "caching" your intended location in a variable and re-applying it after the parent setup finishes, you ensure that both the Agent Engine and Gemini remain configured correctly.feat: add GlobalAdkApp workaround for Gemini 3 + Agent Engine
klmiller-merge commentedon Dec 31, 2025
We've implemented the fix you suggested (capturing GOOGLE_CLOUD_LOCATION before initialization and restoring it after super().set_up()), but we're still experiencing issues with Gemini 3 Flash in Agent Engine. We're hoping someone can help identify what we might be missing.
What We Implemented
Following your guidance, here's our setup:
agent_engine_app.py
from vertexai.preview.reasoning_engines import AdkApp
CRITICAL: Capture location for Gemini 3 BEFORE AdkApp initializes
AdkApp.set_up() will override this, so we need to restore it
See: #3628
_GEMINI_LOCATION = "global"
os.environ["GOOGLE_CLOUD_LOCATION"] = _GEMINI_LOCATION
class ProductResearchApp(AdkApp):
def set_up(self) -> None:
# This call will reset GOOGLE_CLOUD_LOCATION to the deployment region (us-central1)
super().set_up()
Since the environment variable fix alone wasn't sufficient, we implemented a custom Gemini3Flash model class with these techniques:
gemini3_model.py
from google.adk.models import Gemini
from google.genai import Client, types
def _get_global_client() -> Client:
"""Singleton factory that creates and protects the Gemini 3 Flash client."""
global _GLOBAL_GEMINI_CLIENT
class Gemini3Flash(Gemini):
"""Gemini 3 Flash model with explicit global location."""
Our Setup
Agent Engine Location: us-central1
Gemini 3 Flash Location: global (required)
ADK Version: google-adk==1.21.0
Deployment: Vertex AI Agent Engine (Cloud Run backend streams results)
Architecture: Multi-agent orchestrator with 4 specialist agents using Gemini 3 Flash
What's Still Failing
Despite implementing:
✅ Your environment variable capture/restore pattern
✅ Custom model class with property overrides
✅ Direct base_url override to force global endpoint
✅ Singleton client factory to prevent re-initialization
✅ Client close prevention (client.close = lambda: None)
We're still unable to reliably use Gemini 3 Flash with Agent Engine. The issue appears to be that Agent Engine's regional deployment (us-central1) continues to enforce regional endpoints even after all these workarounds.
Questions for the Community
Has anyone successfully deployed Gemini 3 Flash models to Agent Engine?
Are there additional configuration steps needed beyond the environment variable fix?
Is there a fundamental incompatibility between Gemini 3 Flash (global-only) and Agent Engine (regional deployment)?
Should we be using a different approach entirely (e.g., different model, different deployment method)?
Logs/Evidence
When the agent runs, we can see requests going to the regional endpoint instead of global, suggesting the location override isn't being respected downstream in the Agent Engine runtime.
Any guidance would be greatly appreciated! We'd love to use Gemini 3 Flash for its improved capabilities, but we may need to fall back to Gemini 2.5 Pro if there's no viable solution.
Switch to Gemini 2.5 Flash for Agent Engine compatibility
yacinebouaouni commentedon Jan 29, 2026
I found a workaround for using the global Gemini endpoint with Agent Engine in a specific a location. The idea is to go through LiteLLM with vertex_location set to global. This way you can keep the location in your ENV variables to the one used by Agent Engine.
5 remaining items
feat(adk): Gemini 3.0 Flash 対応 - グローバルエンドポイントワークアラウンド
juszzz commentedon Feb 13, 2026
@SatohJohn's workaround worked for us. I will caution that the
@cached_propertydecorator did cause some asyncio lock contention issues in our multithreaded test suite, but switching to an@propertydecorator resolved this for us.BurgherJon commentedon Mar 8, 2026
I was able to do this by using the following changes:
In .env:
`GOOGLE_CLOUD_PROJECT=my-project
GOOGLE_CLOUD_LOCATION=global
GOOGLE_GENAI_USE_VERTEXAI=TRUE`
in agent.py (at the very top):
`import os
os.environ['GOOGLE_CLOUD_LOCATION'] = 'global'`
Obviously, I had to specify the region when doing the deploy... This is working for both gemini pro 3.1, and gemini 3 flash (I use both in the agent). Implemented code is in this repo (it's a little bit more parameterized than the above...): https://github.com/BurgherJon/growth_coach
feat: Enable Gemini 3.1 models via global endpoint workaround
william-yucciolino commentedon Apr 15, 2026
Hey guys!
It worked for me just passing the model name directly to the agent configuration and setting the following environment variables:
In the LOCATION environment variable, I used the fixed value "global," and in the deploy command, I used "us-central1".
docs(gemini): show subclass pattern for custom Client config
fix(agent-engine): make ADK agent run on Vertex AI Agent Engine + Gem…
fix(agent-engine): make ADK agent run on Vertex AI Agent Engine + Gem…
docs(gemini): show subclass pattern for custom Client config