Skip to content

fix(model): generate unique ids for tool calls the provider sends without one - #3675

Closed
pcbeingused33 wants to merge 1 commit into
agentscope-ai:mainfrom
pcbeingused33:fix/openai-stream-tool-calls-without-id
Closed

pcbeingused33 wants to merge 1 commit into
agentscope-ai:mainfrom
pcbeingused33:fix/openai-stream-tool-calls-without-id

Conversation

@pcbeingused33

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

main (73cb2da)

Description

When a provider sends a tool call without an id, the parsers generated one as "tool_call_" + System.currentTimeMillis() ("streaming_" + ... for streamed OpenAI-compatible chunks). Two calls parsed in the same millisecond get the same id. Gemini function calls never carry an id, so parallel function calls hit this routinely, and ToolCallsAccumulator keys builders by id, so the calls are merged into one (their arguments concatenate into invalid JSON and fall back to {}) or their results collide.

This replaces the millisecond suffix with UUID.randomUUID() in GeminiResponseParser (function calls and server-side tool calls) and OpenAIResponseParser (streaming and non-streaming fallbacks). Ids supplied by the provider are unchanged.

Tests: GeminiResponseParserTest.testParseParallelToolCallsWithoutIdsGetDistinctIds and OpenAIStreamingToolCallTest.testParallelStreamingToolCallsWithoutIds (two id-less calls in one chunk, also run through ToolCallsAccumulator). The collision needs both ids in one millisecond, so each test repeats 50 times; both fail on main and pass here. The openai and gemini module suites pass (579 and 169 tests, 0 failures) and mvn spotless:apply leaves no diff.

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test for the openai and gemini modules)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.) (no docs affected: internal id generation only)
  • Code is ready for review

Drafted with Claude Code.

…hout one

Gemini function calls carry no id and the OpenAI-compatible parser falls
back to a generated id when a streamed or non-streamed tool call has none.
Both fallbacks were "tool_call_" + System.currentTimeMillis(), so parallel
calls parsed in the same millisecond got the same id and were merged by
ToolCallsAccumulator (or had their results collide).

Use a random UUID suffix instead.
@jujn jujn closed this Oct 22, 2026
iluv7 added a commit to iluv7/agentscope-java that referenced this pull request Nov 17, 2026
…on invalid combos (agentscope-ai#4220)

Gemini 4 models (gemini-4-argon, gemini-4-carbon) use thinkingLevel instead
of thinkingBudget and reject thinking_budget outright. The adapter sent the
budget-era shape unconditionally whenever a budget was set, so requests
against Gemini 4 failed, zero budgets broke budget-era models, and thinking
could not be enabled on Gemini 4 at all.

- GenerateOptions: add tri-state includeThoughts and thinkingLevel options
- GeminiChatModel: model-aware thinking wiring (gate on argon/carbon),
  mirrored from agentscope-python PR agentscope-ai#3523/agentscope-ai#3675
- Fail fast with a clear error for budget on Gemini 4 / level on budget-era
  models / unsupported levels, instead of an opaque remote error
- Wire-level tests covering the mapping table, defaults merge, and
  stream-path fail-fast

Co-Authored-By: Claude Code <[email protected]>
jujn pushed a commit to iluv7/agentscope-java that referenced this pull request Nov 17, 2026
…on invalid combos (agentscope-ai#4220)

Gemini 4 models (gemini-4-argon, gemini-4-carbon) use thinkingLevel instead
of thinkingBudget and reject thinking_budget outright. The adapter sent the
budget-era shape unconditionally whenever a budget was set, so requests
against Gemini 4 failed, zero budgets broke budget-era models, and thinking
could not be enabled on Gemini 4 at all.

- GenerateOptions: add tri-state includeThoughts and thinkingLevel options
- GeminiChatModel: model-aware thinking wiring (gate on argon/carbon),
  mirrored from agentscope-python PR agentscope-ai#3523/agentscope-ai#3675
- Fail fast with a clear error for budget on Gemini 4 / level on budget-era
  models / unsupported levels, instead of an opaque remote error
- Wire-level tests covering the mapping table, defaults merge, and
  stream-path fail-fast

Co-Authored-By: Claude Code <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants