fix: repetition tool calls in gemini models #4686
Merged
+12
−9
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.
Modifications / 改动点
修复了
ProviderGoogleGenAI(Gemini) 适配器中导致工具调用无限循环的 Bug。在构建
role == "tool"的历史消息时,原代码错误地将tool_call_id当作了函数name传入,且没有显式绑定id到function_response中。这导致 Gemini API 无法正确识别工具执行结果,从而让模型认为任务未完成并陷入死循环。主要修改 (
astrbot/core/provider/sources/gemini_source.py):types.Part.from_function_response中使用真实的函数名 (message.get("name")),而不是 ID。part.function_response.id = message["tool_call_id"],确保工具返回结果能正确匹配到对应的调用请求。Screenshots or Test Results / 运行截图或测试结果
Before Fix / 修复前:

(日志显示模型不断重复调用
chip_build,无法识别工具返回结果,陷入死循环。)After Fix / 修复后:

(Gemini 正确识别了工具执行结果,并成功输出了最终总结文本,跳出了循环。)
Checklist / 检查清单
requirements.txt和pyproject.toml文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations inrequirements.txtandpyproject.toml.