function_calling_utilities

A way for a generative AI model to request a function that your application provides. The utilities define the function's inputs, send that description to the model, and help process the model's request.

In plain words
What is it for?
Use it when a model needs current or private information from databases, APIs, search tools, or other application functions.
Why use it?
It avoids manually writing the schema, request parsing, argument checking, and function-call response handling needed to connect a model to outside systems.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/altaidevorg/rules-for-ai/function_calling_utilities
Clone the repo
git clone --depth 1 https://github.com/altaidevorg/rules-for-ai
Per session 26 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 4,432 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00026 $0.04432
Opus 5 $0.00013 $0.02216
Sonnet 5 $0.00005 $0.00886
Haiku 4.5 $0.00003 $0.00443

Measured yesterday against content hash 03e37eb48c55, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

function_calling_utilities scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

examples/google-genai/function_calling_utilities.mdc · 311 lines

How it starts

The opening of the file, as written. The whole thing — 311 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Chapter 5: Function Calling Utilities

In Chapter 4: Chat / AsyncChat, we explored how to manage conversational history using the Chat object. However, many advanced AI applications require the model to interact with the external world—fetching real-time data, accessing databases, or calling other APIs. This chapter delves into the Function Calling Utilities, a set of features designed to seamlessly integrate external tools and functions with the generative model.

Motivation and Use Case

Generative models are powerful but inherently limited to the information they were trained on and the context provided in the prompt. Function calling allows the model to request the execution of predefined functions (tools) when it determines they are needed to fulfill a user's request. This bridges the gap between the model's knowledge and real-time or proprietary information.

Manually handling this process involves:

  1. Defining the function's interface (name, description, parameters, types) in a specific JSON schema format.
  2. Passing this schema to the model.
  3. Parsing the model's response to detect a function call request.
  4. Extracting the function name and arguments.
  5. Validating and potentially coercing arguments from JSON types to Python types.
  6. Executing the corresponding Python function.
  7. Formatting the function's return value into a specific JSON response format.
  8. Sending this response back to the model to continue the generation.

This cycle is complex and repetitive. The Function Calling Utilities in google-genai abstract away much of this complexity, especially through automatic schema generation and invocation handling.

Central Use Case: You want the model to answer questions about current weather conditions. Since the model's training data is not real-time, you need to provide it with a tool (a Python function) that can fetch live weather data.

# Assuming 'client' is configured
from google.genai import types

# Define the Python function the model can call
def get_current_weather(location: str) -> str:
    """Returns the current weather for a specified location.

    Args:
        location: The city and state, e.g., "Boston, MA".
    """
    # In a real application, this would call a weather API
    print(f"--- Tool: Called get_current_weather(location='{location}') ---")
    if "boston" in location.lower():
        return "The weather in Boston is sunny and 75°F."
    else:
        return f"Sorry, I don't have weather information for {location}."

# Pass the function directly as a tool
# The SDK automatically generates the schema and handles the call cycle
response = client.models.generate_content(
    model='gemini-1.5-flash', # Use a model supporting function calling
    contents="What's the weather like in Boston right now?",
    config=types.GenerateContentConfig(
        tools=[get_current_weather] # Pass the function object
    )
)

# The response contains the final text after the function call
print(f"\nAI: {response.text}")

In this example, the SDK inspects get_current_weather, creates the necessary FunctionDeclaration schema, sends it to the model, detects the FunctionCall in the model's intermediate response, executes get_current_weather with the arguments provided by the model, sends the result back as a FunctionResponse, and returns the final, user-facing text generated by the model based on the weather information.

Read the full file on GitHub · 311 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 311 lines · 26 tokens per session scan A 03e37eb48c55

Subscribe to this mod's changes

function_calling_utilities is a cursor rule published in the GitHub repository altaidevorg/rules-for-ai (2 stars, last pushed 1y ago), licensed MIT. It adds 26 tokens to every session and 4,432 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.