fix(kosong): make Gemini (google-genai/vertexai) tool-calling work#1360
Open
powerfooI wants to merge 1 commit into
Open
fix(kosong): make Gemini (google-genai/vertexai) tool-calling work#1360powerfooI wants to merge 1 commit into
powerfooI wants to merge 1 commit into
Conversation
The Google GenAI provider built function declarations and content parts with snake_case keys (function_declarations, parameters_json_schema, function_call, function_response, thought_signature). The @google/genai SDK expects camelCase, so it silently dropped those keys and sent empty tool specs, causing Gemini to return MALFORMED_FUNCTION_CALL. Separately, tool-call thought_signature extras captured from responses were dropped in the agent-core tool-call event pipeline (LoopToolCallEvent had no extras; the context/transcript reconstructors rebuilt tool calls without them), so multi-turn Gemini 3.x tool use failed with "missing thought_signature". - kosong/google-genai: emit camelCase functionDeclarations / parametersJsonSchema / functionCall / functionResponse / thoughtSignature. - agent-core: add extras to LoopToolCallEvent, dispatch toolCall.extras, and copy extras when rebuilding tool calls in ContextMemory and the transcript service. - Update kosong google-genai tests to assert the camelCase the SDK requires. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: ce8bae6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Related Issue
No existing issue — this is a clear, reproducible bug fix with a focused diff (allowed without prior discussion per CONTRIBUTING). Problem described below.
Problem
Gemini tool-calling is broken for both
google-genaiandvertexai:Empty tool specs →
MALFORMED_FUNCTION_CALL. The provider builds function declarations with snake_case keys (function_declarations,parameters_json_schema) and content parts withfunction_call/function_response/thought_signature. The@google/genaiSDK expects camelCase, so it drops these keys and sends empty tool objects (tools: [{}]) on the wire. Gemini then responds withfinishReason: MALFORMED_FUNCTION_CALLand empty content.Multi-turn fails with
missing thought_signature. Once tools are populated, Gemini 3.x requires thethoughtSignatureto be echoed back on later turns. The provider captures it intoToolCall.extras.thought_signature_b64, butLoopToolCallEventhas noextrasfield and theContextMemory/ transcript reconstructors rebuild tool calls without it, so the signature is lost and continuations are rejected.The existing
google-genaitests mockgenerateContentStreamand assert the snake_case object passed into the SDK, so the real serialization was never exercised and the bug went uncaught.What changed
packages/kosong/src/providers/google-genai.ts— emit the camelCase keys the SDK expects:functionDeclarations,parametersJsonSchema,functionCall,functionResponse,thoughtSignature.packages/agent-core— addextrastoLoopToolCallEvent, dispatchtoolCall.extrasindispatchToolCall, and copyextraswhen rebuilding tool calls inContextMemory(agent/context) and the transcript service, sothoughtSignatureround-trips across turns.packages/kosong/test/google-genai.test.ts— updated to assert the camelCase keys the SDK requires.Verified end-to-end against a real Gemini endpoint (
gemini-3.1-pro-preview): multi-turn tool-using tasks (create file → shell command → read back) now complete for bothgoogle-genaiandvertexai.pnpm typecheck,pnpm lint(0 errors), and the kosong/agent-core test suites pass.Checklist
gen-changesetsskill, or this PR needs no changeset. (changeset added manually)gen-docsskill, or this PR needs no doc update. (no user-facing doc change)