By Sagar Shankaran, Founder of CallSphere
Learn how to use Gemini's built-in Google Search grounding to build agents that access real-time information, handle citations properly, and deliver accurate, up-to-date responses.
Key takeaways
Every language model has a knowledge cutoff date. Events, prices, regulations, and facts change constantly. When your agent answers "What is the current price of Bitcoin?" or "What are the latest changes to GDPR compliance?" using only its training data, the answer is likely outdated.
Gemini solves this with native Google Search grounding. Instead of building a separate search pipeline, you enable grounding and the model automatically searches Google when it needs current information, then cites its sources.
Grounding is enabled by passing a tool configuration when creating the model:
flowchart LR
INPUT(["User intent"])
PARSE["Parse plus<br/>classify"]
PLAN["Plan and tool<br/>selection"]
AGENT["Agent loop<br/>LLM plus tools"]
GUARD{"Guardrails<br/>and policy"}
EXEC["Execute and<br/>verify result"]
OBS[("Trace and metrics")]
OUT(["Outcome plus<br/>next action"])
INPUT --> PARSE --> PLAN --> AGENT --> GUARD
GUARD -->|Pass| EXEC --> OUT
GUARD -->|Fail| AGENT
AGENT --> OBS
style AGENT fill:#4f46e5,stroke:#4338ca,color:#fff
style GUARD fill:#f59e0b,stroke:#d97706,color:#1f2937
style OBS fill:#ede9fe,stroke:#7c3aed,color:#1e1b4b
style OUT fill:#059669,stroke:#047857,color:#fff
import google.generativeai as genai
import os
genai.configure(api_key=os.environ["GOOGLE_API_KEY"])
model = genai.GenerativeModel(
"gemini-2.0-flash",
tools="google_search_retrieval",
)
response = model.generate_content(
"What were the major AI announcements this week?"
)
print(response.text)
When grounding is active, Gemini decides autonomously whether a query needs search results. Factual questions about current events trigger a search, while questions the model can answer from training data may not.
Hear it before you finish reading
Talk to a live CallSphere AI voice agent in your browser — 60 seconds, no signup.
The response includes detailed metadata about which searches were performed and which sources were used:
response = model.generate_content(
"What is the current stock price of NVIDIA?"
)
# The generated answer
print(response.text)
# Access grounding metadata
grounding = response.candidates[0].grounding_metadata
# Search queries that were executed
if grounding.search_entry_point:
print(f"Search rendered: {grounding.search_entry_point.rendered_content}")
# Individual grounding chunks with source URLs
for chunk in grounding.grounding_chunks:
if chunk.web:
print(f"Source: {chunk.web.title} - {chunk.web.uri}")
# Grounding supports — which parts of the response are grounded
for support in grounding.grounding_supports:
print(f"Text: {support.segment.text}")
for idx in support.grounding_chunk_indices:
source = grounding.grounding_chunks[idx]
if source.web:
print(f" Backed by: {source.web.uri}")
This metadata lets you build agents that show their sources, a critical requirement for trust and compliance in enterprise applications.
Here is a complete research agent that formats responses with proper source attribution:
import google.generativeai as genai
import os
genai.configure(api_key=os.environ["GOOGLE_API_KEY"])
class ResearchAgent:
def __init__(self):
self.model = genai.GenerativeModel(
"gemini-2.0-flash",
tools="google_search_retrieval",
system_instruction=(
"You are a research assistant. Provide thorough, "
"factual answers based on current information. "
"Always note when information might change rapidly."
),
)
def research(self, query: str) -> dict:
response = self.model.generate_content(query)
sources = []
grounding = response.candidates[0].grounding_metadata
if grounding and grounding.grounding_chunks:
for chunk in grounding.grounding_chunks:
if chunk.web:
sources.append({
"title": chunk.web.title,
"url": chunk.web.uri,
})
return {
"answer": response.text,
"sources": sources,
"grounded": len(sources) > 0,
}
agent = ResearchAgent()
result = agent.research("What are the latest developments in quantum computing?")
print(result["answer"])
print(f"\nBacked by {len(result['sources'])} sources:")
for src in result["sources"]:
print(f" - {src['title']}: {src['url']}")
You can control how aggressively Gemini uses search with the dynamic retrieval configuration:
from google.generativeai.types import DynamicRetrievalConfig
model = genai.GenerativeModel(
"gemini-2.0-flash",
tools=genai.Tool(
google_search_retrieval=genai.GoogleSearchRetrieval(
dynamic_retrieval_config=DynamicRetrievalConfig(
mode="MODE_DYNAMIC",
dynamic_threshold=0.3, # Lower = more search, higher = less
)
)
),
)
A threshold of 0.3 means the model searches more often, even for queries it could partially answer from training data. A threshold of 0.8 means it only searches when it has very low confidence. For agents handling current events or financial data, a lower threshold is safer.
Still reading? Stop comparing — try CallSphere live.
CallSphere ships complete AI voice agents per industry — 14 tools for healthcare, 10 agents for real estate, 4 specialists for salons. See how it actually handles a call before you book a demo.
Grounding and custom tools can work together. The model chooses between searching the web and calling your functions based on the query:
def get_internal_sales_data(quarter: str, region: str) -> dict:
"""Fetch internal sales data from our database.
Args:
quarter: The fiscal quarter, e.g. 'Q1 2026'.
region: Sales region, e.g. 'North America'.
"""
return {"revenue": 2_500_000, "deals_closed": 47, "growth": 0.12}
model = genai.GenerativeModel(
"gemini-2.0-flash",
tools=[
"google_search_retrieval",
get_internal_sales_data,
],
)
# This query uses internal tools
response = model.generate_content("What were our Q1 2026 North America sales?")
# This query uses Google Search
response = model.generate_content("What is the current market size of the CRM industry?")
Yes. Grounded requests incur additional costs beyond the standard token-based pricing. Each grounded request is billed at a per-request rate that varies by model. Check the current Gemini API pricing page for exact figures.
Google Search grounding is available on the free tier with rate limits. The free tier typically allows a limited number of grounded requests per day, which is sufficient for development and testing.
Gemini uses Google's live search index, so the data is as current as Google Search itself — typically minutes to hours old for major news and events. This is significantly more current than any model's training data cutoff.
#GoogleGemini #GoogleSearch #Grounding #RealTimeAI #Python #AgenticAI #LearnAI #AIEngineering

Written by
Sagar Shankaran· Founder, CallSphere
LinkedInSagar Shankaran is the founder of CallSphere, where he builds production AI voice and chat agents deployed across healthcare, hospitality, real estate, and home services. He writes about agentic AI, LLM engineering, and shipping voice agents that handle real calls in production.
See how AI voice agents work for your industry. Live demo available -- no signup required.
Step-by-step build of a working agent with the OpenAI Agents SDK — Agent class, tools, handoffs, tracing — plus an eval pipeline that catches regressions before merge.
Smolagents lets agents write Python instead of JSON. Why code-as-action reduces tool errors and where the security trade-offs are for production deployments.
The 2026 chat-agent stack uses span-level verification, agentic RAG, and uncertainty-aware evals to cut hallucination rates by an order of magnitude.
Sub-second agent decisions need explicit budgets at every step. The 2026 latency-engineering patterns from real production deployments.
Google shipped Gemini 3.1 Pro, Workspace Intelligence, Notebooks in the Gemini app, and an Enterprise Agent Platform in April 2026.
Modal turns a Python function into autoscaling serverless compute with optional GPU. Deploy a LiveKit Agent with one command and get pay-per-second billing.
© 2026 CallSphere Inc. All rights reserved.
Made within San Francisco
Watch how CallSphere handles real customer calls, schedules appointments, and processes payments — live.