English

Vertex AI Agent Builder is Google's answer to the "give me grounding, tool use, and deployment in one place" problem, and after running three internal agents through it, the honest verdict is: the grounding story is genuinely strong, the tool-calling story is solid once you understand the function-calling contract, and the deployment story only gets clean if you commit to Cloud Run rather than fighting the managed endpoint UI. Here's the practical path through it.

Vertex AI Search for Grounding

The foundation of a Agent Builder agent is a Vertex AI Search data store - point it at a GCS bucket, a website, or a BigQuery table, and it handles ingestion, chunking, and indexing without you managing an embedding pipeline directly.

gcloud alpha discovery-engine data-stores create support-docs-store \
  --location=global \
  --industry-vertical=GENERIC \
  --content-config=CONTENT_REQUIRED \
  --solution-types=SOLUTION_TYPE_SEARCH

Once indexed, grounding a Gemini call against it is a single tool declaration - no manual retrieval, embedding, or reranking code required on your side:

from vertexai.generative_models import GenerativeModel, Tool, grounding

model = GenerativeModel("gemini-2.0-flash")

grounding_tool = Tool.from_retrieval(
    grounding.Retrieval(
        grounding.VertexAISearch(datastore="projects/my-proj/locations/global/collections/default_collection/dataStores/support-docs-store")
    )
)

response = model.generate_content(
    "What's our policy on expedited refunds for enterprise accounts?",
    tools=[grounding_tool],
)

print(response.text)
print(response.candidates[0].grounding_metadata.grounding_chunks)

grounding_metadata gives you the exact source chunks used, which we surface as citations in the UI - the same reason every other cloud RAG offering exposes something similar: nobody trusts an ungrounded answer in a compliance-sensitive workflow.

Defining Agent Tools

Beyond retrieval, agents need real tool calls - looking up an order, checking inventory, escalating a ticket. Agent Builder tools are Gemini function declarations, structurally similar to OpenAI's function calling but with a slightly different schema wrapper.

from vertexai.generative_models import FunctionDeclaration, Tool

check_inventory = FunctionDeclaration(
    name="check_inventory",
    description="Check current warehouse stock level for a given SKU.",
    parameters={
        "type": "object",
        "properties": {
            "sku": {"type": "string", "description": "Product SKU code"},
            "warehouse_id": {"type": "string", "description": "Optional warehouse identifier"},
        },
        "required": ["sku"],
    },
)

inventory_tool = Tool(function_declarations=[check_inventory])

response = model.generate_content(
    "Do we have SKU AB-2291 in stock at the Denver warehouse?",
    tools=[inventory_tool],
)

call = response.candidates[0].content.parts[0].function_call
if call.name == "check_inventory":
    result = check_inventory_impl(**dict(call.args))

The pattern is the same loop every function-calling framework uses: the model returns a structured call instead of text, your code executes it, and you feed the result back as a follow-up turn.

Picking a Gemini Model

  • Gemini 2.0 Flash - our default for anything conversational; low latency, strong enough for tool selection and grounded QA
  • Gemini 2.0 Pro - reserved for genuinely hard reasoning steps (multi-constraint scheduling, complex policy interpretation) where Flash's answers were measurably worse in our eval set
  • Gemini 2.0 Flash-Lite - for high-volume, low-complexity classification steps inside a larger pipeline where cost dominates the decision

Don't default to the biggest model for the whole pipeline - route by step. A classification node and a final-answer-generation node have very different quality/cost tradeoffs.

Deploying to Cloud Run

The managed Agent Builder console works fine for prototyping, but for anything we actually operate long-term, we wrap the agent logic in a FastAPI service and deploy it to Cloud Run - it gives us normal CI/CD, normal autoscaling knobs, and normal observability instead of a bespoke managed-agent lifecycle.

FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]
gcloud run deploy support-agent \
  --source . \
  --region us-central1 \
  --service-account agent-runtime@my-proj.iam.gserviceaccount.com \
  --set-env-vars VERTEX_PROJECT=my-proj,VERTEX_LOCATION=us-central1 \
  --min-instances 1 \
  --concurrency 20

--min-instances 1 matters more than it looks - Cloud Run's cold start plus a Vertex AI Search round trip can add a full second-plus of latency on the first request otherwise, which is exactly the kind of thing that shows up as a bad first impression in a demo.

Monitoring with Cloud Logging

Every Vertex AI generation call and grounding lookup can be structured-logged to Cloud Logging, and from there we build a Cloud Monitoring dashboard on top rather than relying on the Vertex AI console's default views, which don't slice by our own business dimensions (ticket category, customer tier).

import logging
import json

logging.getLogger().info(json.dumps({
    "event": "agent_turn_completed",
    "session_id": session_id,
    "grounding_chunks_used": len(response.candidates[0].grounding_metadata.grounding_chunks),
    "latency_ms": latency_ms,
    "model": "gemini-2.0-flash",
}))

We alert on two Cloud Monitoring metrics specifically: p95 latency crossing 2.5 seconds, and grounding chunk count dropping to zero for more than 1% of requests in a rolling 15-minute window - the latter is our earliest signal that the search data store has an indexing problem upstream.

Lessons Learned

  • Grounding metadata is worth exposing to end users, not just logging internally - it builds trust and gives support a way to verify an answer fast
  • Route model choice per pipeline step, not per agent
  • Treat the managed console as a prototyping tool; production agents belong in your own deployable service
  • Structured logging from day one saves you from rebuilding observability after the first on-call incident

Vertex AI Agent Builder's real value isn't the console - it's Vertex AI Search doing the grounding heavy lifting and Gemini's function-calling contract being solid enough to build real tool-using agents on. Wrap it in infrastructure you actually control for deployment, and it holds up well in production.

Posted ongcpwith tags:
0
0
0
0