AI Assistant Custom Functions

Custom functions are a useful feature to make the AI ​​Assistant more powerful. Allows the developer to add additional capabilities to the AI ​​Assistant in addition to those automatically added by WorkWithPlus. When some custom functions are added, the AI ​​Assistant will automatically determine when to trigger them and with what parameter values ​​based on context and user messages.

To add a user custom function, you need to fill in the procedures:

WWP_AIGetUserCustomAssistantFunctions and WWP_AIProcessUserCustomAssistantFunctions

These are located in 'WorkWithPlus > AI > Procedures > UserCustomAssistantFunctions'.

WWP_AIGetUserCustomAssistantFunctions Procedure

In this procedure, you need to define each custom function and add it to the &UserCustomFunctions variable. This variable is based on the following SDT:

CustomAssistantFunctionSDT

  • name: name of the function.
  • description: description of the function. It is very important as it will be used by the WorkWithPlus AI Assistant to determine when to trigger it.
  • askForConfirmation: whether the function will ask the end-user to confirm that we want to run the function. If true, there are two options: to have the Confirm/Cancel buttons (this is the option by default) or to specify specific confirm buttons (which must be added to the confirmOptions level). If false, the function will be triggered when the AI ​​Assistant determines it is needed without prompting the user for confirmation.
  • confirmOptions: collection with the buttons that will be displayed for the end-user to confirm the trigger of the function.
    • code: code of the option. It will be saved by the response so that you can add the code depending on what the end-user has selected.
    • caption: caption of the option.
    • styleIsPrimary: whether the button will have the primary style or not. 
  • parameters: collection of parameters needed to trigger the function. Parameter values ​​will be automatically determined by the AI ​​Assistant based on context and user messages.
    • name: name of the parameter. It will be used by the developer in the process function procedure to get the value of it.
    • description: description of the parameter. This is very important as the WorkWithPlus AI Assistant will use it to determine what value to use for the parameter based on context and user messages.
    • type: type of the parameter. Possible values: string (default), number (numbers with or without decimals), integer (numbers without decimals) or boolean
    • required: whether this parameter is required or optional.

 

Example of two custom functions with confirmation:

Function with default confirmation

CustomFunctionConfirm01

Function with specific confirmation options

CustomFunctionConfirm02

 

WWP_AIProcessUserCustomAssistantFunctions Procedure

In this procedure, you need to add the code that you want to process when the function is triggered. You have access to the parameters and the selected confirm option. When the confirm options are the default ones (without adding any confirmOptions items), the function will be triggered only when the end-user presses the Confirm button. If some confirmOptions were added, the function will be triggered after the end-user press any button. In this case, the selected button code can be obtened by the develored as follows:

&FunctionParameters.Get(WWP_AIConstants.UserFunction_Confirmation_ResultKey)

 

This procedure must return the variable &Response, which is based on the following SDT:

CustomFunctionResponseSDT

The &Response.Type has 3 possible values:

  • WWP_AIUserCustomAssistantFunctionResponseType.ResponseToAI: The result of the function execution will be sent to the AI ​​Assistant, which will determine what to do next (typically, the AI Assistant will display a new message to the end-user explaining the result, as shown in the following examples). In this case it is important to include in the '&Response.Message' a detailed message explaining the function result (for example: "Result: OK") and a description of what was done (see example below). The AI ​​Assistant may use this information to inform the end-user about what happened.
  • WWP_AIUserCustomAssistantFunctionResponseType.ResponseToEndUser. The result of the function execution will be displayed as a new AI Assistant message to the end-user.
  • WWP_AIUserCustomAssistantFunctionResponseType.Error: Similar to the ResponseToAI, the result of the function execution will be sent to the AI ​​Assistant, which will determine what to do next.

 

Example of processing two custom functions with confirmation:

CustomFunctionProcess01

 

CustomFunctionProcess02

 

Examples mentioned above at runtime

 

AIAssistantCustomFunctionWithConfirm

 

AIAssistantCustomFunctionWithSpecificButtons

As you can visualize in this example, the function needs the ProjectId as a parameter to know which Project to change its status. But this is inferred automatically by the WorkWithPlus AI Assistant, by the context of the previous requests.