1.3 KiB
1.3 KiB
Function Calling Patterns
Complete guide to implementing function calling (tool use) with Gemini API.
Basic Pattern
- Define function declarations
- Send request with tools
- Check if model wants to call functions
- Execute functions
- Send results back to model
- Get final response
Function Declaration Schema
{
name: string, // Function name (no spaces)
description: string, // What the function does
parametersJsonSchema: { // Subset of OpenAPI schema
type: 'object',
properties: {
[paramName]: {
type: string, // 'string' | 'number' | 'boolean' | 'array' | 'object'
description: string, // Parameter description
enum?: string[] // Optional: allowed values
}
},
required: string[] // Required parameter names
}
}
Calling Modes
- AUTO (default): Model decides when to call
- ANY: Force at least one function call
- NONE: Disable function calling
Parallel vs Compositional
Parallel: Independent functions run simultaneously Compositional: Sequential dependencies (A → B → C)
Gemini automatically detects which pattern to use.