tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Generative AI > Google Gemini API > Gemini Function Calling

Gemini Function Calling

Author: Venkata Sudhakar

Gemini function calling lets you give the model access to your own business functions so it can look up real data before answering. When a customer asks "where is my order?" Gemini does not guess - it calls your order tracking function with the order number, reads the real status, and gives a grounded answer. You define functions as tools, Gemini decides when and how to call them, you execute the function and return the result, and Gemini incorporates it into its final response. This is how you build Gemini-powered assistants that are connected to your actual business systems rather than relying on the model knowledge alone.

In the google-genai SDK, tools are defined as ordinary Python functions with docstrings and type hints - the SDK automatically generates the JSON schema. Pass the function list in the tools parameter of generate_content. When Gemini decides to call a function it returns a function_call part; you execute it and send back a function_response part in the next turn. The SDK also supports automatic_function_calling which handles this loop for you - ideal for simple single-tool scenarios where you want minimal boilerplate.

The below example shows an online fashion retailer whose customer service chatbot checks order status and return eligibility - giving accurate real-time answers grounded in actual order data, not guesses.


Running the Gemini function calling loop with real customer questions,


It gives the following output showing function calls before each answer,

Customer: My order ORD-58291 was supposed to arrive today. Where is it?
  [Tool] get_order_status {"order_id": "ORD-58291"}
  [Data] {"status": "Out for delivery", "product": "Blue Denim Jacket...", "eta": "Today by 8pm"}
Gemini:   Great news! Your Blue Denim Jacket (Size M) from order ORD-58291
          is out for delivery with Delhivery and is expected to arrive today
          by 8pm. You will receive an SMS update when it is nearby!

Customer: Can I return my Kurta from order ORD-44102?
  [Tool] check_return_eligibility {"order_id": "ORD-44102"}
  [Data] {"eligible": True, "days_remaining": 3, "instructions": "Go to StyleHub app..."}
Gemini:   Yes, your Floral Kurta Set is eligible for return! You have 3 days
          left in your 7-day return window. Just go to StyleHub app > Orders
          > Return and free pickup will be arranged within 24 hours.

Customer: Check status of ORD-71839 and whether I can return it
  [Tool] get_order_status {"order_id": "ORD-71839"}
  [Tool] check_return_eligibility {"order_id": "ORD-71839"}
  [Data] {"status": "Processing", "expected_dispatch": "1 April 2025"}
  [Data] {"eligible": False, "reason": "Order has not been delivered yet"}
Gemini:   Your Leather Sneakers (ORD-71839) are still being processed and
          are expected to be dispatched by 1 April. Returns are only possible
          after delivery, so check back once you receive them!

# Third question: Gemini called BOTH tools simultaneously - efficient!

Gemini often calls multiple tools in parallel in a single response when it can see that multiple lookups are needed - this is more efficient than sequential tool calls. The SDK detects multiple function_call parts in one response content. Automatic function calling (set automatic_function_calling_config in GenerateContentConfig) removes the need to write the loop entirely - the SDK calls your Python functions automatically and returns only the final text answer. Use the manual loop when you need to log tool calls, add latency tracking, or apply business logic between the tool call and the result being sent back to Gemini.


 
  


  
bl  br