To bypass automatic calling, manually declare a function using types.FunctionDeclaration, pass it via types.Tool, and handle the response.function_calls by executing the function and passing a types.Part.from_function_response back to the model.
from google.genai import types
function = types.FunctionDeclaration(
name='get_current_weather',
description='Get the current weather in a given location',
parameters_json_schema={
'type': 'object',
'properties': {
'location': {
'type': 'string',
'description': 'The city and state, e.g. San Francisco, CA',
}
},
'required': ['location'],
},
)
tool = types.Tool(function_declarations=[function])
response = client.models.generate_content(
model='gemini-3.5-flash',
contents='What is the weather like in Boston?',
config=types.GenerateContentConfig(tools=[tool]),
)
# Handle the function call manually
function_call_part = response.function_calls[0]
# ... execute function ...
function_response_part = types.Part.from_function_response(
name=function_call_part.name,
response={'result': 'sunny'},
)
function_response_content = types.Content(role='tool', parts=[function_response_part])
# Send response back to model
response = client.models.generate_content(
model='gemini-3.5-flash',
contents=[
user_prompt_content, # original user prompt
response.candidates[0].content, # the model's function call
function_response_content, # your function result
],
config=types.GenerateContentConfig(tools=[tool]),
)