How to inject 'user_id` to a tool

I want to pass a user_id to a tool directly without using an agent. How can I do that?

Hi @Odin
Thank you for reaching out and using Phidata! I’ve tagged the relevant engineers to assist you with your query. We aim to respond within 24 hours.
If this is urgent, please feel free to let us know, and we’ll do our best to prioritize it.
Thanks for your patience!

Hey @Odin, can you tell me what exactly are you trying to do here?

If the tool’s function doesn’t have user_id as a param then there are 2 ways to do it. Either inherit the tool class into another class and overload the function with your new function signature, or directly make the change to the tool if you cloned the phidata repository locally.

I will need more details to help you better

Thank you for your help. The function needs a user_id to query the database for user details. I prefer injecting the user_id directly to the tool from the request or backend instead of letting the agent decide which argument to pass to the tool for security reasons. This method prevents exposing sensitive information.

def get_user(user_id: int):
    """
    Use this function to get information about a user. Such as:
    - Username
    - Phone number
    - Email

    Args:
        user_id: The user ID of the user

    Returns:
        str: JSON string with the user information
    """
    # The logic to query go here

In addition, I also prefer not to provide extra context in this case.

    user_id = req.body.user_id; # Example user_id from request
    executor = Agent(
        name="Database executor",
        role="Make query to get information from database",
        additional_context=" The user_id will be the user_id: {}".format(user_id),
        tools=[get_user],
    )

Is there an alternative method to pass the user_id directly to the tool? @manthanguptaa