Module: LLM::Google::Utils

Defined in:
lib/llm/providers/google/utils.rb

Instance Method Summary collapse

Instance Method Details

#tool_id(part:, cindex:, pindex:) ⇒ String

Returns a stable internal tool-call ID for Gemini function calls.

Gemini responses may omit a direct tool-call ID, but llm.rb expects one for matching pending tool calls with tool returns across streaming and normal completion flows.

When Gemini provides a thoughtSignature, that value is used as the basis for the ID. Otherwise the ID falls back to the candidate and part indexes, which are stable within the response.

Parameters:

  • part (Hash)

    A Gemini content part containing a functionCall.

  • cindex (Integer)

    The candidate index for the tool call.

  • pindex (Integer)

    The part index for the tool call within the candidate.

Returns:

  • (String)

    Returns a stable internal tool-call ID.



24
25
26
27
28
# File 'lib/llm/providers/google/utils.rb', line 24

def tool_id(part:, cindex:, pindex:)
  signature = part["thoughtSignature"].to_s
  return "google_#{signature}" unless signature.empty?
  "google_call_#{cindex}_#{pindex}"
end