GEMINI LABJP
NANOLITE — Nano Banana 2 Lite is here: Google's fastest and most cost-efficient Gemini Image model, made for running lightweight image generation cheaplyOMNIFLASH — Gemini Omni Flash is in public preview, a natively multimodal model that lets enterprises and developers build custom, dynamic video workflowsAGENTS — Managed Agents expand with background: true for async server-side runs and polling, remote MCP server integration, and refreshing credentials across interactionsMEMORY — The Memory Bank IngestEvents API is generally available, decoupling event ingestion from memory generation so you can stream content continuouslyTHROUGHPUT — Provisioned Throughput now lets you submit up to seven pending orders for the same model and regionDEPRECATE — Image generation models shut down on August 17, and the Grok 4.1 family on the Gemini Enterprise Agent Platform on August 20NANOLITE — Nano Banana 2 Lite is here: Google's fastest and most cost-efficient Gemini Image model, made for running lightweight image generation cheaplyOMNIFLASH — Gemini Omni Flash is in public preview, a natively multimodal model that lets enterprises and developers build custom, dynamic video workflowsAGENTS — Managed Agents expand with background: true for async server-side runs and polling, remote MCP server integration, and refreshing credentials across interactionsMEMORY — The Memory Bank IngestEvents API is generally available, decoupling event ingestion from memory generation so you can stream content continuouslyTHROUGHPUT — Provisioned Throughput now lets you submit up to seven pending orders for the same model and regionDEPRECATE — Image generation models shut down on August 17, and the Grok 4.1 family on the Gemini Enterprise Agent Platform on August 20
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.