Skip to content

Conversation

@leslie2046
Copy link
Contributor

@leslie2046 leslie2046 commented Dec 31, 2025

Related Issues or Context

fixes #2352

before log


2025/12/31 10:55:17 logger.go:61: [INFO]plugin langgenius/deepseek:0.0.9@686e2328b1388ca07d86e9bccfba107297b29fcf048154cc1e4028d2a2d0d6c5: instance 019b7254 log: [DeepSeek] Messages BEFORE _clean_messages (5 messages):
2025/12/31 10:55:17 logger.go:61: [INFO]plugin langgenius/deepseek:0.0.9@686e2328b1388ca07d86e9bccfba107297b29fcf048154cc1e4028d2a2d0d6c5: instance 019b7254 log:   [0] {"role": "system", "content": "你是一名助手"}
2025/12/31 10:55:17 logger.go:61: [INFO]plugin langgenius/deepseek:0.0.9@686e2328b1388ca07d86e9bccfba107297b29fcf048154cc1e4028d2a2d0d6c5: instance 019b7254 log:   [1] {"role": "user", "content": "同时查询下当前时间和北京天气"}
2025/12/31 10:55:17 logger.go:61: [INFO]plugin langgenius/deepseek:0.0.9@686e2328b1388ca07d86e9bccfba107297b29fcf048154cc1e4028d2a2d0d6c5: instance 019b7254 log:   [2] {"role": "assistant", "content": "<think>\n用户想同时查询当前时间和北京天气。我需要调用两个工具:current_time 和 get_weather。这两个工具可以同时调用。我先来调用它们。\n</think>", "tool_calls": [{"id": "call_00_lxi8kgUWJcnpyZm2or784TnK", "type": "function", "function": {"name": "current_time", "arguments": "{}"}}, {"id": "call_01_wi3GWGNF5CedLbgqy87khs1H", "type": "function", "function": {"name": "get_weather", "arguments": "{\"city\": \"北京\"}"}}]}
2025/12/31 10:55:17 logger.go:61: [INFO]plugin langgenius/deepseek:0.0.9@686e2328b1388ca07d86e9bccfba107297b29fcf048154cc1e4028d2a2d0d6c5: instance 019b7254 log:   [3] {"role": "tool", "content": "2025-12-31 10:55:15", "tool_call_id": "call_00_lxi8kgUWJcnpyZm2or784TnK"}
2025/12/31 10:55:17 logger.go:61: [INFO]plugin langgenius/deepseek:0.0.9@686e2328b1388ca07d86e9bccfba107297b29fcf048154cc1e4028d2a2d0d6c5: instance 019b7254 log:   [4] {"role": "tool", "content": "tool response: {\"error_code\": 0, \"reason\": \"查询成功!\", \"result\": {\"city\": \"北京\", \"future\": [{\"date\": \"2025-12-31\", \"direct\": \"北风转西南风\", \"temperature\": \"-9/0℃\", \"weather\": \"晴\", \"wid\": {\"day\": \"00\", \"night\": \"00\"}}, {\"date\": \"2026-01-01\", \"direct\": \"东北风转北风\", \"temperature\": \"-8/1℃\", \"weather\": \"多云转晴\", \"wid\": {\"day\": \"01\", \"night\": \"00\"}}, {\"date\": \"2026-01-02\", \"direct\": \"西南风\", \"temperature\": \"-8/3℃\", \"weather\": \"晴\", \"wid\": {\"day\": \"00\", \"night\": \"00\"}}, {\"date\": \"2026-01-03\", \"direct\": \"西北风转北风\", \"temperature\": \"-4/5℃\", \"weather\": \"晴转多云\", \"wid\": {\"day\": \"00\", \"night\": \"01\"}}, {\"date\": \"2026-01-04\", \"direct\": \"西风转北风\", \"temperature\": \"-6/5℃\", \"weather\": \"多云转晴\", \"wid\": {\"day\": \"01\", \"night\": \"00\"}}], \"realtime\": {\"aqi\": \"14\", \"direct\": \"东北风\", \"humidity\": \"23\", \"info\": \"晴\", \"power\": \"3级\", \"temperature\": \"-5\", \"wid\": \"00\"}}}.", "tool_call_id": "call_01_wi3GWGNF5CedLbgqy87khs1H"}
2025/12/31 10:55:17 logger.go:61: [INFO]plugin langgenius/deepseek:0.0.9@686e2328b1388ca07d86e9bccfba107297b29fcf048154cc1e4028d2a2d0d6c5: instance 019b7254 log: [DeepSeek] Messages AFTER _clean_messages (4 messages):
2025/12/31 10:55:17 logger.go:61: [INFO]plugin langgenius/deepseek:0.0.9@686e2328b1388ca07d86e9bccfba107297b29fcf048154cc1e4028d2a2d0d6c5: instance 019b7254 log:   [0] {"role": "system", "content": "你是一名助手"}
2025/12/31 10:55:17 logger.go:61: [INFO]plugin langgenius/deepseek:0.0.9@686e2328b1388ca07d86e9bccfba107297b29fcf048154cc1e4028d2a2d0d6c5: instance 019b7254 log:   [1] {"role": "user", "content": "同时查询下当前时间和北京天气"}
2025/12/31 10:55:17 logger.go:61: [INFO]plugin langgenius/deepseek:0.0.9@686e2328b1388ca07d86e9bccfba107297b29fcf048154cc1e4028d2a2d0d6c5: instance 019b7254 log:   [2] {"role": "assistant", "content": "<think>\n用户想同时查询当前时间和北京天气。我需要调用两个工具:current_time 和 get_weather。这两个工具可以同时调用。我先来调用它们。\n</think>", "tool_calls": [{"id": "call_00_lxi8kgUWJcnpyZm2or784TnK", "type": "function", "function": {"name": "current_time", "arguments": "{}"}}, {"id": "call_01_wi3GWGNF5CedLbgqy87khs1H", "type": "function", "function": {"name": "get_weather", "arguments": "{\"city\": \"北京\"}"}}]}
2025/12/31 10:55:17 logger.go:61: [INFO]plugin langgenius/deepseek:0.0.9@686e2328b1388ca07d86e9bccfba107297b29fcf048154cc1e4028d2a2d0d6c5: instance 019b7254 log:   [3] {"role": "tool", "content": "2025-12-31 10:55:15\n\ntool response: {\"error_code\": 0, \"reason\": \"查询成功!\", \"result\": {\"city\": \"北京\", \"future\": [{\"date\": \"2025-12-31\", \"direct\": \"北风转西南风\", \"temperature\": \"-9/0℃\", \"weather\": \"晴\", \"wid\": {\"day\": \"00\", \"night\": \"00\"}}, {\"date\": \"2026-01-01\", \"direct\": \"东北风转北风\", \"temperature\": \"-8/1℃\", \"weather\": \"多云转晴\", \"wid\": {\"day\": \"01\", \"night\": \"00\"}}, {\"date\": \"2026-01-02\", \"direct\": \"西南风\", \"temperature\": \"-8/3℃\", \"weather\": \"晴\", \"wid\": {\"day\": \"00\", \"night\": \"00\"}}, {\"date\": \"2026-01-03\", \"direct\": \"西北风转北风\", \"temperature\": \"-4/5℃\", \"weather\": \"晴转多云\", \"wid\": {\"day\": \"00\", \"night\": \"01\"}}, {\"date\": \"2026-01-04\", \"direct\": \"西风转北风\", \"temperature\": \"-6/5℃\", \"weather\": \"多云转晴\", \"wid\": {\"day\": \"01\", \"night\": \"00\"}}], \"realtime\": {\"aqi\": \"14\", \"direct\": \"东北风\", \"humidity\": \"23\", \"info\": \"晴\", \"power\": \"3级\", \"temperature\": \"-5\", \"wid\": \"00\"}}}.", "tool_call_id": "call_00_lxi8kgUWJcnpyZm2or784TnK"}

after log

2025/12/31 11:04:52 logger.go:61: [INFO]plugin langgenius/deepseek:0.0.9@b6f84030b306390d876425dc241813a3eee58a1f97e3d3a960088d7595486997: instance 019b725c log: [DeepSeek] Messages BEFORE _clean_messages (5 messages):
2025/12/31 11:04:52 logger.go:61: [INFO]plugin langgenius/deepseek:0.0.9@b6f84030b306390d876425dc241813a3eee58a1f97e3d3a960088d7595486997: instance 019b725c log:   [0] {"role": "system", "content": "你是一名助手"}
2025/12/31 11:04:52 logger.go:61: [INFO]plugin langgenius/deepseek:0.0.9@b6f84030b306390d876425dc241813a3eee58a1f97e3d3a960088d7595486997: instance 019b725c log:   [1] {"role": "user", "content": "同时查询下当前时间和北京天气"}
2025/12/31 11:04:52 logger.go:61: [INFO]plugin langgenius/deepseek:0.0.9@b6f84030b306390d876425dc241813a3eee58a1f97e3d3a960088d7595486997: instance 019b725c log:   [2] {"role": "assistant", "content": "<think>\n用户想同时查询当前时间和北京的天气。我有获取当前时间的工具,也有获取天气的工具。我需要同时调用这两个工具来获取所需信息。\n\n那么,我来调用这两个工具。先调用获取当前时间的工具,它不需要参数。然后调用获取天气的工具,参数城市设置为\"北京\"。我会同时调用它们。\n</think>", "tool_calls": [{"id": "call_00_6BKzKgSVSpLyaY92eXq9ctDa", "type": "function", "function": {"name": "current_time", "arguments": "{}"}}, {"id": "call_01_9n9iR4Enq1udcMPFz2ZsuM4h", "type": "function", "function": {"name": "get_weather", "arguments": "{\"city\": \"北京\"}"}}]}
2025/12/31 11:04:52 logger.go:61: [INFO]plugin langgenius/deepseek:0.0.9@b6f84030b306390d876425dc241813a3eee58a1f97e3d3a960088d7595486997: instance 019b725c log:   [3] {"role": "tool", "content": "2025-12-31 11:04:50", "tool_call_id": "call_00_6BKzKgSVSpLyaY92eXq9ctDa"}
2025/12/31 11:04:52 logger.go:61: [INFO]plugin langgenius/deepseek:0.0.9@b6f84030b306390d876425dc241813a3eee58a1f97e3d3a960088d7595486997: instance 019b725c log:   [4] {"role": "tool", "content": "tool response: {\"error_code\": 0, \"reason\": \"查询成功!\", \"result\": {\"city\": \"北京\", \"future\": [{\"date\": \"2025-12-31\", \"direct\": \"北风转西南风\", \"temperature\": \"-9/0℃\", \"weather\": \"晴\", \"wid\": {\"day\": \"00\", \"night\": \"00\"}}, {\"date\": \"2026-01-01\", \"direct\": \"东北风转北风\", \"temperature\": \"-8/1℃\", \"weather\": \"多云转晴\", \"wid\": {\"day\": \"01\", \"night\": \"00\"}}, {\"date\": \"2026-01-02\", \"direct\": \"西南风\", \"temperature\": \"-8/3℃\", \"weather\": \"晴\", \"wid\": {\"day\": \"00\", \"night\": \"00\"}}, {\"date\": \"2026-01-03\", \"direct\": \"西北风转北风\", \"temperature\": \"-4/5℃\", \"weather\": \"晴转多云\", \"wid\": {\"day\": \"00\", \"night\": \"01\"}}, {\"date\": \"2026-01-04\", \"direct\": \"西风转北风\", \"temperature\": \"-6/5℃\", \"weather\": \"多云转晴\", \"wid\": {\"day\": \"01\", \"night\": \"00\"}}], \"realtime\": {\"aqi\": \"14\", \"direct\": \"北风\", \"humidity\": \"22\", \"info\": \"晴\", \"power\": \"3级\", \"temperature\": \"-5\", \"wid\": \"00\"}}}.", "tool_call_id": "call_01_9n9iR4Enq1udcMPFz2ZsuM4h"}
2025/12/31 11:04:52 logger.go:61: [INFO]plugin langgenius/deepseek:0.0.9@b6f84030b306390d876425dc241813a3eee58a1f97e3d3a960088d7595486997: instance 019b725c log: [DeepSeek] Messages AFTER _clean_messages (5 messages):
2025/12/31 11:04:52 logger.go:61: [INFO]plugin langgenius/deepseek:0.0.9@b6f84030b306390d876425dc241813a3eee58a1f97e3d3a960088d7595486997: instance 019b725c log:   [0] {"role": "system", "content": "你是一名助手"}
2025/12/31 11:04:52 logger.go:61: [INFO]plugin langgenius/deepseek:0.0.9@b6f84030b306390d876425dc241813a3eee58a1f97e3d3a960088d7595486997: instance 019b725c log:   [1] {"role": "user", "content": "同时查询下当前时间和北京天气"}
2025/12/31 11:04:52 logger.go:61: [INFO]plugin langgenius/deepseek:0.0.9@b6f84030b306390d876425dc241813a3eee58a1f97e3d3a960088d7595486997: instance 019b725c log:   [2] {"role": "assistant", "content": "<think>\n用户想同时查询当前时间和北京的天气。我有获取当前时间的工具,也有获取天气的工具。我需要同时调用这两个工具来获取所需信息。\n\n那么,我来调用这两个工具。先调用获取当前时间的工具,它不需要参数。然后调用获取天气的工具,参数城市设置为\"北京\"。我会同时调用它们。\n</think>", "tool_calls": [{"id": "call_00_6BKzKgSVSpLyaY92eXq9ctDa", "type": "function", "function": {"name": "current_time", "arguments": "{}"}}, {"id": "call_01_9n9iR4Enq1udcMPFz2ZsuM4h", "type": "function", "function": {"name": "get_weather", "arguments": "{\"city\": \"北京\"}"}}]}
2025/12/31 11:04:52 logger.go:61: [INFO]plugin langgenius/deepseek:0.0.9@b6f84030b306390d876425dc241813a3eee58a1f97e3d3a960088d7595486997: instance 019b725c log:   [3] {"role": "tool", "content": "2025-12-31 11:04:50", "tool_call_id": "call_00_6BKzKgSVSpLyaY92eXq9ctDa"}
2025/12/31 11:04:52 logger.go:61: [INFO]plugin langgenius/deepseek:0.0.9@b6f84030b306390d876425dc241813a3eee58a1f97e3d3a960088d7595486997: instance 019b725c log:   [4] {"role": "tool", "content": "tool response: {\"error_code\": 0, \"reason\": \"查询成功!\", \"result\": {\"city\": \"北京\", \"future\": [{\"date\": \"2025-12-31\", \"direct\": \"北风转西南风\", \"temperature\": \"-9/0℃\", \"weather\": \"晴\", \"wid\": {\"day\": \"00\", \"night\": \"00\"}}, {\"date\": \"2026-01-01\", \"direct\": \"东北风转北风\", \"temperature\": \"-8/1℃\", \"weather\": \"多云转晴\", \"wid\": {\"day\": \"01\", \"night\": \"00\"}}, {\"date\": \"2026-01-02\", \"direct\": \"西南风\", \"temperature\": \"-8/3℃\", \"weather\": \"晴\", \"wid\": {\"day\": \"00\", \"night\": \"00\"}}, {\"date\": \"2026-01-03\", \"direct\": \"西北风转北风\", \"temperature\": \"-4/5℃\", \"weather\": \"晴转多云\", \"wid\": {\"day\": \"00\", \"night\": \"01\"}}, {\"date\": \"2026-01-04\", \"direct\": \"西风转北风\", \"temperature\": \"-6/5℃\", \"weather\": \"多云转晴\", \"wid\": {\"day\": \"01\", \"night\": \"00\"}}], \"realtime\": {\"aqi\": \"14\", \"direct\": \"北风\", \"humidity\": \"22\", \"info\": \"晴\", \"power\": \"3级\", \"temperature\": \"-5\", \"wid\": \"00\"}}}.", "tool_call_id": "call_01_9n9iR4Enq1udcMPFz2ZsuM4h"}

This PR contains Changes to Non-Plugin

  • Documentation
  • Other

This PR contains Changes to Non-LLM Models Plugin

  • I have Run Comprehensive Tests Relevant to My Changes

This PR contains Changes to LLM Models Plugin

  • My Changes Affect Message Flow Handling (System Messages and User→Assistant Turn-Taking)
  • My Changes Affect Tool Interaction Flow (Multi-Round Usage and Output Handling, for both Agent App and Agent Node)
  • My Changes Affect Multimodal Input Handling (Images, PDFs, Audio, Video, etc.)
  • My Changes Affect Multimodal Output Generation (Images, Audio, Video, etc.)
  • My Changes Affect Structured Output Format (JSON, XML, etc.)
  • My Changes Affect Token Consumption Metrics
  • My Changes Affect Other LLM Functionalities (Reasoning Process, Grounding, Prompt Caching, etc.)
  • Other Changes (Add New Models, Fix Model Parameters etc.)

Version Control (Any Changes to the Plugin Will Require Bumping the Version)

  • I have Bumped Up the Version in Manifest.yaml (Top-Level Version Field, Not in Meta Section)

Dify Plugin SDK Version

  • I have Ensured dify_plugin>=0.3.0,<0.6.0 is in requirements.txt (SDK docs)

Environment Verification (If Any Code Changes)

Local Deployment Environment

  • Dify Version is: , I have Tested My Changes on Local Deployment Dify with a Clean Environment That Matches the Production Configuration.

SaaS Environment

  • I have Tested My Changes on cloud.dify.ai with a Clean Environment That Matches the Production Configuration

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Dec 31, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @leslie2046, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue within the Deepseek reasoner's message handling, specifically preventing the incorrect merging of tool and system messages. By ensuring these critical message types are treated as distinct entities, the PR enhances the reliability and accuracy of the LLM's interaction with tools and system instructions. Additionally, it updates the Dify Plugin SDK dependency and bumps the plugin's version, alongside introducing logging for better observability.

Highlights

  • Message Flow Handling Fix: Implemented a crucial fix in the _clean_messages method to prevent ToolPromptMessage and SystemPromptMessage from being merged. This ensures that these distinct message types, which often carry unique tool_call_ids or critical system instructions, are processed individually, improving the accuracy of the Deepseek reasoner's message flow.
  • Dify Plugin SDK Update: The dify_plugin dependency in requirements.txt has been updated to >=0.7.1, ensuring compatibility with the latest Dify Plugin SDK features and improvements.
  • Version Bump: The Deepseek plugin version in manifest.yaml has been incremented from 0.0.8 to 0.0.9 to reflect the changes introduced in this pull request.
  • Logging Integration: Added standard Python logging to the DeepseekLargeLanguageModel class, which will aid in debugging and monitoring the model's behavior.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses an issue with the DeepSeek reasoner by refining the message cleaning logic. The key change prevents the merging of ToolPromptMessage and SystemPromptMessage instances, which is a crucial fix for correct message flow handling. The plugin version and dependencies have also been updated. My review includes a couple of suggestions to improve code quality by removing unused code and fixing a minor formatting issue.

@dosubot dosubot bot added the bug Something isn't working label Dec 31, 2025
@leslie2046 leslie2046 changed the title Fix/deepseek reasoner fix: some tool messages may be unexpected removed when consecutive tool messages are sent. Dec 31, 2025
leslie2046 and others added 2 commits December 31, 2025 11:16
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@leslie2046
Copy link
Contributor Author

@hjlarry thanks!

@leslie2046 leslie2046 changed the title fix: some tool messages may be unexpected removed when consecutive tool messages are sent. fix: some tool messages may be unexpected removed when consecutive tool messages are received. Dec 31, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Dec 31, 2025
@hjlarry hjlarry merged commit d3eb62d into langgenius:main Dec 31, 2025
2 checks passed
@leslie2046 leslie2046 deleted the fix/deepseek-reasoner branch December 31, 2025 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Errors caused by parallel tool calls due to removed tool message that not expected

2 participants