Skip to content

feat(llm): run every Gemini call on Vertex AI with GOOGLE_GENAI_USE_VERTEXAI - #228

Open
ajstars1 wants to merge 1 commit into
google:mainfrom
ajstars1:feat/vertex-backend-switch
Open

ajstars1 wants to merge 1 commit into
google:mainfrom
ajstars1:feat/vertex-backend-switch

Conversation

@ajstars1

Copy link
Copy Markdown

Closes #227

Summary

Adds one switch that moves all Gemini traffic to Vertex AI: setting google-genai's own GOOGLE_GENAI_USE_VERTEXAI=true makes every google endpoint, helper agents included, run on Vertex with Application Default Credentials. Today the step summarizer, explorer, object detector and video analyzer build their Gemini clients from GOOGLE_API_KEY, so they keep hitting the developer API (free-tier 429s, busy-time 503s) even when the main model is meant to run on Vertex.

This complements #186: that PR fixes the explicit vertexai provider (ChatVertexAI part order, #156). This one leaves that provider unchanged and instead routes google endpoints through google-genai with vertexai=True, which keeps the developer-API message conversion, so it does not hit the #156 error either.

Changes

  1. artemis/llm/google/provider.py: use_vertex_backend() reads GOOGLE_GENAI_USE_VERTEXAI; vertex_project() reads VERTEX_AI_PROJECT then GOOGLE_CLOUD_PROJECT; vertex_location() reads VERTEX_AI_LOCATION then GOOGLE_CLOUD_LOCATION, default global (where Gemini 3 is served). Env-only, so the module stays free of SDK and settings imports.
  2. ModelFactory.create_model: with the switch on, the google branch passes vertexai=True, project and location instead of an API key. Everything else (thinking level, safety settings, grounding patch) is shared, so get_google_llm callers such as the step summarizer follow automatically.
  3. Explorer and video analyzer: on Vertex they skip their native developer-API path, which needs the API key and the Files API, and use the LangChain path.
  4. .env.example documents the three variables.
  5. tests/unit/test_vertex_backend.py covers the flag values, project/location precedence, the factory kwargs with and without the switch, and the explorer engine choice. tests/conftest.py clears the flag so a developer's local .env cannot change test behaviour (without it, test_explorer_run fails on a machine that has the switch on).

Verification

  • make lint, make typecheck, make test (2540 passed, 7 skipped)
  • Live, with only the switch, GOOGLE_CLOUD_PROJECT and ADC set: gemini-3.8-flash, gemini-3.5-flash-lite and gemini-robotics-er-2-preview each answered on Vertex global, and a replayed second turn (tool call, tool result, new observation) returned the next tool call where ChatVertexAI had returned the Vertex Gemini 3.8 Flash fails after the first ARTEMIS tool-calling turn #156 400.
  • Nothing Phone (3a), Android 16, Flash profile: a 6-step task (search for a song in a music app and play the second result) completed on Vertex in about 75 s with no calls to the developer API. Before the change the same task stalled on step summarizer 429s and developer-API 503s.

…ERTEXAI

Configuring the agents for Vertex AI does not move all Gemini traffic
off the Gemini API key. Helper agents build their own google endpoints
or google-genai clients from the key: the Flash step summarizer
(get_google_llm), the explorer's native engine, the object detector and
the video analyzer. With a free-tier key those calls hit 429
RESOURCE_EXHAUSTED and stall runs even when the main model is on Vertex.

Honour google-genai's own switch, GOOGLE_GENAI_USE_VERTEXAI. When it is
set, every google endpoint is created as ChatGoogleGenerativeAI with
vertexai=True, the project from VERTEX_AI_PROJECT or
GOOGLE_CLOUD_PROJECT and the location from VERTEX_AI_LOCATION or
GOOGLE_CLOUD_LOCATION (default global, where Gemini 3 is served),
authenticated with Application Default Credentials. The explorer and
video analyzer skip their native developer-API path on Vertex, since it
needs the API key and the Files API, and use the LangChain path.

Because these calls go through google-genai, they keep the developer-API
message conversion and do not hit the ChatVertexAI part-order error
from google#156. The explicit vertexai provider is unchanged.

Tests clear the flag so a local .env cannot change their behaviour.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Helper agents keep using the Gemini API key when Gemini should run on Vertex AI

1 participant