"Genkit Dart Tool Calling: Gemini Functions That Run Code"

"Function-calling tutorials always demo a fake weather function. This genkit dart defineTool example wires a real API call into Gemini: typed inputs with schemantic, toolNames wiring, tools that survive failure, and multiple tools cooperating in one agent loop."

Every tool-calling tutorial shows the same demo: the model "calls" a getWeather function that returns a hardcoded "Sunny, 72°F" . The audience nods. The tutorial declares victory. But nothing actually ran — no network call, no parsing, no failure modes. That's the least interesting part of tool calling, and it's where most tutorials stop. The interesting part is everything they skip: the model ignoring your tool, your tool throwing mid-loop, two tools cooperating, a loop that never ends. Tools are the moment your AI stops reciting training data and starts doing work. This genkit dart defineTool example builds a real one: a weather tool backed by a live API, wired into Gemini, with the failure modes handled instead of hand-waved. What you'll walk away with The anatomy of defineTool : the four pieces and what the model actually sees A real API-backed tool with typed inputs — no stubs, no hardcoded strings toolNames wiring: how the model decides when to call what Tools that survive failure: error strings, timeouts, and input validation Multiple tools cooperating in a single agent loop Debugging playbook for "the model won't call my tool" Tool anatomy: the four pieces the model sees A tool is a contract between your code and the model. defineTool takes four things, and only two of them are for the model: final getWeather = ai.defineTool( name: 'getWeather', // 1. the model's handle description: 'Gets the current temperature for a city. ' 'Use this when the user asks about weather, temperature, ' 'or conditions somewhere.', // 2. what the model reads inputSchema: WeatherInput.$schema, // 3. the shape of arguments fn: (WeatherInput input, _) async { // 4. your code. Only this runs. // ... fetch, compute, return…

Explore