Every time I wrote about agent skills, someone asked: “What about Gemini?” I’ve covered Claude’s tool use and OpenAI’s functions. Now it’s Google’s turn. Gemini’s function calling works on the same basic idea. You define a tool. The model decides to use it. You run the code. Then you hand the result back. The syntax is just different enough to be annoying if you’re used to the other two. By the end of this guide, you’ll have a working agent and a comparison table to keep the names straight.
How is Gemini’s “function calling” different from the others?
Gemini doesn’t use a stateless message array by default. It uses a “chat session” model.
The Scenario: You’re building a support bot for a travel agency. A user asks “Is my flight to Delhi on time?” Gemini doesn’t know your flight schedule. It stops and sends a request for your
check_flight_statustool. You find the flight, see it’s delayed by an hour, and tell Gemini. Gemini then tells the user “Your flight is running 60 minutes late—grab a coffee.”
The model handles the conversation state for you. You just focus on the tool calls.
What do I need to get Gemini running?
You need the Google Generative AI SDK and an API key. Google AI Studio gives you a free key without a credit card.
npm install @google/generative-ai
How do I tell Gemini about my tools?
Gemini calls tool definitions “function declarations.” The names for types must be in uppercase strings like STRING or OBJECT.
const weatherTool = {
name: "get_weather",
description: "Get weather for a city. Use for rain or temp questions.",
parameters: {
type: "OBJECT",
properties: {
city: { type: "STRING", description: "The city name" }
},
required: ["city"]
}
};
How do I start a “smart” conversation?
You create a model instance and pass your tools into it. Then you start a chat session.
const model = genAI.getGenerativeModel({
model: "gemini-2.0-flash",
tools: [{ functionDeclarations: [weatherTool] }]
});
const chat = model.startChat();
const response = await chat.sendMessage("What's the weather in Mumbai?");
How do I know when Gemini wants to use a tool?
You check the response parts for a functionCall. Unlike OpenAI, Gemini gives you a pre-parsed object. No JSON.parse() is required here.
The Scenario: You’re building a fitness bot. A user asks “How many calories are in a Big Mac?” Gemini doesn’t have a nutrition database. It stops and sends a
functionCallfor yourget_nutritiontool. You find the answer (563 calories) and hand it back. Gemini tells the user “A Big Mac has 563 calories—maybe try a salad?”
Where does the actual heavy lifting happen?
Your tool function is just regular JavaScript. It can be an API call or a database query.
async function get_weather({ city }) {
const res = await fetch(`https://api.weather.com/${city}`);
return await res.json();
}
How do I hand the result back to Google’s AI?
You send the result back through the same chat session. You use a functionResponse part.
const result = await get_weather(functionCallPart.functionCall.args);
await chat.sendMessage([{
functionResponse: {
name: "get_weather",
response: result // Send the object directly
}
}]);
What does a complete Gemini agent look like?
A real agent runs in a while loop. It keeps processing function calls until it gets a final text response.
Gemini vs. Claude vs. OpenAI: Which one is easiest?
Each one has its own quirks. Gemini is the only one that accepts plain objects as tool results. OpenAI forces you to use JSON strings. Claude requires a specific “tag” for every tool result.
What can Gemini do that the others can’t?
Gemini has built-in “Google Search Grounding.” You don’t have to write your own search tool.
The Scenario: You’re building a research bot. Instead of paying for a search API, you just turn on Gemini’s search grounding. Now your agent can browse the live web using Google’s own search engine for free. It’s a huge cost saver.
Can I just use the Vercel AI SDK instead?
Yes. If you don’t want to learn the specific Gemini syntax, the Vercel AI SDK is the best choice. It lets you write one tool and use it across any model.
Does Gemini work with the Model Context Protocol?
Yes. Gemini 2.0 supports MCP. This is the industry standard for connecting AI to external tools.
What should I build next?
- One API for all: Vercel AI SDK Tools: One API for Claude and OpenAI Skills
- Compare the others: Agent Skills with the Claude API and Agent Skills with the OpenAI API
- Basics first: What Are Agent Skills? AI Tools Explained Simply