Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Googleapis Python genai AutomaticFunctionCallingConfig Setup

From Leeroopedia
Knowledge Sources
Domains Function_Calling, Tool_Use
Last Updated 2026-02-15 00:00 GMT

Overview

Concrete tool for configuring automatic function calling behavior and tool invocation modes provided by the google-genai types module.

Description

AutomaticFunctionCallingConfig controls whether the SDK automatically executes function calls and feeds results back to the model. When enabled (default), the SDK handles the multi-turn function calling loop transparently. ToolConfig with FunctionCallingConfig controls the model's function calling mode (AUTO, ANY, NONE) and can restrict which functions are allowed. These configurations are set in GenerateContentConfig.

Usage

Set automatic_function_calling_config in the GenerateContentConfig to control the AFC loop. Disable AFC by setting disable=True when you want manual control over function execution. Set maximum_remote_calls to limit the number of automatic invocations (default: 10). Use ToolConfig to control whether the model must, may, or cannot call functions.

Code Reference

Source Location

  • Repository: googleapis/python-genai
  • File: google/genai/types.py
  • Lines: L4606 (AutomaticFunctionCallingConfig), L4424 (ToolConfig)

Signature

class AutomaticFunctionCallingConfig(_common.BaseModel):
    """Configuration for automatic function calling."""
    disable: Optional[bool] = None  # If True, disable AFC
    maximum_remote_calls: Optional[int] = 10  # Max auto calls
    ignore_call_history: Optional[bool] = None

class ToolConfig(_common.BaseModel):
    """Tool configuration shared for all tools."""
    function_calling_config: Optional[FunctionCallingConfig] = None
    retrieval_config: Optional[RetrievalConfig] = None

class FunctionCallingConfig(_common.BaseModel):
    """Config for function calling."""
    mode: Optional[FunctionCallingConfigMode] = None  # AUTO, ANY, NONE
    allowed_function_names: Optional[list[str]] = None

Import

from google.genai import types

I/O Contract

Inputs

Name Type Required Description
disable Optional[bool] No If True, disable automatic function calling
maximum_remote_calls Optional[int] No Max number of automatic calls (default 10)
mode Optional[FunctionCallingConfigMode] No AUTO, ANY, or NONE
allowed_function_names Optional[list[str]] No Restrict which functions model can call

Outputs

Name Type Description
AutomaticFunctionCallingConfig AutomaticFunctionCallingConfig AFC configuration for GenerateContentConfig
ToolConfig ToolConfig Tool behavior configuration for GenerateContentConfig

Usage Examples

Disable Automatic Function Calling

from google import genai
from google.genai import types

client = genai.Client(api_key="YOUR_API_KEY")

response = client.models.generate_content(
    model="gemini-2.0-flash",
    contents="What's the weather?",
    config=types.GenerateContentConfig(
        tools=[get_weather],
        automatic_function_calling_config=types.AutomaticFunctionCallingConfig(
            disable=True
        ),
    ),
)
# response.function_calls will contain the call to execute manually

Force Function Calling

response = client.models.generate_content(
    model="gemini-2.0-flash",
    contents="Tell me about the weather.",
    config=types.GenerateContentConfig(
        tools=[get_weather],
        tool_config=types.ToolConfig(
            function_calling_config=types.FunctionCallingConfig(
                mode="ANY"  # Force model to call a function
            )
        ),
    ),
)

Limit Automatic Calls

response = client.models.generate_content(
    model="gemini-2.0-flash",
    contents="Plan a trip to Paris.",
    config=types.GenerateContentConfig(
        tools=[get_weather, get_flights, get_hotels],
        automatic_function_calling_config=types.AutomaticFunctionCallingConfig(
            maximum_remote_calls=5  # Limit loop iterations
        ),
    ),
)

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment