Skip to content

Feature Request: Allow passing a custom Client to Gemini #5027

Closed

Description

@naresh-gn

Is your feature request related to a specific problem?

When building a multi-agent system with LlmAgent and Gemini, each agent may need a different model hosted in a different Vertex AI location. For example:

  • Agent 1 uses gemini-3.1-pro-preview, which is only available in the global location
  • Agent 2 uses gemini-2.5-flash, which is available in us-central1

Currently, Gemini creates its own Client internally via the api_client cached property (google_llm.py L273), which reads project and location from environment variables (GOOGLE_CLOUD_PROJECT, GOOGLE_CLOUD_LOCATION). Since environment variables are process-global, there is no way to configure different locations (or projects) for different agents within the same process.

Previously it was possible to construct a google.genai.Client with per-agent settings and pass it into Gemini(client=client), but this is no longer supported — Gemini is a Pydantic BaseModel that only accepts model, base_url, speech_config, use_interactions_api, and retry_options.

This makes it impossible to run a multi-agent system where agents target different Vertex AI locations or projects.

Describe the Solution You'd Like

Allow Gemini to accept an optional client: Optional[Client] = None parameter. When provided, Gemini should use the supplied client instead of constructing its own in the api_client cached property.

Proposed API:

from google.genai import Client
from google.adk.models.google_llm import Gemini
from google.adk.agents import LlmAgent

client_global = Client(vertexai=True, project="my-project", location="global")
client_us = Client(vertexai=True, project="my-project", location="us-central1")

agent_1 = LlmAgent(
    name="Agent1",
    model=Gemini(client=client_global, model="gemini-3.1-pro-preview"),
    instruction="...",
)

agent_2 = LlmAgent(
    name="Agent2",
    model=Gemini(client=client_us, model="gemini-2.5-flash"),
    instruction="...",
)

If client is not provided, behavior stays exactly as it is today (auto-create from env vars).

Impact on your work

This is blocking our multi-agent deployment. We have a root coordinator agent that delegates to specialist sub-agents, and our models are available in different Vertex AI regions. Without per-agent client configuration, we cannot use ADK's native Gemini integration and would have to work around it by subclassing Gemini and overriding the api_client property, which is fragile and may break across releases.

Activity

  1. added
    core[Component] This issue is related to the core interface and implementation
    on Mar 28, 2026
  2. added theissue type on Mar 28, 2026
  3. brucearctor commented on Mar 28, 2026

    @brucearctor
    Contributor

    @naresh-gn : hows the PR look for what you had in mind?

  4. klateefa commented on Mar 30, 2026

    @klateefa

    @naresh-gn Thanks for the update. The request is currently being reviewed, and I will let you know if anything further is needed. Thank you for understanding.

  5. added
    needs review[Status] The PR/issue is awaiting review from the maintainer
    on Mar 30, 2026
  6. Sravan1011 commented on Mar 30, 2026

    @Sravan1011

    is this issue resolved or should I create a pr ?

  7. brucearctor commented on Apr 1, 2026

    @brucearctor
    Contributor

    is this issue resolved or should I create a pr ?

    ???

    #5035

    That might solve it, but up to you?

  8. naresh-gn commented on May 6, 2026

    @naresh-gn
    Author

    @GWeale @klateefa is this change/approach fixes this issue?
    48105b4

  9. haranrk commented on Jul 14, 2026

    @haranrk
    Collaborator

    @naresh-gn This is currently possible via client_kwargs. Does this work for your use case?

    from google.adk.agents import LlmAgent
    from google.adk.models.google_llm import Gemini
    
    agent_1 = LlmAgent(
        name="Agent1",
        model=Gemini(
            model="gemini-3.1-pro-preview",
            client_kwargs={"vertexai": True, "project": "my-project", "location": "global"},
        ),
        instruction="...",
    )
    
    agent_2 = LlmAgent(
        name="Agent2",
        model=Gemini(
            model="gemini-2.5-flash",
            client_kwargs={"vertexai": True, "project": "my-project", "location": "us-central1"},
        ),
        instruction="...",
    )
  10. self-assigned this
    on Aug 6, 2026
  11. GWeale commented on Aug 6, 2026

    @GWeale
    Collaborator

    client_kwargs on Gemini covers this, pass project and location there and they go to the google.genai.Client constructor. for a fully custom client, subclass and override api_client. open a new issue if it resurfaces.

  12. added a commit that references this issue on Aug 21, 2026
    a01d516
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

core[Component] This issue is related to the core interface and implementationneeds review[Status] The PR/issue is awaiting review from the maintainer

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions