fix(gemini): preserve assistant tool calls during history conversion#8742
fix(gemini): preserve assistant tool calls during history conversion#8742Rat0323 wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the Gemini provider source to automatically disable the thinking configuration when tools are active, preventing API errors since Gemini does not support both simultaneously. The reviewer suggested adding a warning log when this automatic disabling occurs to improve observability and prevent confusion, which is a valuable improvement.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| if tool_list: | ||
| thinking_config = None |
There was a problem hiding this comment.
When thinking_config is automatically disabled due to the presence of tools, it is highly recommended to log a warning message. This provides crucial observability for users and developers, preventing confusion as to why the model's thinking/reasoning mode is not active when plugins or tools are triggered.
| if tool_list: | |
| thinking_config = None | |
| if tool_list and thinking_config: | |
| logger.warning("[Gemini] Thinking config is automatically disabled because tools are active for this request.") | |
| thinking_config = None |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Given that
tool_listmay beNoneor different iterable types over time, consider making the condition more explicit (e.g.,if tool_list is not None and len(tool_list) > 0) to avoid surprising behavior iftool_listchanges shape in future refactors. - Since this override changes user-visible behavior when tools are present, it might be safer to route this through a small helper (e.g.,
disable_thinking_if_tools) so the intent is centralized and future changes to tool handling don’t accidentally bypass this constraint.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Given that `tool_list` may be `None` or different iterable types over time, consider making the condition more explicit (e.g., `if tool_list is not None and len(tool_list) > 0`) to avoid surprising behavior if `tool_list` changes shape in future refactors.
- Since this override changes user-visible behavior when tools are present, it might be safer to route this through a small helper (e.g., `disable_thinking_if_tools`) so the intent is centralized and future changes to tool handling don’t accidentally bypass this constraint.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
54c1a72 to
851b526
Compare
|
是否有相关文档链接,以及报错日志?》 |
|
Superseded by the latest revision. This earlier comment reflected the initial hypothesis that explicit The current confirmed fix is focused on Gemini history conversion: assistant messages that contain both |
|
Updated validation note. The useful part of the earlier log review is the pre-patch tool-loop evidence: in a PR-summary request, Gemini returned assistant content together with a tool call, then later turns repeated After narrowing the PR, I no longer use these logs as evidence for a universal The latest revision adds focused regression tests for assistant text/list content with |
|
Superseded by the latest revision. This note referred to the earlier broader patch. The current PR no longer claims a universal Gemini thinking/tools conflict and is now verified with focused unit tests for Gemini history conversion. |
|
Updated this PR after re-checking the evidence and running a minimal reproduction against the PR base. The confirmed issue is Gemini history conversion: when an assistant message contains both I also re-tested explicit This revision now focuses on the verified serialization bug and adds regression tests for assistant text/list content with Verification: uv run python -m pytest tests/test_gemini_source.py -q
uv run ruff check astrbot/core/provider/sources/gemini_source.py tests/test_gemini_source.py |
…e to active tools
…multaneously to avoid tool loop
bb8b34e to
413d4b9
Compare
|
CI note for the latest revision: The current failing
This PR currently only changes:
After comparing the latest green master run and this failed PR run, the important difference appears to be dependency resolution timing. The green master CI run installed So I am keeping this PR focused on the Gemini history-conversion regression instead of adding unrelated dashboard/test fixes here. I also tried to rerun the failed check, but GitHub requires repository admin permission for that action. |
|
Closing this in favor of #8787. The original hypothesis in this PR was narrowed after validation, so I opened a clean replacement PR with a single focused commit for the confirmed Gemini history-conversion bug. |
Summary
This PR fixes Gemini history conversion when an assistant message contains both normal content and
tool_calls.Previously,
_prepare_conversation()handled assistant messages with mutually exclusiveif / elif / elifbranches. If an assistant message had text content, or list content such as a think/text part, thetool_callsbranch was skipped. The next Gemini request could then contain a tool response without the corresponding assistant function-call part, which can make Gemini repeat the same tool call or request invalid tool names in later turns.Changes
ModelContent.partslist.tool_calls: nullas empty, so OpenAI-style assistant messages with a null field do not crash local conversion.tool_callstool_callstool_calls: nullNotes
This PR was narrowed after re-checking the evidence. The earlier wording about a universal Gemini
thinking_config+ tools incompatibility was too broad, so that part has been removed from the patch and from the main claim here. This PR now focuses on the confirmed serialization bug.Verification