Repository navigation
Description
Describe the bug
Gemini function calls without an explicit ID can collide inside GeminiResponseParser, causing separate tool calls to be merged and rejected before execution. A request to look up Tokyo and Paris weather can therefore execute neither lookup, even though both function calls contain valid arguments.
Reproduced on 2.1.0-SNAPSHOT, main f9d717ec56201404067d26b55f4308c3ef69ef16.
To reproduce
-
Construct a Google GenAI
GenerateContentResponsecontaining these two parts:[ {"functionCall":{"name":"get_weather","args":{"city":"Tokyo"}}}, {"functionCall":{"name":"get_weather","args":{"city":"Paris"}}} ] -
Pass the response through
GeminiResponseParser.parseResponse()andReasoningContext.processChunk(), as the normal model/agent path does. Repeat the pair in a short loop to exercise the clock collision. -
Inspect
buildFinalMessage().getContentBlocks(ToolUseBlock.class), or execute the response through aReActAgentwith a recordingget_weathertool.
Expected: two independent calls with their original arguments; both tools execute.
Observed in the local fixture: 99 of 100 parser/accumulator attempts collapsed the two calls into one malformed call. In 20 agent runs, the tool was invoked zero times in every run. These are local reproduction counts, not production failure rates. Supplying distinct provider IDs makes both controls pass.
No provider API access is needed: the fixture uses the real SDK response types, parser, accumulator and Agent, with a local model fixture.
Cause
GeminiResponseParser.parseToolCall() falls back to:
functionCall.id().orElse("tool_call_" + System.currentTimeMillis())Calls parsed in the same millisecond receive the same ID. ToolCallsAccumulator then treats them as fragments of one call and concatenates their JSON arguments into {"city":"Tokyo"}{"city":"Paris"}. The malformed-arguments guard correctly refuses to execute that corrupted call and sends an error result to the next reasoning step.
The provider's FunctionCall.id is optional in the Google API, so these are valid inputs. Both streaming and non-streaming Gemini paths use this parser.
Proposed change
Generate a unique fallback ID for each independent local function call while retaining provider-supplied IDs. Add parser/accumulator and actual Agent execution regressions, including the distinct-provider-ID control. I am preparing this focused fix.
Activity
fix(gemini): keep generated function call IDs distinct (agentscope-ai…