Repository navigation
Let an agent's model name the Vertex AI location it is called in - #95
Merged
Merged
Conversation
Some Gemini models are offered only in the global location, and Agent
Engine runs in a region it also writes into GOOGLE_CLOUD_LOCATION. A
declaration cannot override that variable, and a full resource path in
model still goes to the regional endpoint, so such a model could not be
declared at all.
model now also takes {id, location}. The runtime hands the location to
ADK's Gemini through client_kwargs, a field every ADK release in the
supported range reads when building its clients, so no subclass is
needed. A model called where the agent runs stays a plain string.
🤖 Generated with Claude Code
Under oneOf, a model object missing its location was reported as not being a string, which says nothing about what to fix. One schema typed as string or object lets each keyword apply to its own type, so the message names the missing or unexpected key instead. 🤖 Generated with Claude Code
The location reaches the model only through the Gemini client, yet any id was wrapped in Gemini. A model ADK serves with another class, such as Claude on Vertex AI, passed validate and then called a publisher that does not have it. The id is now resolved through ADK's own registry, the one a plain name goes through: validate reports anything that is not a Gemini, and the runtime refuses it too, for a deployment validate never saw. The runtime test no longer compares the client arguments, which fixed how the location travels rather than where the call goes; the test that checks the client's location covers that. README says such a model is always called on Vertex AI, local runs included. 🤖 Generated with Claude Code
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Some Gemini models on Vertex AI are offered only in the
globallocation (for examplegemini-3-flash-previewandgemini-3.1-pro-preview); a regional endpoint such asus-central1returns 404 for them. Agent Engine runs in a region, and gete had no way to declare an agent on such a model:GOOGLE_CLOUD_LOCATIONis reserved: Agent Engine sets it itself, andgete validaterefuses it inruntime.agent_engine.env.modeltoLlmAgentas a plain string, so ADK'sGeminibuilt its client from the environment's location.projects/<p>/locations/global/publishers/google/models/...) does not help either: the request still goes to the regional endpoint.One reason to want these models: with
gemini-2.5-*, a built-in tool such asurl_contextorgoogle_searchcannot be combined with function declarations in one request (400 Multiple tools are supported only when they are all search tools), while the Gemini 3 models accept the combination. So an agent that wants abuiltin:tool next tomcp:/openapi:tools needs one of them.What changes
modelalso takes an object naming the location to call the model in:A model called in the agent's own region is still written as the plain string, as before. This follows the
connectionsentries, whose object form is used only when it selects something.Schema. The object requires both
idandlocationand accepts no other keys.locationmust look like a Vertex AI location (global,us,us-central1, ...), since it becomes part of the endpoint's host name and URL path.modelis typed as string or object rather than aoneOf, so a malformed object is reported by the key at fault (model: 'location' is a required property) instead of as "not of type 'string'".Runtime. The
idis resolved through ADK'sLLMRegistry, the same registry a plain model name goes through, and the location is handed to that class asclient_kwargs={"enterprise": True, "location": location}.client_kwargsis a field onGeminiin every ADK release in the supported range (checked in 2.6.0, 2.7.0 and 2.8.0), and ADK passes it togoogle.genai.Clientwhen it builds both its generate and its live clients, so no subclass overridingapi_clientis needed.enterprise=Trueis the flag ADK itself sets for Vertex AI resource paths and is available in thegoogle-genaiversions ADK 2.6 requires.Only Gemini models. The location reaches the model only through the Gemini client.
gete validatereports an object-formmodelwhoseidADK does not resolve toGemini(or a subclass), such as a Claude model on Vertex AI, and the runtime refuses it as well, for a deployment that skipped validate.README describes the object form under
agent.yaml, and notes that such a model is always called on Vertex AI,gete runincluded: aGOOGLE_API_KEYfor the Gemini Developer API is not enough there.Compatibility
Additive. Existing declarations with a string
modelbuild exactly the same agent.An agent that uses the object form has to be deployed with a gete that includes this change, since the runtime inside the archive is what reads it.
Testing
idorlocation, with an emptyid, with an unknown key, or with a malformedlocationis refused, and the message names the key at fault.Gemini, and withGOOGLE_CLOUD_LOCATION=us-central1in the environment, its client is a Vertex AI client forglobal. A non-Gemini id is refused.pytest,ruff check,ruff format --checkandmypypass locally, excepttest_generated_file_is_valid_hcl_for_terraform_fmt, which fails the same way onmainwith the local Terraform version and is unrelated.