How to pass the current user’s information, such as userId and token, when calling a custom tool? #6853

Closed
opened 2026-02-21 18:17:36 -05:00 by yindo · 2 comments
Owner

Originally created by @andylzming on GitHub (Nov 20, 2024).

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 can the user information be passed to the custom function when the large model invokes it? such as userId and token.

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 @andylzming on GitHub (Nov 20, 2024). ### 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 can the user information be passed to the custom function when the large model invokes it? such as userId and token. ### 2. Additional context or comments _No response_ ### 3. Can you help us with this feature? - [X] I am interested in contributing to this feature.
yindo added the 🙋‍♂️ question label 2026-02-21 18:17:36 -05:00
yindo closed this issue 2026-02-21 18:17:37 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Nov 20, 2024):

To pass the current user's information, such as userId and token, when calling a custom tool or function, you can use the _invoke method of the AIPPTGenerateToolAdapter class. This method takes user_id and tool_parameters as arguments. The token is retrieved using the _get_api_token method, which requires the runtime credentials and the user_id. Here's a brief overview of how you can pass these parameters:

  1. Use the _invoke method, providing user_id and tool_parameters.
  2. Ensure the token is available by calling the _get_api_token method with the appropriate credentials and user_id.

Here's a code snippet for reference:

def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> ToolInvokeMessage | list[ToolInvokeMessage]:
    # Your implementation here
    # Use user_id and tool_parameters as needed

Make sure to handle the token retrieval and pass the necessary parameters when invoking the tool [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Nov 20, 2024): <!-- Answer --> To pass the current user's information, such as `userId` and `token`, when calling a custom tool or function, you can use the `_invoke` method of the `AIPPTGenerateToolAdapter` class. This method takes `user_id` and `tool_parameters` as arguments. The `token` is retrieved using the `_get_api_token` method, which requires the runtime credentials and the `user_id`. Here's a brief overview of how you can pass these parameters: 1. Use the `_invoke` method, providing `user_id` and `tool_parameters`. 2. Ensure the `token` is available by calling the `_get_api_token` method with the appropriate credentials and `user_id`. Here's a code snippet for reference: ```python def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> ToolInvokeMessage | list[ToolInvokeMessage]: # Your implementation here # Use user_id and tool_parameters as needed ``` Make sure to handle the token retrieval and pass the necessary parameters when invoking the tool <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/tools/provider/builtin/aippt/tools/aippt.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@zzy-life commented on GitHub (Apr 16, 2025):

To pass the current user's information, such as userId and token, when calling a custom tool or function, you can use the _invoke method of the AIPPTGenerateToolAdapter class. This method takes user_id and tool_parameters as arguments. The token is retrieved using the _get_api_token method, which requires the runtime credentials and the user_id. Here's a brief overview of how you can pass these parameters:

  1. Use the _invoke method, providing user_id and tool_parameters.
  2. Ensure the token is available by calling the _get_api_token method with the appropriate credentials and user_id.

Here's a code snippet for reference:

def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> ToolInvokeMessage | list[ToolInvokeMessage]:
# Your implementation here
# Use user_id and tool_parameters as needed
Make sure to handle the token retrieval and pass the necessary parameters when invoking the tool [1].

To continue talking to Dosu, mention @dosu.

@dosu
No parameters user_id
def _invoke(self, tool_parameters: dict) -> Generator[ToolInvokeMessage, None, None]:

@zzy-life commented on GitHub (Apr 16, 2025): > To pass the current user's information, such as `userId` and `token`, when calling a custom tool or function, you can use the `_invoke` method of the `AIPPTGenerateToolAdapter` class. This method takes `user_id` and `tool_parameters` as arguments. The `token` is retrieved using the `_get_api_token` method, which requires the runtime credentials and the `user_id`. Here's a brief overview of how you can pass these parameters: > > 1. Use the `_invoke` method, providing `user_id` and `tool_parameters`. > 2. Ensure the `token` is available by calling the `_get_api_token` method with the appropriate credentials and `user_id`. > > Here's a code snippet for reference: > > def _invoke(self, user_id: str, tool_parameters: dict[str, Any]) -> ToolInvokeMessage | list[ToolInvokeMessage]: > # Your implementation here > # Use user_id and tool_parameters as needed > Make sure to handle the token retrieval and pass the necessary parameters when invoking the tool [[1]](https://github.com/langgenius/dify/blob/main/api/core/tools/provider/builtin/aippt/tools/aippt.py). > > _To continue talking to [Dosu](https://dosu.dev), mention [@dosu](https://github.com/dosu)._ @dosu No parameters user_id def _invoke(self, tool_parameters: dict) -> Generator[ToolInvokeMessage, None, None]:
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#6853