[PR #2154] Fix duplicate JSON response output when agent invokes tools #2290

Open
opened 2026-02-16 11:16:35 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langgenius/dify-official-plugins/pull/2154
Author: @paul0728
Created: 11/30/2025
Status: 🔄 Open

Base: mainHead: fix/agent-tool-response-duplicate


📝 Commits (5)

📊 Changes

4 files changed (+141 additions, -84 deletions)

View changed files

📝 .gitignore (+3 -0)
📝 agent-strategies/cot_agent/manifest.yaml (+1 -1)
📝 agent-strategies/cot_agent/strategies/ReAct.py (+76 -46)
📝 agent-strategies/cot_agent/strategies/function_calling.py (+61 -37)

📄 Description

Related Issues or Context

This PR fixes an issue where duplicate JSON content appears in tool responses when an agent invokes a workflow tool.

Problem Background:
When an agent calls a workflow tool, the tool returns responses in both TEXT and JSON formats simultaneously. The TEXT type serializes the JSON structure into a string, while the JSON type preserves the original JSON structure. This results in the final tool_response containing duplicate content, for example:

{"test_tool_output": "測試"}tool response: {"test_tool_output": "測試"}

Solution:
Implement smart deduplication logic in function_calling.py and ReAct.py. When a JSON-type response is detected, the TEXT-type response is skipped, and only the JSON response is retained.

Key Changed Files:

  • agent-strategies/cot_agent/strategies/function_calling.py: Added response deduplication logic
  • agent-strategies/cot_agent/strategies/ReAct.py: Added response deduplication logic
  • agent-strategies/cot_agent/manifest.yaml: Bumped version to 0.0.26
  • .gitignore: Added .claude and dify-plugin.exe

Impact Scope:

  • Only affects response handling when agents invoke tools
  • Does not change the output format of workflow tools
  • Maintains backward compatibility
  • Improves code formatting to follow Python best practices

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 (0.0.25 → 0.0.26)

Dify Plugin SDK Version

  • I have Ensured dify_plugin>=0.3.0,<0.6.0 is in requirements.txt (Current: dify_plugin>=0.5.0,<0.6.0)

Environment Verification (If Any Code Changes)

Local Deployment Environment

  • Dify Version is: 1.10.1, 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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langgenius/dify-official-plugins/pull/2154 **Author:** [@paul0728](https://github.com/paul0728) **Created:** 11/30/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/agent-tool-response-duplicate` --- ### 📝 Commits (5) - [`787e641`](https://github.com/langgenius/dify-official-plugins/commit/787e641c74b5ac9071c859631824726012e1fa7c) 修复 agent 调用工具时 JSON 响应重复输出的问题 - [`51116dd`](https://github.com/langgenius/dify-official-plugins/commit/51116ddca76a439d6226f37cdd6ac42d1c9e59f4) 修复 agent 调用工具时 JSON 响应重复输出的问题 - [`5679d61`](https://github.com/langgenius/dify-official-plugins/commit/5679d61330c7f369482d505731be1b1f1324907f) refactor: 改進工具響應去重邏輯 - [`a7912b9`](https://github.com/langgenius/dify-official-plugins/commit/a7912b92d798fab1e13b8dac077597ee5bd816c7) 重構:簡化工具響應處理邏輯,直接跳過 TEXT 類型 - [`921b9c1`](https://github.com/langgenius/dify-official-plugins/commit/921b9c1dbf71a1366a6a92dd09b3e5af3826938d) Merge branch 'fix/agent-tool-response-duplicate' of https://github.com/paul0728/dify-official-plugins into fix/agent-tool-response-duplicate ### 📊 Changes **4 files changed** (+141 additions, -84 deletions) <details> <summary>View changed files</summary> 📝 `.gitignore` (+3 -0) 📝 `agent-strategies/cot_agent/manifest.yaml` (+1 -1) 📝 `agent-strategies/cot_agent/strategies/ReAct.py` (+76 -46) 📝 `agent-strategies/cot_agent/strategies/function_calling.py` (+61 -37) </details> ### 📄 Description ## Related Issues or Context <!-- ⚠️ NOTE: This repository is for Dify Official Plugins only. For community contributions, please submit to https://github.com/langgenius/dify-plugins instead. - Link Related Issues if Applicable: #issue_number - Or Provide Context about Why this Change is Needed --> This PR fixes an issue where duplicate JSON content appears in tool responses when an agent invokes a workflow tool. **Problem Background:** When an agent calls a workflow tool, the tool returns responses in both TEXT and JSON formats simultaneously. The TEXT type serializes the JSON structure into a string, while the JSON type preserves the original JSON structure. This results in the final `tool_response` containing duplicate content, for example: ``` {"test_tool_output": "測試"}tool response: {"test_tool_output": "測試"} ``` **Solution:** Implement smart deduplication logic in `function_calling.py` and `ReAct.py`. When a JSON-type response is detected, the TEXT-type response is skipped, and only the JSON response is retained. **Key Changed Files:** - `agent-strategies/cot_agent/strategies/function_calling.py`: Added response deduplication logic - `agent-strategies/cot_agent/strategies/ReAct.py`: Added response deduplication logic - `agent-strategies/cot_agent/manifest.yaml`: Bumped version to 0.0.26 - `.gitignore`: Added `.claude` and `dify-plugin.exe` **Impact Scope:** - ✅ Only affects response handling when agents invoke tools - ✅ Does not change the output format of workflow tools - ✅ Maintains backward compatibility - ✅ Improves code formatting to follow Python best practices ## This PR contains Changes to *Non-Plugin* - [ ] Documentation - [ ] Other ## This PR contains Changes to *Non-LLM Models Plugin* - [x] I have Run Comprehensive Tests Relevant to My Changes <!-- 📷 Include Screenshots/Videos Demonstrating the Fix, New Feature, or the Behavior Before/After Breaking 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) - [x] I have Bumped Up the Version in Manifest.yaml (0.0.25 → 0.0.26) ## Dify Plugin SDK Version - [x] I have Ensured `dify_plugin>=0.3.0,<0.6.0` is in requirements.txt (Current: `dify_plugin>=0.5.0,<0.6.0`) ## Environment Verification (If Any Code Changes) ### Local Deployment Environment - [x] Dify Version is: 1.10.1, I have Tested My Changes on Local Deployment Dify with a Clean Environment That Matches the Production Configuration. ### SaaS Environment - [x] I have Tested My Changes on cloud.dify.ai with a Clean Environment That Matches the Production Configuration --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 11:16:35 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-official-plugins#2290