◉GEMINI LABJP
●2.5 ROUTE — From today, 12/1, calls to gemini-2.5-pro and 2.5-flash are rerouted to newer models automatically●CLI 0.71.1 — Gemini CLI stable is still v0.71.1, with a 0.73 nightly published on 11/30●INTRO END — Introductory pricing for 3.8, 3.7 and 3.6 Flash ends on 12/31. 30 days left●VERTEX — Developers are asking how to run Gemini CLI with Vertex AI credentials●NEON — Gemini 4 Neon became generally available on 11/18 (paid tier only)●IMAGE TEXT — A new test shows text inside an image can sway Gemini's answer●2.5 ROUTE — From today, 12/1, calls to gemini-2.5-pro and 2.5-flash are rerouted to newer models automatically●CLI 0.71.1 — Gemini CLI stable is still v0.71.1, with a 0.73 nightly published on 11/30●INTRO END — Introductory pricing for 3.8, 3.7 and 3.6 Flash ends on 12/31. 30 days left●VERTEX — Developers are asking how to run Gemini CLI with Vertex AI credentials●NEON — Gemini 4 Neon became generally available on 11/18 (paid tier only)●IMAGE TEXT — A new test shows text inside an image can sway Gemini's answer
← Back to Blog

Building an Autonomous Agent with Gemini 3 Flash Function Calling

geminifunction-callingagentgoogle-searchdev-notes

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:

  1. Fetches real-time info via Google Search
  2. Synthesizes information from multiple sources
  3. Generates a structured report
  4. 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:

  1. Pass tool definitions to the model
  2. The model returns a "please call this tool" response
  3. Your app executes the tool and returns results
  4. 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 messages

Why 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.