Gemini Model Implementation Regression from v0.3.0 -> v0.5.4 #647

Closed
opened 2026-02-16 10:20:03 -05:00 by yindo · 1 comment
Owner

Originally created by @tushverma on GitHub (Sep 14, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues Dify issues & Dify Official Plugins, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.8.1

Plugin version

0.5.4

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

REGRESSION #1: v0.3.0 → v0.4.0

ToolPromptMessage Role Change

File: llm-v0.4.0.pyLines: 468-477Impact: CRITICAL

Change:

v0.3.0 (WORKING) - line 382

elif isinstance(message, ToolPromptMessage):
return types.Content(
role="function",
parts=[types.Part.from_function_response(...)]
)

v0.4.0 (BROKEN) - line 472

elif isinstance(message, ToolPromptMessage):
return types.Content(
role="user", #
parts=[types.Part.from_function_response(...)]
)

Root Cause: Tool response messages are now sent as "user" messages instead of "function" messages.

Impact on Agents:

  • False answers: Model interprets tool outputs as user questions
  • Ignoring tool calls: Model loses context of tool call/response cycle
  • Breaking instruction following: Model treats tool responses as new user instructions

REGRESSION #2: v0.5.1 → v0.5.2

Thinking Tag Removal

File: llm-v0.5.2.pyLines: 463-464Impact: CRITICAL

Change: Centralized thinking tag removal

NEW in v0.5.2 - _build_text_parts function

def _build_text_parts(_content: str | TextPromptMessageContent) -> List[types.Part]:
text_parts = []
if isinstance(_content, TextPromptMessageContent):
_content = _content.data
if message.role == PromptMessageRole.ASSISTANT:
_content = re.sub(r"^.?\s", "", _content, count=1, flags=re.DOTALL)
# STRIPS ALL THINKING CONTENT FROM ASSISTANT MESSAGES
if _content:
text_parts.append(types.Part.from_text(text=_content))
return text_parts

Root Cause: All tags are now stripped from assistant messages during processing, removing crucial reasoning context.

Impact on Agents:

  • False answers: Reasoning chains are broken
  • Ignoring instructions: Chain-of-thought context is lost
  • Degraded performance: Model can't see its own reasoning process

✔️ Error log

No response

Originally created by @tushverma on GitHub (Sep 14, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [Dify issues](https://github.com/langgenius/dify/issues) & [Dify Official Plugins](https://github.com/langgenius/dify-official-plugins/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.8.1 ### Plugin version 0.5.4 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce REGRESSION #1: v0.3.0 → v0.4.0 ToolPromptMessage Role Change File: llm-v0.4.0.pyLines: 468-477Impact: CRITICAL Change: # v0.3.0 (WORKING) - line 382 elif isinstance(message, ToolPromptMessage): return types.Content( role="function", parts=[types.Part.from_function_response(...)] ) # v0.4.0 (BROKEN) - line 472 elif isinstance(message, ToolPromptMessage): return types.Content( role="user", # parts=[types.Part.from_function_response(...)] ) Root Cause: Tool response messages are now sent as "user" messages instead of "function" messages. Impact on Agents: - ❌ False answers: Model interprets tool outputs as user questions - ❌ Ignoring tool calls: Model loses context of tool call/response cycle - ❌ Breaking instruction following: Model treats tool responses as new user instructions --- REGRESSION #2: v0.5.1 → v0.5.2 Thinking Tag Removal File: llm-v0.5.2.pyLines: 463-464Impact: CRITICAL Change: Centralized thinking tag removal # NEW in v0.5.2 - _build_text_parts function def _build_text_parts(_content: str | TextPromptMessageContent) -> List[types.Part]: text_parts = [] if isinstance(_content, TextPromptMessageContent): _content = _content.data if message.role == PromptMessageRole.ASSISTANT: _content = re.sub(r"^<think>.*?</think>\s*", "", _content, count=1, flags=re.DOTALL) # ❌ STRIPS ALL THINKING CONTENT FROM ASSISTANT MESSAGES if _content: text_parts.append(types.Part.from_text(text=_content)) return text_parts Root Cause: All <think> tags are now stripped from assistant messages during processing, removing crucial reasoning context. Impact on Agents: - ❌ False answers: Reasoning chains are broken - ❌ Ignoring instructions: Chain-of-thought context is lost - ❌ Degraded performance: Model can't see its own reasoning process ### ✔️ Error log _No response_
yindo added the bug label 2026-02-16 10:20:03 -05:00
yindo closed this issue 2026-02-16 10:20:03 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 14, 2025):

You've correctly identified two critical regressions in the Gemini plugin:

  1. The ToolPromptMessage role was changed from "function" to "user" in v0.4.0 to comply with Gemini API requirements, but this broke agent tool response handling—tool outputs were misinterpreted as user questions, disrupting the tool call/response cycle and instruction following. This change is documented in PR #1488. A later fix restored the correct "function" role assignment in PR #991.

  2. The centralized removal of <think> tags from assistant messages was introduced in v0.5.2 via the _build_text_parts function, which strips reasoning content using a regex before converting to model input. This impacts agent reasoning and chain-of-thought context. The implementation and refactoring are shown in PR #1600.

Workarounds:

  • For regression #1, you can revert the role assignment for ToolPromptMessage to "function" in your plugin code if you need the previous agent loop behavior, or update to a version after PR #991 where this is fixed.
  • For regression #2, you can modify or comment out the regex logic in _build_text_parts to preserve <think> tags and reasoning context for assistant messages.

These changes were made for API compliance and code maintainability, but they introduced the issues you've described. If you need more granular control, patching these specific areas in your deployment should restore expected behavior.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Sep 14, 2025): <!-- Answer --> You've correctly identified two critical regressions in the Gemini plugin: 1. The ToolPromptMessage role was changed from `"function"` to `"user"` in v0.4.0 to comply with Gemini API requirements, but this broke agent tool response handling—tool outputs were misinterpreted as user questions, disrupting the tool call/response cycle and instruction following. This change is documented in [PR #1488](https://github.com/langgenius/dify-official-plugins/pull/1488). A later fix restored the correct `"function"` role assignment in [PR #991](https://github.com/langgenius/dify-official-plugins/pull/991). 2. The centralized removal of `<think>` tags from assistant messages was introduced in v0.5.2 via the `_build_text_parts` function, which strips reasoning content using a regex before converting to model input. This impacts agent reasoning and chain-of-thought context. The implementation and refactoring are shown in [PR #1600](https://github.com/langgenius/dify-official-plugins/pull/1600). **Workarounds:** - For regression #1, you can revert the role assignment for `ToolPromptMessage` to `"function"` in your plugin code if you need the previous agent loop behavior, or update to a version after PR #991 where this is fixed. - For regression #2, you can modify or comment out the regex logic in `_build_text_parts` to preserve `<think>` tags and reasoning context for assistant messages. These changes were made for API compliance and code maintainability, but they introduced the issues you've described. If you need more granular control, patching these specific areas in your deployment should restore expected behavior. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/9d25f257-054a-4e33-a4bb-7b293cf02ffe?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/9d25f257-054a-4e33-a4bb-7b293cf02ffe?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/9d25f257-054a-4e33-a4bb-7b293cf02ffe?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/9d25f257-054a-4e33-a4bb-7b293cf02ffe?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/9d25f257-054a-4e33-a4bb-7b293cf02ffe?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/9d25f257-054a-4e33-a4bb-7b293cf02ffe?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/9d25f257-054a-4e33-a4bb-7b293cf02ffe?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify-official-plugins/issues/1710)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-official-plugins#647