Agent with Vertex AI

Use Gemini through Vertex AI by setting environment variables or passing vertexai=True.

Code

"""
To use Vertex AI, with the Gemini Model class, you need to set the following environment variables:

export GOOGLE_GENAI_USE_VERTEXAI="true"
export GOOGLE_CLOUD_PROJECT="your-project-id"
export GOOGLE_CLOUD_LOCATION="global"

Or you can set the following parameters in the `Gemini` class:

gemini = Gemini(
    vertexai=True,
    project_id="your-google-cloud-project-id",
    location="global",
)
"""

from agno.agent import Agent, RunOutput  # noqa
from agno.models.google import Gemini

agent = Agent(model=Gemini(id="gemini-3.5-flash"), markdown=True)

# Get the response in a variable
# run: RunOutput = agent.run("Share a 2 sentence horror story")
# print(run.content)

# Print the response in the terminal
agent.print_response("Share a 2 sentence horror story")

Usage

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Set up Vertex AI

Use a Google Cloud project with billing and the Vertex AI API enabled, and an identity authorized to call the model. For local development, configure Application Default Credentials:

gcloud auth application-default login

On Google Cloud, use the runtime’s service identity. Set your environment variables:

export GOOGLE_GENAI_USE_VERTEXAI="true"
export GOOGLE_CLOUD_PROJECT="your-project-id"
export GOOGLE_CLOUD_LOCATION="global"

Or configure in code:

gemini = Gemini(
    vertexai=True,
    project_id="your-google-cloud-project-id",
    location="global",
)

Install dependencies

uv pip install -U google-genai agno

Run Agent

Save the code above as vertexai.py, then run:

python vertexai.py