When a React agent invokes a tool, the tool response is exceptionally repeated twice. #5492

Closed
opened 2026-02-21 18:11:13 -05:00 by yindo · 7 comments
Owner

Originally created by @Lixtt on GitHub (Sep 9, 2024).

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 search for existing issues, 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

0.7.3

Cloud or Self Hosted

Cloud

Steps to reproduce

When I use a React-formatted agent to call a tool, it unusually repeats the returned result twice.
5534619383

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @Lixtt on GitHub (Sep 9, 2024). ### 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 [search for existing issues](https://github.com/langgenius/dify/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 0.7.3 ### Cloud or Self Hosted Cloud ### Steps to reproduce When I use a React-formatted agent to call a tool, it unusually repeats the returned result twice. ![5534619383](https://github.com/user-attachments/assets/afa76b80-1d70-4c95-9eea-4e79a693eb88) ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 18:11:13 -05:00
yindo closed this issue 2026-02-21 18:11:13 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 9, 2024):

@lixiangtiandashen Hello! I'm here to help you with any bugs, questions, or contributions you have for the project. Let me know how I can assist you!

I found a similar unsolved discussion regarding the issue where the agent tool invocation returns duplicate response content. You can check it out here [1].

In version 0.7.3 of Dify, a React agent might invoke a tool and receive a response that is repeated twice due to the way the ToolEngine.agent_invoke method processes and transforms the tool response. Specifically, the method _convert_tool_response_to_str concatenates the messages from the tool response, which might lead to repeated information if the tool response itself contains repeated messages.

Here is the relevant part of the code:

@staticmethod
def _convert_tool_response_to_str(tool_response: list[ToolInvokeMessage]) -> str:
    """
    Handle tool response
    """
    result = ''
    for response in tool_response:
        if response.type == ToolInvokeMessage.MessageType.TEXT:
            result += response.message
        elif response.type == ToolInvokeMessage.MessageType.LINK:
            result += f"result link: {response.message}. please tell user to check it."
        elif response.type == ToolInvokeMessage.MessageType.IMAGE_LINK or \
             response.type == ToolInvokeMessage.MessageType.IMAGE:
            result += "image has been created and sent to user already, you do not need to create it, just tell the user to check it now."
        elif response.type == ToolInvokeMessage.MessageType.JSON:
            result += f"tool response: {json.dumps(response.message, ensure_ascii=False)}."
        else:
            result += f"tool response: {response.message}."

    return result

This method concatenates all messages in the tool_response list into a single string. If the tool_response list contains repeated messages, the resulting string will also contain those repeated messages [2].

Additionally, the CotAgentRunner class in the api/core/agent/cot_agent_runner.py file shows that the agent's thought process and tool invocation results are managed through a scratchpad mechanism. The scratchpad accumulates responses and observations, which are then formatted and published. If the tool invocation results are not properly managed or deduplicated within this process, it could lead to repeated responses being included in the final output [3].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Sep 9, 2024): <!-- Greeting --> @lixiangtiandashen Hello! I'm here to help you with any bugs, questions, or contributions you have for the project. Let me know how I can assist you! <!-- Answer --> I found a similar unsolved discussion regarding the issue where the agent tool invocation returns duplicate response content. You can check it out [here](https://github.com/langgenius/dify/discussions/8144) <sup>[[1]](https://github.com/langgenius/dify/discussions/8144)</sup>. In version 0.7.3 of Dify, a React agent might invoke a tool and receive a response that is repeated twice due to the way the `ToolEngine.agent_invoke` method processes and transforms the tool response. Specifically, the method `_convert_tool_response_to_str` concatenates the messages from the tool response, which might lead to repeated information if the tool response itself contains repeated messages. Here is the relevant part of the code: ```python @staticmethod def _convert_tool_response_to_str(tool_response: list[ToolInvokeMessage]) -> str: """ Handle tool response """ result = '' for response in tool_response: if response.type == ToolInvokeMessage.MessageType.TEXT: result += response.message elif response.type == ToolInvokeMessage.MessageType.LINK: result += f"result link: {response.message}. please tell user to check it." elif response.type == ToolInvokeMessage.MessageType.IMAGE_LINK or \ response.type == ToolInvokeMessage.MessageType.IMAGE: result += "image has been created and sent to user already, you do not need to create it, just tell the user to check it now." elif response.type == ToolInvokeMessage.MessageType.JSON: result += f"tool response: {json.dumps(response.message, ensure_ascii=False)}." else: result += f"tool response: {response.message}." return result ``` This method concatenates all messages in the `tool_response` list into a single string. If the `tool_response` list contains repeated messages, the resulting string will also contain those repeated messages <sup>[[2]](https://github.com/langgenius/dify/blob/main/api/core/tools/tool_engine.py)</sup>. Additionally, the `CotAgentRunner` class in the `api/core/agent/cot_agent_runner.py` file shows that the agent's thought process and tool invocation results are managed through a scratchpad mechanism. The scratchpad accumulates responses and observations, which are then formatted and published. If the tool invocation results are not properly managed or deduplicated within this process, it could lead to repeated responses being included in the final output <sup>[[3]](https://github.com/langgenius/dify/blob/main/api/core/agent/cot_agent_runner.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@crazywoola commented on GitHub (Sep 9, 2024):

I suggest you switching to a smarter agent, or if you are using ReAct, change the max_iteration to 1 to ensure there is only one tool call .

@crazywoola commented on GitHub (Sep 9, 2024): I suggest you switching to a smarter agent, or if you are using ReAct, change the max_iteration to 1 to ensure there is only one tool call .
Author
Owner

@yuhp-zts commented on GitHub (Sep 9, 2024):

I suggest you switching to a smarter agent, or if you are using ReAct, change the max_iteration to 1 to ensure there is only one tool call .

My agent only calls one tool, the model uses Qwen-32B, the agent iteration count is 1, and I do not receive duplicate replies when running the tool separately, but duplicates occur when called through the agent.

@yuhp-zts commented on GitHub (Sep 9, 2024): > I suggest you switching to a smarter agent, or if you are using ReAct, change the max_iteration to 1 to ensure there is only one tool call . My agent only calls one tool, the model uses Qwen-32B, the agent iteration count is 1, and I do not receive duplicate replies when running the tool separately, but duplicates occur when called through the agent.
Author
Owner

@yuhp-zts commented on GitHub (Sep 9, 2024):

I suggest you switching to a smarter agent, or if you are using ReAct, change the max_iteration to 1 to ensure there is only one tool call .

I found that this issue occurs when the agent calls a tool converted from a workflow; tools that are not part of a workflow do not exhibit duplication.

@yuhp-zts commented on GitHub (Sep 9, 2024): > I suggest you switching to a smarter agent, or if you are using ReAct, change the max_iteration to 1 to ensure there is only one tool call . I found that this issue occurs when the agent calls a tool converted from a workflow; tools that are not part of a workflow do not exhibit duplication.
Author
Owner

@yuhp-zts commented on GitHub (Sep 9, 2024):

Perhaps the reason is here.
image

@yuhp-zts commented on GitHub (Sep 9, 2024): Perhaps the reason is here. ![image](https://github.com/user-attachments/assets/18eb7f2c-8a2b-4e7b-a815-640683d87d28)
Author
Owner

@crazywoola commented on GitHub (Sep 9, 2024):

In this case you could try to return the text or json only in the workflow end node to see if you can get two same records. @yuhp-zts

@crazywoola commented on GitHub (Sep 9, 2024): In this case you could try to return the text or json only in the workflow end node to see if you can get two same records. @yuhp-zts
Author
Owner

@EcoleKeine commented on GitHub (Feb 16, 2025):

@crazywoola How to "return the text or json only" ?
I dont see any selector in workflow end node

the problem is still exists in v0.15.3

@EcoleKeine commented on GitHub (Feb 16, 2025): @crazywoola How to "return the text or json only" ? I dont see any selector in workflow end node the problem is still exists in v0.15.3
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5492