From the course: Gemini API: Tool and Function Calling

Single-turn function call

- [Instructor] Now that we understand how to give functions as tools to our models and use the response from the model to call functions, in this section, we'll be looking at how function calling is used in applications, starting with a single turn function call. A single turn function call is the simplest and most common workflow for integrating external tools with the Gemini API. It consists of a two step process that begins with a single user request and ends with a single final response from the model. Here is how the single turn flow goes. First, the user initiates the process by prompting the model with a query that implicitly or explicitly requires a tool operation. Your application sends this prompt to the Gemini model, along with the predefined function declarations. The model then analyzes the user's request and the available tools. It then discovers a single tool from the list of tools provided that can provide all the necessary information. The model then returns information about this tool in a function call object. In the third step, your application receives the function call object and uses this information to call the corresponding local function. In most real world scenarios, this function will likely make an API request to a third party service or query an internal file system or database. Once the function completes its task and returns the result of its operation, your application then packages this data into a function response object. In the final step, your application sends the function response back to the model in a new call to the Gemini API, along with the original prompt and initial function call object. With this new information from the function's results, the model can then synthesize a final coherent and user-friendly textual response. This response is the final answer to the user and thus completes the single turn conversation. An example of this process is a user asking your application what's the weather like in Tokyo? The Gemini model then calls a get_current_weather tool you're provided, gets the temperature from the application, and then a final text response. In a single turn function calling operation, a single tool call is all that's needed to fully answer the question.

Contents