Set Up a Google Cloud Gemini Agent for Work
In this article
This guide walks you through creating a Gemini agent in Google Cloud—a custom AI assistant that can answer questions, automate tasks, and connect to your internal tools. By the end, you’ll have a working agent deployed in Vertex AI, ready to handle real work like summarizing documents, drafting emails, or querying databases. You’ll need a Google Cloud project with billing enabled, and basic familiarity with the Cloud Console.
What You'll Need
- A Google Cloud account with an active project (billing must be enabled).
- Access to the Vertex AI API—enable it in your project.
- Google Cloud CLI installed locally (optional, but used in some steps).
- Permissions: roles/aiplatform.user or equivalent.
Step-by-Step
- Enable the Vertex AI API
Go to the Google Cloud Console → APIs & Services → Library. Search for “Vertex AI API” and click Enable. If you plan to use the Gemini API directly, also enable “Generative Language API”. - Create a service account for the agent
Navigate to IAM & Admin → Service Accounts. Click Create Service Account, give it a name (e.g.,gemini-agent-sa), and assign roles:Vertex AI UserandService Usage Consumer. This account will be used by the agent to authenticate. - Set up a Cloud Storage bucket (optional but recommended)
If your agent needs to read files (PDFs, docs), create a bucket in Cloud Storage. Note the bucket name—you’ll reference it in the agent’s tools. - Open Vertex AI Agent Builder
In the Console, go to Vertex AI → Agent Builder (or “Generative AI Studio” in older UIs). Click Create Agent. - Choose a model and configure the agent
Select a Gemini model (e.g.,gemini-1.5-proorgemini-2.0-flash). Give your agent a name and description. Set the system instruction—this is the “persona” that tells the agent how to behave (e.g., “You are a customer support assistant for Acme Corp”). - Add tools and extensions
Under “Tools”, add extensions like “Code Interpreter” for data analysis, or “Web Search” for live information. If you have a REST API, you can add it as an “Extension” using an OpenAPI spec. For file access, attach your Cloud Storage bucket via the “File” tool. - Connect to your data (RAG)
To ground the agent in your company’s documents, create a data store in Vertex AI Search. Upload your PDFs or connect to a website. Then link this data store to your agent as a “Data Store” tool. - Test the agent in the playground
Use the built-in chat panel to test. Try questions relevant to your work—e.g., “Summarize the latest sales report from the bucket.” Refine the system instruction and tools based on the responses. - Deploy the agent
Click “Deploy” to create an endpoint. You’ll get a URL (likehttps://us-central1-aiplatform.googleapis.com/v1/projects/.../locations/.../publishers/google/models/...) that you can call via REST or gRPC. - Integrate with your apps
Use the endpoint in your internal tools—e.g., a Slack bot, a web app, or a Google Chat integration. Use the service account’s key to authenticate. For a simple start, use the Cloud Console’s “Test” tab to generate a sample request.
Common Mistakes
- Not enabling the correct APIs—Vertex AI and Generative Language API are separate; missing one causes 403 errors.
- Using the wrong service account permissions—the agent needs
aiplatform.userandstorage.objectViewerif accessing files. - Forgetting to set the project region—some resources are regional; ensure your agent and data store are in the same region.
- Overloading the system instruction—too many instructions confuse the model. Keep it concise and specific.
- Ignoring grounding—without connecting to your data, the agent will hallucinate answers. Always link a data store for factual queries.
Tips
- Start with a simple agent and add tools gradually—this makes debugging easier.
- Use versioned system instructions—save them in a file and reference them.
- Enable logging in Vertex AI to see request/response pairs for cost and quality analysis.
- Set a budget alert to avoid unexpected charges from heavy usage.
- For production, use the Vertex AI SDK in Python or Node.js rather than raw REST calls.
Troubleshooting
- 403 Permission Denied—Check that the service account has the
aiplatform.userrole and that the API is enabled. Also verify that you’re using the correct project ID in the request. - Model not found—Ensure the model name is correct for your region. Some models are only available in certain regions—check the documentation for availability.
- Data store not returning results—Confirm that the data store is indexed. You may need to wait a few minutes after uploading files. Also check that the data store is linked to the agent in the “Tools” section.
- Agent gives irrelevant answers—Refine the system instruction. Add explicit constraints like “Only answer based on the provided documents.” Also try lowering the temperature parameter (e.g., to 0.2) for more deterministic outputs.
- Endpoint returns 504 Timeout—This often happens with long-running requests. Increase the timeout in your client, or use the asynchronous API for heavy tasks.
Frequently Asked Questions
Can I use Gemini for free?
Google Cloud offers a free tier for Vertex AI with limited requests per minute. For work, you’ll likely need to pay for usage—check the pricing page for current rates.
How do I connect Gemini to my company’s database?
You can create a custom extension that calls your database API. Alternatively, use a tool like Cloud SQL’s built-in integration with Vertex AI, or export data to a vector store like AlloyDB.
What is grounding and why is it important?
Grounding means providing the model with your own data (via a data store) to base answers on. This reduces hallucinations and ensures responses are accurate to your business context.
Can I use Gemini with Google Workspace (Gmail, Docs)?
Yes, you can use the Google Workspace extension in Vertex AI Agent Builder to access Gmail, Docs, and Drive. You’ll need to authorize the extension with OAuth.
How do I monitor costs?
Use the Cloud Billing reports to track spend. Also enable Vertex AI logging and set up alerts for unusual usage.
Is it possible to deploy the agent on-premise?
No, Google Cloud’s Gemini agents run only in the cloud. However, you can access them via API from your on-premise systems.