Adapt parallel Gemini tool results to CometAPI functionResponse parts

Moving a Gemini tool loop from Google’s Interactions examples to CometAPI’s native Gemini endpoint is not just a change of URL. The adapter must change how it collects calls and serializes their results.

In Google’s parallel function-calling example, the application iterates interaction.steps and selects function_call steps. A preceding history example uses function_result with name and call_id. Those are Interactions representations—not native Gemini functionResponse parts. The parallel example shows requested calls, not a completed concurrent tool run or a multi-call result fan-in.

For the destination, CometAPI’s generating-content contract supplies the relevant requirements: preserve the preceding model content, return a corresponding functionResponse for every functionCall, match the name and returned id, and retain opaque thoughtSignature data when present.

The adapter decision: keep tool execution separate from the CometAPI serializer, and collect the complete result set before continuing the model turn. That is a design recommendation derived from the two documented representations, not a claim that CometAPI runs tools for you.

A practical implementation boundary is:

  1. Capture the whole call set. On the CometAPI native path, retain the preceding model content intact and collect every returned functionCall, including its name, arguments, and id when returned. Do not rebuild the model content from just the fields your runner understands; that risks losing opaque signatures.
  2. Run only authorized tools. Apply the application’s own permission checks before dispatch. A model request is not an authorization grant. Choose sequential or concurrent execution in the runner; the presence of several calls does not establish how they execute.
  3. Correlate before serializing. Associate each outcome with its originating call rather than with its position in the completion queue. Build native functionResponse parts using the matching name and returned id. Keep any Interactions call_id metadata distinct from the destination’s field representation rather than copying step objects into native parts.
  4. Check completeness, then continue. As an application-side guard, require one corresponding response per returned call. Stop the continuation if a result is missing or cannot be matched. Define failed-tool handling explicitly rather than silently dropping that call or reporting success. Send the preserved model content and native result parts through CometAPI only after the mapping is complete.

For an adapter test, use two calls whose tools finish in reverse order. The proposed pass condition is that both responses still match their originating calls and the preserved model content remains unchanged. A second fixture can omit one result: the local completeness guard should refuse to submit that partial turn. These are suggested tests, not reported execution results or claims about gateway rejection behavior.

The important distinction is multiple requested calls versus a valid native continuation. Google’s example helps identify the former; CometAPI’s contract determines the latter. Removing the CometAPI serialization step would leave a tool runner, but not the adapter needed for this migration. This advice is specific to the documented Gemini representations; it does not establish another model’s support, call ordering, tool-mode equivalence, or automatic concurrent execution.

For a creative-production tool loop, I would add an asset-revision check before the native serializer. Correct call pairing does not by itself establish that the tool results describe the same version of an image.

Consider a hypothetical runner with two read-only tools: one reports pixel dimensions and another returns a crop-safe region. If the source image changes between their reads, both calls could finish successfully and still produce an unusable combination: dimensions from revision A and crop coordinates from revision B. A complete result set would not catch that mismatch.

My application-side policy would be to pin an immutable asset revision before dispatch and retain that revision alongside each call’s execution record. Before building the Gemini functionResponse parts, check both call correlation and asset consistency. If the revisions differ, stop the continuation and resolve the stale input rather than presenting the combined measurements as one coherent result. Keep this asset bookkeeping separate from the provider’s call identifiers; it must not replace the matching name or returned id required by the CometAPI native Gemini contract.

An additional adapter fixture could return two correctly paired, successful results with deliberately different asset revisions. The expected outcome would be a local consistency failure, not a submitted model turn. This is a proposed production guard, not a documented Gemini validation feature or a claim about image-tool execution support.