What is the recommended way of dealing with multiple functionCall requests?

When working against either the Flash or Pro endpoints, both of them will invoke tools we have configured correctly.

My question is: What is the recommended approach to take if a model sends a response that consists of, say, 1 text part and 3 functionCall parts? As I see it, we’ve two choices:

  1. We run all 3 function calls and then send back a functionResponse with 3 parts in the array.
  2. We send a single functionResponse back 3 times, one for each request.

Note that we’re using model.generateContent in the TypeScript API, not the ‘chat’ API as we need to manage the context history ourselves.

Cheers,

Rich

@Richard_Davey,

depending on your application, if you want to call all the 3 function calls simultaniously, you can do so in a loop and add the responses to a list/array and send back to the model

following is an pseudo example for this:

for fc in tool_call.function_calls:
                    function_response = types.FunctionResponse(
                        id=fc.id,
                        name=fc.name,
                        response={ "result": "ok" } # simple, hard-coded function response
                    )
                    function_responses.append(function_response)

but if you want the output of 1st function call to use as input for the next you can use compositional function calling(Function Calling with the Gemini API  |  Google AI for Developers) .