refactor(gemini): replace counter-based tool call IDs with UUIDs #659
+119
−113
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
Replace the current counter-based tool call ID generation (
function_name,function_name-2, etc.) with UUID-based IDs to ensure uniqueness across multiple model calls within a session.Current Implementation Analysis
Current approach:
map[string]intto track function call countsfunction_name,function_name-2,function_name-3Problem:
Proposed Solution
1. Replace Counter with UUID Generation
Changes to
convFC()function:github.com/google/uuid(already in dependencies) to generate unique IDsNew ID format:
550e8400-e29b-41d4-a716-446655440000(standard UUID v4)2. Simplify Function Signatures
Since we no longer need to track counts, we can:
toolCallIDs map[string]intparameter from all functionsconvFC(),convCandidate(),convResponse()signaturesGenerate()andStream()methods3. Update Implementation
Files to modify:
gemini.go: Update ID generation logic, remove map trackinggemini_test.go: Update tests to expect UUID format instead of counter formatREADME.md: Update documentation with new UUID-based approachREADME_zh.md: Update Chinese documentationDetailed Changes
Code Changes
Add UUID import to
gemini.go:Simplify
convFC()function:Update function signatures:
convResponse(resp *genai.GenerateContentResponse) (*schema.Message, error)convCandidate(candidate *genai.Candidate) (*schema.Message, error)convFC(part *genai.Part) (*schema.ToolCall, error)Remove map initialization:
Generate(): Removemake(map[string]int)callStream(): RemovetoolCallIDs := make(map[string]int)lineUpdate comments: Replace counter-based explanations with UUID explanations
Test Changes
Update
TestDuplicateToolCallIDsto:TestUniqueToolCallIDs(more accurate name)func-2,func-3)Documentation Changes
README.md & README_zh.md:
Example update:
Benefits
✅ Session-wide uniqueness: UUIDs are globally unique, preventing conflicts across multiple model calls
✅ Simpler code: No need to maintain counter state or pass maps through function calls
✅ Industry standard: UUIDs are widely recognized and used for unique identifiers
✅ Better traceability: Each tool call has a truly unique identifier for debugging and logging
Breaking Changes
function_name-Nto UUIDImpact:
Implementation Steps
gemini.gowith UUID generation