fix(chat): strip functionCall.id from Gemini requests#84
Open
yhny1001 wants to merge 1 commit into
Open
Conversation
Gemini responses return a `functionCall.id`, which we persist verbatim in
`native.gemini` and echo back on the next tool-call turn. The Gemini
`generateContent` request API rejects that field ("Unknown name \"id\" at
'contents[N].parts[M].function_call'"), breaking agent tool-call loops.
Strip the response-only `id` from every `functionCall` part at the request
build boundary (covers native replay, content passthrough, and tool calls;
applies to both makersuite and vertexai). The id stays in the normalized
`tool_calls`, and Gemini pairs `functionResponse` by name, so pairing is
unaffected.
Co-authored-by: Cursor <cursoragent@cursor.com>
Owner
Contributor
Author
|
openai接口用gemini时,三方聚合公益站 |
Owner
|
看Gemini官方文档是需要回传id的,是第三方的问题吗 |
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.


背景 / 问题
通过 Gemini(makersuite / vertexai)跑带工具调用的 agent 时,第二轮回放会报:
导致工具调用循环(含子 agent)中断。
根因
functionCall带id(Gemini 3 尤甚)。归一化器读取该 id 用于匹配,同时把整段候选content原样存入native.gemini(normalizers.rs)。encode.rs::copy_native_continuation把native.gemini原样塞回消息,makersuite.rs::message_native_gemini_parts又原样取出当请求体 parts。generateContent请求端不接受functionCall.id(只在响应里返回),于是被拒。核心矛盾:Gemini 响应的 functionCall 带 id,但请求的 functionCall 不允许 id,而我们原样回放了。
修复
在
payload/makersuite.rs构建每条消息发往 Gemini 的 parts 出口处,统一剥掉functionCall.id(strip_function_call_ids)。一处出口覆盖原生回放、content 透传、工具调用三条路径,且 makersuite 与 vertexai 共用convert_messages,两种来源都生效。为什么安全
functionCall.id本就只存在于响应、请求端不接受,删除是符合 Gemini 契约的。tool_calls里做内部记账。functionResponse靠name配对,不靠 id,故工具调用/结果配对不受影响。改动符合的约定
makersuite_strips_function_call_id_from_replayed_native_parts,模拟带 id 的原生 Gemini functionCall 回放,断言请求里 id 被剥、name 保留。Test plan
cd src-tauri && cargo test --lib makersuiteUnknown name "id" ... function_callMade with Cursor