Image URL in agent_thoughts (observation/thought) not dynamically updated with FILES_URL and signature #22052

Open
opened 2026-02-21 20:15:33 -05:00 by yindo · 2 comments
Owner

Originally created by @keminar on GitHub (Feb 4, 2026).

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • 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, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.11.4

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Initiate a conversation with the large model to generate an image.
Wait for 10 minutes and then check the response from the Message API.

Environment

Related component: Message API
Scenario: Large model image generation interaction

✔️ Expected Behavior

The image URLs in agent_thoughts.observation and agent_thoughts.thought should be dynamically updated in real time, following the FILES_URL configuration and carrying the latest valid signature.

Actual Behavior

The URLs in agent_thoughts.observation and agent_thoughts.thought fail to update dynamically; their domain and signature remain static.
Only the image address in the answer field is correct and updated properly.

Originally created by @keminar on GitHub (Feb 4, 2026). ### 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.11.4 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce Initiate a conversation with the large model to generate an image. Wait for 10 minutes and then check the response from the Message API. # Environment Related component: Message API Scenario: Large model image generation interaction ### ✔️ Expected Behavior The image URLs in agent_thoughts.observation and agent_thoughts.thought should be dynamically updated in real time, following the FILES_URL configuration and carrying the latest valid signature. ### ❌ Actual Behavior The URLs in agent_thoughts.observation and agent_thoughts.thought fail to update dynamically; their domain and signature remain static. Only the image address in the answer field is correct and updated properly.
yindo added the 🐞 bug label 2026-02-21 20:15:33 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Feb 4, 2026):

The reason image URLs in agent_thoughts.observation and agent_thoughts.thought do not update dynamically is because these fields lack a dynamic URL re-signing hook during serialization, unlike the answer field. The answer field uses a regex-based function (re_sign_file_url_answer) and a Pydantic validation alias to scan for file/image URLs and replace them with freshly signed URLs using the current FILES_URL and signature, ensuring they remain valid and up-to-date each time the API response is generated source.

In contrast, agent_thoughts fields are stored and returned as plain strings, so any image URLs inside them are static snapshots from when the message was first created. There is no built-in mechanism to refresh or re-sign these URLs at response time source.

To fix this, you can implement a helper function similar to re_sign_file_url_answer that scans and re-signs URLs in agent_thoughts.observation and agent_thoughts.thought fields during serialization. Then, update the AgentThought response model to use field aliases or validators that invoke this helper, so these fields always return fresh, valid URLs in API responses source.

This approach will ensure agent_thoughts image URLs behave consistently with the answer field and remain valid for clients. Edge cases to consider include handling multiple URLs, deprecated formats, and distinguishing between plain text and JSON payloads. The core file signing logic (get_signed_file_url, sign_tool_file) is already reusable for this purpose.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Feb 4, 2026): <!-- Answer --> The reason image URLs in `agent_thoughts.observation` and `agent_thoughts.thought` do not update dynamically is because these fields lack a dynamic URL re-signing hook during serialization, unlike the answer field. The answer field uses a regex-based function (`re_sign_file_url_answer`) and a Pydantic validation alias to scan for file/image URLs and replace them with freshly signed URLs using the current FILES_URL and signature, ensuring they remain valid and up-to-date each time the API response is generated [source](https://github.com/langgenius/dify/blob/64e769f96ea01161ca8e28af7db2dbe590a5d048/api/models/model.py#L1140-L1964). In contrast, agent_thoughts fields are stored and returned as plain strings, so any image URLs inside them are static snapshots from when the message was first created. There is no built-in mechanism to refresh or re-sign these URLs at response time [source](https://github.com/langgenius/dify/blob/64e769f96ea01161ca8e28af7db2dbe590a5d048/api/fields/message_fields.py#L50-L62). To fix this, you can implement a helper function similar to `re_sign_file_url_answer` that scans and re-signs URLs in `agent_thoughts.observation` and `agent_thoughts.thought` fields during serialization. Then, update the AgentThought response model to use field aliases or validators that invoke this helper, so these fields always return fresh, valid URLs in API responses [source](https://github.com/langgenius/dify/blob/64e769f96ea01161ca8e28af7db2dbe590a5d048/api/fields/conversation_fields.py#L120-L318). This approach will ensure agent_thoughts image URLs behave consistently with the answer field and remain valid for clients. Edge cases to consider include handling multiple URLs, deprecated formats, and distinguishing between plain text and JSON payloads. The core file signing logic (`get_signed_file_url`, `sign_tool_file`) is already reusable for this purpose. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/7bbfd489-a400-43b5-9a34-99187d82fe5b?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/7bbfd489-a400-43b5-9a34-99187d82fe5b?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/7bbfd489-a400-43b5-9a34-99187d82fe5b?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/7bbfd489-a400-43b5-9a34-99187d82fe5b?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/7bbfd489-a400-43b5-9a34-99187d82fe5b?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/7bbfd489-a400-43b5-9a34-99187d82fe5b?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/7bbfd489-a400-43b5-9a34-99187d82fe5b?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=The%20reason%20image%20URLs%20in%20%60agent_thoughts.observation%60%20and%20%60agent_thoughts.thought%60%20do%20not%20update%20dynamically%20is%20because%20these%20fields%20lack%20a%20dynamic%20URL%20re-signing%20hook%20during%20serialization%2C%20unlike%20the%20answer%20field.%20The%20answer%20field%20uses%20a%20regex-based%20function%20%28%60re_sign_file_url_answer%60%29%20and%20a%20Pydantic%20validation%20alias%20to%20scan%20for%20file/image%20URLs%20and%20replace%20them%20with%20freshly%20signed%20URLs%20using%20the%20current%20FILES_URL%20and%20signature%2C%20ensuring%20they%20remain%20valid%20and%20up-to-date%20each%20time%20the%20API%20response%20is%20generated%20%5Bsource%5D%28https%3A//github.com/langgenius/dify/blob/64e769f96ea01161ca8e28af7db2dbe590a5d048/api/models/model.py%23L1140-L1964%29.%0A%0AIn%20contrast%2C%20agent_thoughts%20fields%20are%20stored%20and%20returned%20as%20plain%20strings%2C%20so%20any%20image%20URLs%20inside%20them%20are%20static%20snapshots%20from%20when%20the%20message%20was%20first%20created.%20There%20is%20no%20built-in%20mechanism%20to%20refresh%20or%20re-sign%20these%20URLs%20at%20response%20time%20%5Bsource%5D%28https%3A//github.com/langgenius/dify/blob/64e769f96ea01161ca8e28af7db2dbe590a5d048/api/fields/message_fields.py%23L50-L62%29.%0A%0ATo%20fix%20this%2C%20you%20can%20implement%20a%20helper%20function%20similar%20to%20%60re_sign_file_url_answer%60%20that%20scans%20and%20re-signs%20URLs%20in%20%60agent_thoughts.observation%60%20and%20%60agent_thoughts.thought%60%20fields%20during%20serialization.%20Then%2C%20update%20the%20AgentThought%20response%20model%20to%20use%20field%20aliases%20or%20validators%20that%20invoke%20this%20helper%2C%20so%20these%20fields%20always%20return%20fresh%2C%20valid%20URLs%20in%20API%20responses%20%5Bsource%5D%28https%3A//github.com/langgenius/dify/blob/64e769f96ea01161ca8e28af7db2dbe590a5d048/api/fields/conversation_fields.py%23L120-L318%29.%0A%0AThis%20approach%20will%20ensure%20agent_thoughts%20image%20URLs%20behave%20consistently%20with%20the%20answer%20field%20and%20remain%20valid%20for%20clients.%20Edge%20cases%20to%20consider%20include%20handling%20multiple%20URLs%2C%20deprecated%20formats%2C%20and%20distinguishing%20between%20plain%20text%20and%20JSON%20payloads.%20The%20core%20file%20signing%20logic%20%28%60get_signed_file_url%60%2C%20%60sign_tool_file%60%29%20is%20already%20reusable%20for%20this%20purpose.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/31907)
Author
Owner

@jackjin1997 commented on GitHub (Feb 4, 2026):

Hey, I submitted a lightweight fix for this in PR #31955.

@jackjin1997 commented on GitHub (Feb 4, 2026): Hey, I submitted a lightweight fix for this in PR #31955.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#22052