From Bright Pattern Documentation
< 5.19:Tutorials-for-admins‎ | AI
Revision as of 05:46, 13 November 2024 by Wyler.metge (talk | contribs) (Updated via BpClonePage extension. Source page: draft:Tutorials-for-admins/AI/HowtoUseAIAgentinScenarios)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
• 5.19

How to Use AI Agent in Scenarios

This tutorial will help you learn how how to deploy AI-powered scenarios using the AI Agent scenario block. It explains how to retrieve API credentials from your account in an external AI Provider, configure a Bright Pattern AI Provider integration account, and finally, build and test a scenario that takes advantage of AI language models to automate purposeful dialogs with customers.

Prerequisites

This article assumes that you have:

Procedure

The below tutorial covers the following:

Step 1: Get API Credentials from your AI Provider

Bright Pattern offers integrations with several providers that offer generative AI models. To use a language model in your contact center, you need to configure an AI Provider integration account with appropriate API credentials.

The following example shows how to generate API credentials for an OpenAI account. If you would prefer to use Vertex AI as an AI provider, you can skip this section and instead follow the steps outlined in the Vertex AI FAQ article on creating a service account key.

  1. Navigate to the Settings page of your OpenAI organization account.

    Open your account Settings page

  2. Projects in your OpenAI account help you manage integrations and let you set alerts and limits on usage. Select or create a project that you want to be associated with the Bright Pattern integration.

    Create a new project or select an existing one

  3. With your desired project selected, navigate to Project > Members and click + Service account to add a new service account to the project.

    Add a service account to your project

  4. The API credentials generated for this service account will be used by the AI Provider integration to access OpenAI resources on your behalf. Give the account an appropriately descriptive name.

    Give your service account a descriptive name

  5. Securely store the secret key that is displayed after account creation. This key is displayed only once, and anyone with the key will have API access to your OpenAI account. You will use this key during the next step to configure an AI Provider integration account.

    Securely store the API key for the new service account

Step 2: Create an AI Provider Integration Account

The AI Provider integration account gives Bright Pattern access to language models hosted by third-parties. This section will show how to configure OpenAI as the AI Provider, but the steps are similar if you choose to use a different provider.

  1. Sign in to the Contact Center Administrator application, navigate to the section Configuration > Call Center Configuration > Integration Accounts, and add an AI Provider integration account by selecting AI Provider.

    Create an AI Provider integration account

  2. Choose the account type based on which third-party provider you want to use. This example shows how to configure OpenAI as the AI Provider.

    Select your desired AI Provider

  3. Provide a descriptive Name for the integration account to help differentiate it from other accounts you may later create. Use the secret key generated in the previous section as the value for API Key, and click Read Models to retrieve the list of models that can be accessed with your OpenAI API key.

    Name your account, provide the API key, and read models

  4. The GPT Model dropdown should now contain a list of models. Select the model you want to use to evaluate customer messages, generate responses, and choose follow up actions in your scenario. Different models offer trade-offs between speed, accuracy, and cost. Consider consulting the OpenAI model descriptions to determine which model to use. Note that you must choose a model which accepts text as an input and returns text as an output.

    Select the desired GPT Model

  5. Click Test Connection, and you should see confirmation that your API credentials are valid. If you receive a dialog indicating that your credentials appear to be invalid, ensure that you have correctly entered the key from your OpenAI account, and that you are able to make API requests to OpenAI using the key.

  6. Click Apply to save the configured integration account.

    Click Apply


Step 3: Create a Scenario with an AI Agent Block

The following example is a voice scenario in order to illustrate all the settings of the AI Agent scenario block. If you prefer to configure a chat scenario, follow the below instructions, but use the Send Message + scenario block instead of the Play Prompt block.

  1. Create a basic voice scenario and an appropriate dial-in scenario entry.

  2. Add a Set Language block to the beginning of the scenario to define the language that you want the AI to use when responding to customers. This is not required, but can result in better results, especially for conversations in languages other than English.

    Use a Set Language block to define the language that AI will use to talk with customers

  3. After the Set Language block, add an AI Agent block and consider the example configuration presented below.

    Add an AI Agent block to the scenario

    • Title Text
      The name for this AI Agent block, in this example, simply "AI".

    • AI Provider
      Indicate the AI Provider integration account that you want this block to use to generate messages to the customer and evaluate customer responses. This example uses the OpenAI integration account created previously in Step 1 and Step 2, but any AI provider integration account may be used when following this tutorial.

    • Transcriber
      Choose the Speech to Text Integration account that the block will use to transcribe the customer's responses. This examples uses The Transcriber setting applies only to voice scenarios, and is not displayed in AI Agent blocks used in chat scenarios.

    • Custom end of silence time
      Define the length of silence that indicates the customer has finished speaking. The default value of 0.8 seconds is appropriate for most use cases. This setting is applicable only to voice scenarios.

    • Allow interrupting AI prompt by custom voice
      When enabled, customer speech during the AI response will immediately register the user's input and stop the AI message. If you want users to hear the complete AI message during every step of the interaction, disable this setting. Applies only to voice scenarios.

    • Prompt to play while waiting for AI
      You may choose an audio prompt to play while the AI Agent block waits for a response from the AI Provider. If you do, choose a prompt that conveys to the customer that their reply is being processed. This setting is applicable only to voice scenarios.

    • Instructions to AI
      These instructions will be sent to the AI when it generates messages for customers and evaluates customer responses. For best results, precisely explain to the AI how it should conduct dialogs with the customer, what goals it should pursue, its general demeanor, the scope of topics which it should address, and any other guidance which you want the AI to follow. The section Instructions to AI offers further explanation and links to relevant resources on writing effective instructions. In this tutorial, the following instructions are used:
      You are chatting with a customer, be inquisitive, and ask questions to find out what they want. 
      Ask short questions. 
      The company you represent is Bright Pattern.  
      Only talk about address change or subscription, and only to collect the necessary data. 
      Introduce yourself as Diana Yeh, a Bright Pattern virtual assistant. 
      Maintain a very polite and professional tone.
      Note that the above instructions restrict the scope of discussion to "address change or subscription", the details of which are defined in the Requested outcomes setting. It is considered best practice to ensure that the Instructions to AI and Requested outcomes reinforce one another.

    • Include preceding transcripts
      Enabling this option will result in the full conversation transcript being sent to the AI Provider for every turn of dialog. This can improve the accuracy and quality of the dialog generated by the AI, but can increase costs and processing time. You may wish to test how the behavior of this AI Agent block changes depending on whether this setting is enabled. Refer to the section Include preceding transcripts for illustrative examples.

    • Requested outcomes
      Define the outcomes which the AI should pursue when conducting dialogs with the customer. The following will add two outcomes, "change address" and "create subscription". Note that these two outcomes are mentioned in the Instructions to AI setting.

      • Click add Outcome

        Click Add Outcome

      • Fill in the Name field with "change address" and then click add Data. Note that the name of each outcome is provided to the AI, to allow it to determine how to conduct the dialog. For best results, ensure that each outcome name is sufficiently descriptive.

        Provide a Name for the outcome and then click add Data

      • Specify what data needs to be collected from the customer for the "change address" outcome. The Name field describes the necessary data to the AI. The Value indicates the scenario variable where the data will be stored if the customer provides the data to the AI. Suppose that changing the customer's address requires both their old address and the new address. To instruct the AI to get this data, the first data point has Name "Old Address" and Value "old_address".

        Provide a Name and Value for the data

      • Add another data element to the "change address" outcome, with Name "New Address" and Value "new_address":

        The change address outcome is configured with two data points "old address" and "new address"

      • Add another outcome "create subscription" with the following data elements:
        • Name: "new address" and Value: "new_address"
        • Name: "start date" and Value: "start_date"
        • Name: "subscription duration" and Value: "subscription_duration"

      • The AI Agent block should now display two conditional exits that correspond to the two Requested outcomes:

        Each Requested outcome creates a corresponding conditional exit

    • Max dialog turns
      Specify the maximum number of AI message and customer response pairs that the AI Agent block will allow. The default value of 10 is appropriate in this case. If the dialog exceeds this value, the block will take the default exit and populate the error variables.

    • AI response timeout
      The maximum amount of time that the AI block will wait for a response from the AI provider. This value should be chosen based on the speed of the AI model used by the AI Provider. In this case, 100 seconds is sufficient. If the AI provider does not respond within this time, the block will take the default exit and populate the error variables.

    • Customer reply timeout
      Indicate the amount of time to wait for a customer response before generating a new message for the customer. In this case, 10 seconds is sufficient.

    • Max consecutive timeouts
      The maximum number of times that the AI Agent block will try to engage the customer without receiving any response. In this case, a value of 10 is sufficient. If the customer does not respond after this many attempts, the block will take the default exit and populate the error variables.

Step 4: Configure the AI Agent Conditional Exits

Now that the AI Agent block is configured, there are two conditional exits which the block can take, representing the Requested Outcomes "change address" and "create subscription". The following configurations will help you explore the behavior of the block during testing, but showing what outcome the AI chooses, and what data it is able to extract during conversations.

  1. Add a Set Variable block to the "change address" conditional exit. This block will set the variable speech with a snippet of dynamic text that contains the address data collected by the AI.

    Add a Set Variable block to the "change address" conditional exit

    • Set the Variable Name to "speech".
    • In the Value parameter, write a short text using the old_address and new_address variables that you defined in the AI Agent block's Requested outcomes, for example:
      Thank you for updating your address from $(old_address) to $(new_address). 
      Have a good day!


  2. Add a Play Prompt block following the Set Variable block, and click Select to choose the prompt. This block will be used to play the speech variable to the customer.

    Add a play prompt block

  3. Add a voice prompt with segment "Text" and Value "$(speech)". This will play the text saved in the speech variable.

    Set a text-type prompt with "$(speech)" to play the "speech" variable

  4. Add an Exit block to finish the interaction after outcome has been presented to the customer.

  5. For the next conditional exit "create subscription", repeat the previous steps, copying the Set Variable, Play Prompt, and Exit blocks.

    Configure the "create subscription" conditional exit

  6. Modify the Value of the Set Variable block to use the new_address, subscription_duration, and start_date variables. Optionally, you may also use the variable aiAgentFinalReply which contains the final reply from the AI. For example:
    Thank you for subscribing at $(new_address) for $(subscription_duration) starting on $(start_date).
    Have a good day! 
    The final reply was $(aiDialogFinalReply)


Step 5: Use a Switch Block to Catch any Errors

Before testing the scenario, you will want to have some method of examining any errors that might occur during the operation of the scenario. In the event of an error, the AI Agent block follows the default exit and populates two variables aiAgentErrorCode and aiAgentErrorBody. Refer to AI Agent error variables to understand what information these variables can contain.

  1. Add a Switch block at the default (bottom) exit of the AI Agent block. Set the Variable to test to "aiAgentErrorCode".

    Add a Switch block

  2. Click Add Branch to add a conditional exit to the Switch block. According to the table included in the AI Agent error variables section, the aiAgentErrorCode variable will take a value of 1000 in the case that the "AI Provider account is not specified or has been deleted". To catch this error gracefully, set the Variable value to 1000 and give the Exit label a relevant name, such as "No AI".

    Add a conditional exit "No AI" for the case where the value of aiAgentErrorCode is 1000

  3. Add a Set Variable block under the "No AI" conditional exit, and use it to set the speech variable to something appropriate for the exit, for example "No AI available".

    Set the speech variable to "No AI available!"

  4. Add conditional exits to the Switch block for any error condition which you would like to test. The table of error numbers in the AI Agent error variables section may be a useful reference.

  5. Add a Play Prompt block after the Switch block. As in previous steps, configure this Play Prompt block to play the speech variable.

    Add a Play Prompt block after the Switch block

  6. Optionally, add a Goto block at the end of the scenario that points back to the AI Agent block. This will allow you to test different error conditions without necessarily needing to call the scenario entry multiple times.


Step 6: Test the Scenario

Now that you have created a scenario using the AI Agent Block, you can test it. Here are some example test cases:

Successful Outcomes:

  1. Change Address:
    • Test Input: "I'd like to change my address." "My old address is 123 Main Street." "My new address is 456 Oak Avenue."
    • Expected Output: The AI should recognize the "Change Address" intent, collect the old and new addresses, and then say something similar to "Thank you for updating your address from 123 Main Street to 456 Oak Avenue. Have a good day!"

  2. Create Subscription:
    • Test Input: Phrases along the lines of "I want to sign up for a subscription." "My address is 789 Pine Lane." "I want it to start next Monday." "I want a 3-month subscription."
    • Expected Output: The AI should understand the "Create Subscription" intent, gather the address, start date, and duration, and then say something similar to "Thank you subscribing at 789 Pine Lane for 3 months starting on next Monday. Have a good day!"


Error Handling:

  1. No AI Provider:
    • Scenario Configuration: Temporarily remove or disable the AI Provider integration account.
    • Test Input: Call into the scenario.
    • Expected Output: The scenario should follow the default exit of the AI Agent block and then the "No AI" branch of the Switch block, playing the prompt "No AI available".

  2. Too Many Dialog Turns:
    • Scenario Configuration: In the AI Agent block, set the "Max Dialog Turns" to a low number such as 2 or 3, and configure a conditional exit in the Switch block for error code 1006.
    • Test Input: Engage in a conversation that exceeds the maximum number of turns.
    • Expected Output: The AI Agent block will follow the default exit and the scenario should handle this gracefully. For example, you might configure a the conditional exit of the Switch block to play a prompt similar to "I'm sorry, I'm having trouble understanding. Please try again later.


Additional Tests

  • Experiment with Instructions: Try different Instructions to AI to see how the AI's behavior changes during dialogs.
  • Contextual Understanding: Test if the AI can maintain context across multiple turns in the conversation by changing between topics midway through the dialog. See how the setting Include preceding transcript affects the AI during these tests
  • Out of Scope Conversations: Try to get the AI to discuss topics outside the scope of the instructions.
    < Previous | Next >