Gemini function calling in the Gen AI SDK: automatic vs manual
Answer: With the Google Gen AI Python SDK you can pass a Python function directly as a tool, and it will be automatically called and responded by default. If you do not want automatic function calling, you can disable it with AutomaticFunctionCallingConfig(disable=True).
How the SDK builds the declaration
The Gemini cookbook says the SDK builds a FunctionDeclaration schema from your Python function by inspecting the function name, the docstring (used for the description), and parameter names and type annotations.
ANY mode
If function calling mode is ANY, the model will always return function call parts. With a Python function as a tool, the SDK keeps doing automatic function calling until it reaches the maximum remote calls, which defaults to 10.
Manual handling
Without automatic function calling, you have to call the function yourself, for example with if function_call.name == ... and **function_call.args.
See also
- ao-tools-tool-choice-across-providers
- ao-tools-openai-function-calling
- ao-tools-anthropic-tool-use-loop
- ao-tools-ollama-tool-calling
Claims
- id: C1 claim: Python functions are called automatically by default. source: S2 evidence: "You can pass a Python function directly and it will be automatically"
- id: C2 claim: ANY mode always returns function call parts. source: S2 evidence: "then the model will always return function call parts"
- id: C3 claim: The docstring becomes the description. source: S1 evidence: "Docstring: Used for the function's description."
Sources
- [S1] Function calling quickstart. google-gemini/cookbook (GitHub). https://github.com/google-gemini/cookbook/blob/main/quickstarts/Function_calling.ipynb . License: Apache-2.0. Accessed 2026-11-16.
- [S2] Google Gen AI Python SDK README. googleapis/python-genai (GitHub). https://github.com/googleapis/python-genai/blob/main/README.md . License: Apache-2.0. Accessed 2026-11-16.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: google-gemini/cookbook (GitHub), Function calling quickstart, Apache-2.0 (https://raw.githubusercontent.com/google-gemini/cookbook/main/LICENSE); googleapis/python-genai (GitHub), Google Gen AI Python SDK README, Apache-2.0 (https://raw.githubusercontent.com/googleapis/python-genai/main/LICENSE). Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: google-gemini/cookbook (GitHub), Function calling quickstart, Apache-2.0 (https://raw.githubusercontent.com/google-gemini/cookbook/main/LICENSE); googleapis/python-genai (GitHub), Google Gen AI Python SDK README, Apache-2.0 (https://raw.githubusercontent.com/googleapis/python-genai/main/LICENSE).
Cite this
iinventedlight. 2026. "Gemini function calling in the Gen AI SDK: automatic vs manual." iinventedlight Library, iil:note:c2cq7wt4, version of 2026-11-16. https://iinventedlight.com/library/notes/ao-tools-gemini-function-calling/. License: CC-BY-4.0.
@misc{iil_note_c2cq7wt4,
author = {{iinventedlight}},
title = {{Gemini function calling in the Gen AI SDK: automatic vs manual}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-16},
url = {https://iinventedlight.com/library/notes/ao-tools-gemini-function-calling/},
note = {Permanent ID iil:note:c2cq7wt4. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/ao-tools-gemini-function-calling.md.