Skip to content

fix(gemini): accept snake_case function_call/function_response parts - #662

Merged
jpr5 merged 1 commit into
mainfrom
fix/gemini-snake-case-function-parts
Dec 3, 2026
Merged

jpr5 merged 1 commit into
mainfrom
fix/gemini-snake-case-function-parts

Conversation

@jpr5

@jpr5 jpr5 commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Fixes #658

The Gemini API takes the proto field names in snake_case as well as camelCase, and LiteLLM's Gemini / Vertex AI transformation (so Google ADK agents on LiteLlm) sends tool calls and results as function_call / function_response. The request parser in src/gemini.ts only looked at functionCall / functionResponse, so a snake_case tool result turned into an empty user turn and hasToolResult / toolResultContains / userMessage fixtures didn't match (404).

The fix maps function_call / function_response onto the camelCase names before the parts are read, in both the user and model branches of geminiToCompletionRequest. A part that already uses camelCase is returned as the same object, so camelCase requests behave exactly as before. If a part somehow has both spellings, camelCase wins.

Red / green

New test src/__tests__/gemini-snake-case-parts.test.ts starts a real aimock server with the fixture from the issue and sends the issue's three-turn request to both streamGenerateContent?alt=sse and generateContent, once with snake_case parts and once with camelCase (control).

Before the fix (unmodified main):

× ... > streamGenerateContent matches a tool-result fixture with snake_case parts
  → expected 404 to be 200 // Object.is equality
× ... > generateContent matches a tool-result fixture with snake_case parts
  → expected 404 to be 200 // Object.is equality
✓ ... > streamGenerateContent matches a tool-result fixture with camelCase (control) parts
✓ ... > generateContent matches a tool-result fixture with camelCase (control) parts
Tests  2 failed | 2 passed (4)

After the fix:

✓ ... > streamGenerateContent matches a tool-result fixture with snake_case parts
✓ ... > generateContent matches a tool-result fixture with snake_case parts
✓ ... > streamGenerateContent matches a tool-result fixture with camelCase (control) parts
✓ ... > generateContent matches a tool-result fixture with camelCase (control) parts
Tests  4 passed (4)

I also ran the issue's repro (empty fixtures, fixture added through /__aimock/fixtures, then the streaming request) against the CLI:

published 1.49.0:   snake_case: HTTP 404 (no ANSWER)   camelCase: HTTP 200 (ANSWER in body)
this branch (dist): snake_case: HTTP 200 (ANSWER in body)   camelCase: HTTP 200 (ANSWER in body)

Not in this PR

  • Gemini Live (src/ws-gemini-live.ts) reads the same part keys, but a snake_case Live client would also send client_content / tool_response / function_responses at the message level, which that handler doesn't read either. Fixing only the parts there wouldn't help anyone, so I left Live alone.
  • The issue also mentions inline_data / file_data. The request parser doesn't read inlineData / fileData either, so both spellings are already treated the same way and there is nothing to fix for matching.

@pkg-pr-new

pkg-pr-new Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@copilotkit/aimock@662

commit: b80d5a7

The Gemini API accepts proto field names in snake_case, and LiteLLM's
Gemini/Vertex transformation sends tool calls and results that way.
The request parser only read functionCall/functionResponse, so a
snake_case tool result became an empty user turn and tool-result
fixtures did not match (404). Map the snake_case keys onto the
camelCase names before parsing; camelCase parts pass through
unchanged.

Fixes #658
@jpr5
jpr5 force-pushed the fix/gemini-snake-case-function-parts branch from 4494be7 to b80d5a7 Compare December 3, 2026 23:33
@jpr5
jpr5 merged commit 7c04cf0 into main Dec 3, 2026
30 checks passed
@jpr5
jpr5 deleted the fix/gemini-snake-case-function-parts branch December 3, 2026 23:44
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.

Gemini: snake_case function_call / function_response parts are ignored, so tool-result fixtures don't match

1 participant