[ ABORT TO HUD ]
SEQ. 1
SEQ. 2
SEQ. 3
Function Calling (Tools)
⚙️ Structured Outputs & Tools 15m 300 BASE XP⌨ HANDS-ON LAB
Orchestrating Deterministic Tool Execution
Function Calling empowers Gemini to act as an intelligent orchestrator. The model does not execute foreign code inside its own sandbox; instead, it outputs structured call signatures with typed parameters that your application executes securely.
Tool Configuration Modes
- AUTO: The model autonomously decides whether to call a tool or respond with natural language.
- ANY: Forces the model to select and invoke at least one tool from the supplied list.
- NONE: Prohibits tool invocation, enforcing plain text generation.
from google import genai
from google.genai import types
def get_exchange_rate(base_currency: str, target_currency: str) -> dict:
"""Retrieves real-time foreign currency exchange rates."""
rates = {"USD:GBP": 0.78, "GBP:USD": 1.28, "EUR:GBP": 0.85}
key = f"{base_currency}:{target_currency}"
return {"pair": key, "rate": rates.get(key, 1.0)}
client = genai.Client()
# Pass native Python functions directly to tools
response = client.models.generate_content(
model="gemini-2.0-flash",
contents="Convert 5,000 GBP to USD at current rates.",
config=types.GenerateContentConfig(
tools=[get_exchange_rate],
tool_config=types.ToolConfig(
function_calling_config=types.FunctionCallingConfig(
mode=types.FunctionCallingConfigMode.AUTO
)
)
)
)
# Handle tool call and return response
if response.function_calls:
call = response.function_calls[0]
print(f"Invoking {call.name} with args: {call.args}")
⌨ HANDS-ON LABInvoke Gemini with Structured Function Calling Tools
⭐ +150 XPProvide a JSON schema tool definition to Gemini 2.0 Flash and extract structured arguments for API dispatch.
1Dispatch a prompt accompanied by a get_stock_quote function declaration.
OBJECTIVE 1 / 1 — type "hint" if stuck
SYNAPSE VERIFICATION
QUERY 1 // 2
When using Function Calling, who actually executes the external API call?
Vertex AI backend
Google Cloud Functions
Your application code
The Gemini model directly