Agent V2 File and Vision Handling#
Agent V2 file and vision handling spans three concerns: a frontend gating layer that decides which files are included in the chat request, a backend forwarding path that encodes those files and injects them into the agent runtime, and configure UI awareness of the selected model's vision capabilities. Several bugs in each layer have been patched or have pending fixes.
Key files:
app_generator.pyβ orchestrates generate, parses uploaded files into access-controlled DifyFileobjectsruntime_request_builder.pyβ assembles thedify-agentrun request, detects vision support, constructs multimodal or download layersrequest_builder.pyβ definesAgentBackendAgentAppRunInputand emits layer specsmodel_access.pyβ providesresolve_model_supports_vision()to inspect credential-bound model schemaslayer.pyβdify-agentuser_prompt layer implementation for multimodal contentchat-conversation.tsxβ frontend send path; line 186 is the current vision-gate fix
File Forwarding Path#
When a user sends a message with attachments in an Agent App:
-
Frontend (
chat-conversation.tsx) β files are unconditionally attached:if (files?.length) data.files = files. -
app_generator.generate()readsargs.get("files")intoraw_files. Within a file-access scope, it callsfile_factory.build_from_mappings()to parse uploaded files into access-controlled DifyFileobjects. TheseFileobjects are passed to_AgentAppRunnerviaAgentAppGenerateEntitywith the populatedfilesfield (not empty). No file locators are appended to the query text anymore. -
AgentAppRuntimeRequestBuilder.build()calls_build_user_files()to determine delivery mode. The builder invokesresolve_model_supports_vision()fromcore.app.llm.model_accessto check if the selected model supports vision. When vision is supported and image files are present, images are converted toDifyUserPromptImageConfigand sent through theDifyUserPromptLayerConfigas native multimodal content. Image URLs become Pydantic AIImageUrlcontent; inline Base64 images becomeBinaryContent. Non-image files and cases where vision is not supported fall back to thedelivery="download"mode with shell-baseddify-agent file downloadinstructions appended to the prompt text. -
dify-agentbackend (layer.py) β theDifyUserPromptLayerconsumes theDifyUserPromptLayerConfig. Images markeddelivery="multimodal"are converted to Pydantic AIImageUrlorBinaryContentand sent directly to the model. Files markeddelivery="download"have their locators serialized and appended to the prompt text.
Known Gaps and Fixes#
All Attachments Dropped for Non-Vision Models β Fixed#
Previously, chat-conversation.tsx had if (files?.length && supportVision) data.files = files, gating all file types on the model's vision flag . DOCX, PDF, and TXT uploads were silently discarded whenever the selected model didn't advertise ModelFeature.VISION.
PR #40586 / #40179 (merged 2026-08-12) removed the && supportVision check. Vision capability governs whether the LLM can interpret images directly; it must not gate file delivery to the agent sandbox, where tools process documents independently of LLM vision support .
Vision Toggle Missing in Configure UI β Open#
The Agent V2 "Chat Features" panel renders a generic File Upload card with no ModelFeature.VISION check . The legacy agent configure, by contrast, reads currModel.features in use-configuration.ts and renders ConfigVision with resolution (high/low) controls. The confirmed gaps in Agent V2:
- No vision capability check anywhere in the configure context
- No warning or toggle when image uploads are enabled on a non-vision model
image.detailresolution setting is buried in the generic file-upload settings modal, not surfaced as a top-level control
PR #41135 (OPEN) proposes threading supportsVision from useAgentConfigureModelOptions() into the configure context, adding a non-blocking warning banner for the mismatch case, and surfacing the resolution setting.
Initial File Forwarding β Fixed#
Before PR #37926 (merged 2026-06-25), the files field was always empty at execution time even when a file was visually accepted in the UI. The fix wired file handling through FileUploadConfigManager and file_factory in app_generator.py, and introduced the DifyUserPromptLayerConfig / DifyUserPromptFileConfig layer in dify-agent.
Images Sent as Download Instructions β Fixed#
PR #41685 (merged 2026-09-07) replaced the old prompt_file_mappings approach. Previously, all files (including images) were serialized as JSON locators and appended to the user prompt as text instructions for the agent's built-in download tools. The fix introduces:
- Vision detection via
resolve_model_supports_vision()inspecting the credential-bound model schema - Native multimodal delivery for images when the model supports vision
- The
DifyUserPromptLayerindify-agentconverts image URLs to Pydantic AIImageUrland inline Base64 toBinaryContent - Non-image files and non-vision models continue to use the download fallback
Vision Capability: Legacy vs Agent V2#
| Surface | Vision check | Location |
|---|---|---|
| Legacy agent configure | currModel.features.includes(ModelFeatureEnum.vision) β ConfigVision | use-configuration.ts |
| Agent V2 configure UI | None (as of v1.16.1) | chat-features-panel.tsx |
| Agent V2 runtime send | None (fixed β was && supportVision) | chat-conversation.tsx line 186 |
Related Topics#
- Agent File Handling β covers
DifyAgentNodeoutput normalization,ToolFilerebacker, and unsigned URL issues (workflow/pipeline path, distinct from Agent App chat input) - Agent File Upload Configuration β covers
AgentFileUploadFeatureConfig, file type buckets, and the allowed-types/methods model