Skip to content

fix(dify-agent): describe plugin tool binary output instead of inlining it - #45409

Closed
Aling33 wants to merge 1 commit into
langgenius:mainfrom
Aling33:fix/dify-agent-blob-observation
Closed

Aling33 wants to merge 1 commit into
langgenius:mainfrom
Aling33:fix/dify-agent-blob-observation

Conversation

@Aling33

@Aling33 Aling33 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Related issue

Refs #42114.

What changed

_convert_tool_response_to_text in dify-agent/src/dify_agent/layers/dify_plugin/tools_layer.py now renders BLOB messages as a bounded description instead of falling back to str(message).

Before this change a plugin tool that returned binary output (an image, a PDF, a generated archive) reached the model as blob=b'\x89PNG\r\n\x1a\n...'. str() escapes every byte, so the observation is roughly three times the payload — measured 2056 bytes of PNG turning into a 5905 character observation — and the merge cap in merge_blob_chunks allows that to grow to 30 MB. The model cannot read the bytes anyway.

Now the observation is binary output (image/png, 2056 bytes) is not included in the text result, falling back to application/octet-stream when the daemon sends no mime_type.

The API never inlines these bytes: ToolFileMessageTransformer.transform_tool_invoke_messages persists a BLOB as a tool file first and rewrites it to an IMAGE_LINK / BINARY_LINK (api/core/tools/utils/message_transformer.py). This PR does not port that file pipeline — it only stops the unbounded inlining. The full fix is #43099, which has been conflicting with main since 2026-09-28.

Verification

Added test_native_plugin_tool_describes_binary_output_instead_of_inlining_it in dify-agent/tests/local/dify_agent/layers/dify_plugin/test_layers.py, parametrised over a blob frame that carries mime_type: image/png and one that carries no meta at all.

  • Without the change both cases fail with assert "blob=b'\x89PNG...fd\xfe\xff'" == 'binary output (...)'.
  • With it: uv run python -m pytest tests/local/dify_agent/layers/dify_plugin/test_layers.py -q → 15 passed.
  • ruff check and ruff format --check are clean.
  • Full tests/local on this branch: 22 failed / 1025 passed / 2 errors, the same 22 environment failures as on main (e2b SDK version mismatch, openshell has no Windows wheel, python3 shell scripts).

AI assistance

Written with AI assistance. The tests above were run locally on Windows; an end-to-end plugin-daemon run was not possible there because openshell ships no Windows wheel.

…ng it

_convert_tool_response_to_text fell back to str(message) for BLOB messages, so
binary tool output reached the model as escaped bytes -- about three times the
payload, up to the 30 MB merge cap in merge_blob_chunks -- and was unreadable.

The API persists blobs as tool files before rendering text
(ToolFileMessageTransformer); until that pipeline exists here, report the
mimetype and size instead. Refs langgenius#42114.
@github-actions github-actions Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Nov 3, 2026
@crazywoola crazywoola closed this Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants