Introduction
Since Gemini 3 Flash launched, I'd been wanting to try something: building an autonomous agent that combines Function Calling with Google Search grounding.
I finally got around to it over the weekend, and it worked better than expected. Here's what I built, and what I learned.
What I Built
A "news aggregator agent" that auto-generates summary reports on a given topic.
The user provides a topic (e.g., "latest AI regulation developments"), and the agent automatically:
- Fetches real-time info via Google Search
- Synthesizes information from multiple sources
- Generates a structured report
- Appends a source list at the end
The whole thing came in around 200 lines of Python.
How Function Calling Works
The Gemini API's Function Calling flow is straightforward:
- Pass tool definitions to the model
- The model returns a "please call this tool" response
- Your app executes the tool and returns results
- The model generates the final answer
This back-and-forth is the core of Function Calling — the model decides what to do, but you control how it's executed.
Key Learnings
1. Tool description quality is everything
Vague tool descriptions lead to the model calling tools at the wrong time. Being explicit about when to use it, what goes in, and what comes back significantly improved accuracy.
tools = [
{
"name": "search_web",
"description": "Search the web for a query and retrieve up-to-date information. Use when the user needs current events, recent data, or real-time information.",
"parameters": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "Search query (English or Japanese)"
}
},
"required": ["query"]
}
}
]2. Function Calling vs. Google Search Grounding
The Gemini API also offers "Google Search Grounding" where the model searches automatically. The difference:
- Google Search Grounding: Model searches autonomously. Minimal code required.
- Function Calling: You define and control the tools. Enables multiple tool combinations and custom API integrations.
I chose Function Calling because I wanted flexibility to add internal API integrations later.
3. Higher thinking budget improves tool selection
Setting thinking_budget to high noticeably improved the model's judgment about when to call tools. For cost-sensitive use cases, medium was good enough.
4. Always limit loop steps
Add a maximum step count to prevent runaway tool-calling loops. During testing, I ran up an unexpected API bill without this guardrail.
MAX_STEPS = 5
for step in range(MAX_STEPS):
response = model.generate_content(messages, tools=tools)
if not response.candidates[0].function_calls:
break # No tool call → final answer
# Execute tool → append result to messagesWhy Gemini 3 Flash for Agents
Gemini 3 Flash turned out to be the right choice for agentic use cases:
- Speed: Agents have many roundtrips, so slow responses kill the UX
- Cost: $0.50/1M input tokens stays realistic even with loops
- Function Calling accuracy: SWE-bench 78% translates to accurate tool selection
Compared to Gemini 3.1 Pro, the cost difference is significant while performance for this use case is on par. For agents, Flash is the pragmatic choice.
What's Next
- Multi-tool agents combining web search + email + calendar
- Google Antigravity integration for fully autonomous workflows
- Streaming support to show the agent's "thinking" in real time
Function Calling turned out to be simpler to implement than I expected, with a wide range of applications. Expect more concrete agent implementation articles on Gemini Lab soon.