[Bug] Agents stringify binary plugin tool outputs and omit generated files from chat and logs
- Dominant language
- TypeScript
- Stars
- 156k
- Forks
- 24.6k
- Avg merge
- 22h 9m
- Merged PRs (30d)
- 610
Description
### Self Checks
- [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542).
- [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, otherwise it will be closed.
- [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
- [x] Please do not modify this template :) and fill in all the required fields.
### Dify version
1.17.0 source build, based on upstream commit 688107c3e5a2f6e278fc014bce9136527afc6c26
### Cloud or Self Hosted
Self Hosted (Docker)
### Steps to reproduce
Self Hosted (Docker), with API, standalone `dify-agent`, and Web built from source.
The affected plugin output converter and Agents log response implementation are unchanged in inspected upstream main `f1da874b53ab82f69f25e7703fedb51355b7831e`. The production reproduction was on our source deployment, not a fresh deployment of this later main commit.
1. Create an app in the new Agents interface using the standalone `dify-agent` backend.
2. Enable a plugin tool that returns a generated file as a BLOB message. The reported case used an image generation tool named `gpt_image_2_generate`.
3. Ask the agent to generate an image, for example, "Draw a cat."
4. Inspect the tool observation and the following model request. In this deployment, the same tool works in a Chatflow tool node.
The image provider reports successful generation, but the Agent tool observation contains a Python-style representation of the file bytes:
```text
blob=b'\x89PNG\r\n\x1a\n...'
```
The next model request can exceed its context limit. The reported request was approximately 1,150,233 tokens against a 1,050,000-token limit. This failure happens after image generation has succeeded.
There is also a missing attachment path in Agents logs. After persisting the generated file as an assistant `MessageFile` and delivering it through the existing chat file event, the live conversation can display the image, but the dedicated Agents log endpoint and log detail page still omit the attachment.
### ✔️ Expected Behavior
Save generated files through Dify's configured storage backend. Give the model a compact description and reusable file reference, and display the file as an assistant attachment in the conversation and Agents logs. Reopening persisted messages should produce usable signed file URLs.
### ❌ Actual Behavior
The standalone Agent plugin tool layer stringifies BLOB messages instead of persisting them as files. Binary bytes inflate textual tool observations and subsequent model input. The generated output is not delivered through the chat attachment path.
The dedicated Agents logs response also lacks persisted message attachments, and the log detail page does not pass attachments to the existing chat file components.
We have a candidate fix with regression tests:
- Upload binary tool outputs through the existing signed Dify file-upload API; carry saved file IDs in `ToolReturn.metadata` and return compact file descriptions and references to the model.
- Validate the persisted file's tenant, user, and conversation before saving assistant message attachments and emitting the existing file event.
- Include persisted attachments in Agents log responses and render them using the existing file components, refreshing signed URLs when reading historical messages.
The reporter confirmed successful deployment verification with Aliyun OSS, including conversation and Agents log display. The implementation uses Dify's storage abstraction; OSS-specific configuration is not part of the proposed contribution.
I would like to contribute this fix and its tests. Could a maintainer confirm the approach and assign this issue to `hanwei808`?
Contributor guide
Research direction
Start with the standalone dify-agent plugin output converter and the Agents log response and detail page; trace how BLOB tool outputs, persisted MessageFile attachments, and the existing chat file event flow. Run the regression tests for tool output conversion, message attachments, and Agents logs, then verify compact model observations, signed file URLs, and attachment rendering in both conversation and log views.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, typescript
- Domain
- api, backend, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100