how to get user_id or username in custom tool plugins #12498

Closed
opened 2026-02-21 19:07:41 -05:00 by yindo · 3 comments
Owner

Originally created by @dataknocker on GitHub (Apr 2, 2025).

Self Checks

  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

1. Is this request related to a challenge you're experiencing? Tell me about your story.

how to get user_id or username in custom tool plugins

2. Additional context or comments

No response

3. Can you help us with this feature?

  • I am interested in contributing to this feature.
Originally created by @dataknocker on GitHub (Apr 2, 2025). ### Self Checks - [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 (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### 1. Is this request related to a challenge you're experiencing? Tell me about your story. how to get user_id or username in custom tool plugins ### 2. Additional context or comments _No response_ ### 3. Can you help us with this feature? - [ ] I am interested in contributing to this feature.
yindo added the 🙋‍♂️ question label 2026-02-21 19:07:41 -05:00
yindo closed this issue 2026-02-21 19:07:41 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Apr 2, 2025):

Hello @dataknocker! I'm here to assist you with any bugs, questions, or contributions you may have. I'm a bot designed to help you out while waiting for a human maintainer. Let me know how I can assist you!

You can access the current user's ID in Dify custom tool plugins using sys.user_id within the chatflow of your custom tool [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot[bot] commented on GitHub (Apr 2, 2025): <!-- Greeting --> Hello @dataknocker! I'm here to assist you with any bugs, questions, or contributions you may have. I'm a bot designed to help you out while waiting for a human maintainer. Let me know how I can assist you! <!-- Answer --> You can access the current user's ID in Dify custom tool plugins using `sys.user_id` within the chatflow of your custom tool <sup>[[1]](https://github.com/langgenius/dify/issues/15404)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/730c93f1-9f2e-4aab-91c2-7841598c2586?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/730c93f1-9f2e-4aab-91c2-7841598c2586?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/730c93f1-9f2e-4aab-91c2-7841598c2586?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/730c93f1-9f2e-4aab-91c2-7841598c2586?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/730c93f1-9f2e-4aab-91c2-7841598c2586?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/730c93f1-9f2e-4aab-91c2-7841598c2586?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/730c93f1-9f2e-4aab-91c2-7841598c2586?feedback_type=other)</sup>
Author
Owner

@dataknocker commented on GitHub (Apr 3, 2025):

@dosu @crazywoola I want to automatically pass sys.user_id to the plugin, for example, to handle permission-related tasks within the plugin, preventing users from modifying this value."

@dataknocker commented on GitHub (Apr 3, 2025): @dosu @crazywoola I want to automatically pass sys.user_id to the plugin, for example, to handle permission-related tasks within the plugin, preventing users from modifying this value."
Author
Owner

@dosubot[bot] commented on GitHub (Apr 3, 2025):

To automatically pass sys.user_id to a plugin in Dify, you can utilize the ToolEngine.generic_invoke method, which includes the user_id as a parameter during the invocation of plugins [1]. This ensures that the user_id is securely passed and available for handling permission-related tasks within the plugin.

However, regarding preventing users from modifying this value, the specific security measures in place to protect system variables like sys.user_id from unauthorized modifications are not detailed in the available documentation or codebase. You might need to implement additional checks or validations within your plugin to ensure the integrity of the user_id.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot[bot] commented on GitHub (Apr 3, 2025): <!-- Answer --> To automatically pass `sys.user_id` to a plugin in Dify, you can utilize the `ToolEngine.generic_invoke` method, which includes the `user_id` as a parameter during the invocation of plugins <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/workflow/nodes/tool/tool_node.py)</sup>. This ensures that the `user_id` is securely passed and available for handling permission-related tasks within the plugin. However, regarding preventing users from modifying this value, the specific security measures in place to protect system variables like `sys.user_id` from unauthorized modifications are not detailed in the available documentation or codebase. You might need to implement additional checks or validations within your plugin to ensure the integrity of the `user_id`. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/70b2f113-2ed4-4002-ab2e-bc039258e012?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/70b2f113-2ed4-4002-ab2e-bc039258e012?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/70b2f113-2ed4-4002-ab2e-bc039258e012?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/70b2f113-2ed4-4002-ab2e-bc039258e012?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/70b2f113-2ed4-4002-ab2e-bc039258e012?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/70b2f113-2ed4-4002-ab2e-bc039258e012?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/70b2f113-2ed4-4002-ab2e-bc039258e012?feedback_type=other)</sup>
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#12498