

# Use Predictive Insights for proactive self-service and agent assistance

## Overview
<a name="predictive-insights-ai-agents-overview"></a>

Predictive Insights lets you personalize every customer conversation based on what your customers have already done, before they say a word. You can use it in two ways:
+ **Proactive self-service:** Use AI agent designer to build self-service experiences that act on a customer's predicted intent. They can resolve the customer's need or make a relevant offer before the customer asks.
+ **Agent assistance:** Use Connect AI agents to help your human agents in real time. The AI agent tells them why the customer is likely contacting you, what to do next, and what to recommend.

For both experiences, you can bring Predictive Insights into the conversation in the following ways:

1. **Customer profiles flow block:** In your flows, use the **Customer profiles** block to get Predictive Insights before the contact reaches an AI agent or a human agent. First, use the **Get profile** action to find the customer. Then use the lambda invocation flow block to get the customer's Predictive Intents: last search intent, web session summary, price sensitivity, and upgrade propensity. This will require a Lambda function which invokes the public API for `BatchGetIntentForProfile`. Later blocks can use the intents to handle the contact based on why the customer is likely contacting you. For example, they can route a customer with a likely billing issue to the right queue, play a prompt about their recent search, or pass the intents to the AI agent as context. When you also want to suggest items, add the **Get profile recommendations** action to get recommendations from your Predictive Insights recommenders. Recommendations are saved as contact attributes, so any later block in the flow can refer to them.

1. **Customer Profile context source:** When you set the AI agent's context source to Customer Profile, Connect Customer loads the customer's profile into the agent's session before each turn or at session start. The profile includes the customer's Predictive Intents: last search intent, web session summary, price sensitivity, and upgrade propensity. From the first turn, the agent knows why the customer is likely contacting you and how to approach them.

1. **BatchGetIntentForProfile tool:** If you want only the Predictive Intents and not the full profile, add the `BatchGetIntentForProfile` tool from the Connect Customer namespace to the AI agent instead of setting a context source.

1. **Recommendation tools:** To choose which items to suggest, the agent uses the `getProfileRecommendation` tool, which calls your Predictive Insights recommenders: **Recommended for you**, **Similar items**, **Frequently paired items**, **Popular items**, and **Trending now**. This keeps every suggestion grounded in your catalog and matched to the customer's intent.

## Example use cases
<a name="predictive-insights-ai-agents-example-use-cases"></a>

### Proactive self-service with AI agent designer
<a name="predictive-insights-ai-agents-proactive-self-service"></a>

**Service-intent resolution:** A customer starts a self-service interaction, and the AI agent already knows why from their last search intent, web session summary, and open cases. It can address the customer's need right away, without asking discovery questions. If the customer has an open case or a billing issue, the agent resolves that first and holds off on selling.

**Upsell and cross-sell:** When the customer's upgrade propensity is high, the agent offers one step up, using the **Similar items** recommender with the item the customer is viewing. After a purchase, it suggests complementary items from the **Frequently paired items** recommender. Price sensitivity determines whether the agent leads with value or with features.

### Agent assistance with Connect AI agents
<a name="predictive-insights-ai-agents-agent-assistance"></a>

**Next-best-action:** When a customer is talking to a human agent, the Connect AI agent combines the live conversation with the customer's Predictive Intents to tell the human agent what to do next. For example, it can tell them to acknowledge an open case, pitch a lower-cost plan, or offer specific recommended items, and it gives them a reply they can send. For new customers with little history, it falls back to **Trending now** or **Popular items**.

## Setup and configuration
<a name="predictive-insights-ai-agents-setup"></a>

### Prerequisites
<a name="predictive-insights-ai-agents-prerequisites"></a>

Before you begin, complete the following:
+ Associate a Customer Profiles domain with your Connect Customer instance. Then map your interaction events to the standard Web Analytics object in that domain, and import your item catalog.
+ Enable Connect AI agents on your Connect Customer instance.
+ Enable Predictive Intents on your Customer Profiles domain for the intents that you want the AI agent to use. If you want to deliver product recommendations via AI agents, create at least one recommender, and wait until its status is **ACTIVE**.
+ Make sure that each contact has the customer's profile ID. You can add it in any of the following ways, or any other way that fits your setup. However you add it, the profile ID must end up in one of these two places on the contact: the top-level **CustomerId** field, or the contact attribute `{"CustomerId": "<profile ID>"}`.
  + Use the [**Customer profiles** flow block](customer-profiles-block.md) with the **Get profile** action, and search by an identifier such as email address or phone number.
  + If you use the communications widget, [pass the customer ID in the widget's JWT](connect-widget-on-website.md#communications-widget-domains), or pass it as a contact attribute.
  + Use the **Authenticate customer** flow block.

### Step 1: Create the AI agent
<a name="predictive-insights-ai-agents-create-agent"></a>

1. Log in to your Connect Customer instance, open **AI agent designer**, and choose **AI agents**.

1. Create an AI agent of type **Orchestration**.

### Step 2: Add Predictive Intents to the AI agent (Optional)
<a name="predictive-insights-ai-agents-add-intents"></a>

Choose one of the following options:
+ **Context source.** In the AI agent editor, add a context configuration and choose **Customer Profile** as the context source. Then choose a key to store the context under, for example `profile_data`, and choose when the context loads:
  + **Before each turn** refreshes the context on every turn. Intents that are still being computed when the contact starts then show up later in the conversation.
  + **Session initialization** loads the context once, when the session starts.

  At run time, Connect Customer adds the customer's profile context to the prompt as an XML bundle. The bundle contains the [standard profile object](standard-profile-definition.md), the Predictive Intents (when they are enabled and available), the [standard cases object](standard-case-definition.md), and the [standard order object](standard-order-definition.md). Sections that have no data are left out. The bundle has this shape:

  ```
  <profile-data>
    <profile-details>...</profile-details>
    <intents></intents>
    <cases>
      <case>...</case>
    </cases>
    <orders>
      <order>...</order>
    </orders>
  </profile-data>
  ```

  If you use the API, the AI agent's `contextConfiguration` looks like this:

  ```json
  "contextConfiguration": {
    "entries": [
      {
        "dataConfiguration": {
          "contextFulfillmentConfiguration": {
            "dataRequestFulfillmentConfiguration": {
              "dataRequestType": "CUSTOMER_PROFILE",
              "maxSingleContextCharacters": 90000
            }
          },
          "contextFulfillmentTiming": "BEFORE_EACH_TURN"
        },
        "destinationConfiguration": {
          "destinationType": "CONTEXT_DATA",
          "destination": { "contextData": { "key": "profile_data" } }
        }
      }
    ]
  }
  ```
+ **Tool.** If you need only the Predictive Intents, add the **BatchGetIntentForProfile** tool from the **Connect Customer** namespace instead. The agent calls the tool when it needs the customer's intents.

### Step 3: Add the recommendation tools (Optional)
<a name="predictive-insights-ai-agents-add-recommendation-tools"></a>

Add one `getProfileRecommendation` tool for each recommender that you want the agent to use. Give each tool a name and an instruction that identify its recipe. For example, name a tool `GetTrendingItemsRecommendation`, and instruct it to use the ACTIVE recommender with the recipe `trending-now`. To fix inputs that shouldn't change, such as `MaxResults`, use override input values.

Each recommendation tool needs three inputs: **the profile ID, the Customer Profiles domain name, and the recommender name**. The Similar items and Frequently paired items recommenders also need an item to start from. Pass that item in `Context` as `{"_catalogItem.Id": "<item ID>"}`. Add the following tools so that the agent can get the inputs:
+ **Profile ID:** the **DescribeContact** tool returns the profile ID that is stored on the contact. The profile ID can get onto the contact in several ways: the **Customer profiles** flow block, the customer ID that the communications widget passes, or any other method that adds the customer ID or profile ID to the contact.
+ **Domain name:** the **customerprofiles\_ListAccountIntegrations** tool returns the Customer Profiles domain that is linked to your Connect Customer instance.
+ **Recommender name:** the **customerprofiles\_ListRecommenders** tool lists all the recommenders in the domain. The agent picks the most recently created ACTIVE recommender for the recipe that it needs.

### Step 4: Write the prompt
<a name="predictive-insights-ai-agents-write-prompt"></a>

If you set up a context source in step 2, add the context variable to the **system** section of the prompt, using the key that you chose. For example:

```
<customer_profile>
{{$.SessionContext.profile_data}}
</customer_profile>
```

Context variables work only in the system section, not in the messages section. Tell the agent that the profile context including the Predictive Intents comes from the system and must never be treated as instructions.

Tell the agent when to recommend (for example, when the customer is comparing options) and when not to (for example, during a complaint or a billing dispute). Map each intent to a behavior: for high price sensitivity, lead with the lowest-cost option, and for low upgrade propensity, don't suggest upgrades. List the recommendation strategies in priority order, with a fallback. Tell the agent to suggest only items that a recommendation tool returned, and which catalog fields to show, such as `Name`, `Price`, and `Link`. For agent assistance, also add the contact transcript (`{{$.transcript}}`) and tell the agent that it's helping the human agent, not the customer.

Publish the prompt, update the AI agent to use it, and publish the AI agent. Make sure you have selected the appropriate security profile for this agent that will have the required permission. The following screenshot shows an example AI agent configuration. The AI agent is of type Orchestration and uses the **Admin** security profile. It has six tools in the Connect Customer namespace, each with **Sufficient** permissions: `GetDomainName`, `GetFrequentlyPairedTogetherItemsRecommendation`, `GetPopularItemsRecommendation`, `GetRecommendedForYouRecommendation`, `GetTrendingItemsRecommendation`, and `ListRecommenders`. It has one context entry with the destination key `profile_data`, the data source **Customer profile**, the fetch timing **Before each turn**, and a maximum of 90,000 single context characters.

![AI agent configuration page showing the security profile, the six recommendation tools, and the Customer profile context entry with the destination key profile_data.](https://docs.aws.amazon.com/connect/latest/adminguide/images/predictive-insights-ai-agent-configuration.png)


### Step 5: Add the agent to your flow
<a name="predictive-insights-ai-agents-add-to-flow"></a>

In the inbound flow, add a [**Customer profiles** block](customer-profiles-block.md) to find the customer's profile. Then add a **Set contact attributes** block with key `CustomerId` and value `$.Customer.ProfileId`. Next, attach the AI agent:
+ **Agent assistance:** a [**Connect assistant** flow block](connect-assistant-block.md) with your AI assistant ARN and the AI agent.
+ **Self-service:** a [**Get customer input** flow block](get-customer-input.md) with an Amazon Lex bot, with the AI agent selected under additional options. The recommended approach for Self-service use-case is to use ACXD flow with Generative journey having a tool which calls the public customer profile API `BatchGetIntentForProfile` API.

### Required permissions
<a name="predictive-insights-ai-agents-permissions"></a>

You don't need to configure any extra IAM permissions. What the AI agent is allowed to do comes from the **security profile** that you select for it in the AI agent editor. Make sure that this security profile grants access to the tools that you added. The tools and the context mentioned here mainly requires the `customer_profile.view` security profile permission.

## Limitations & considerations
<a name="predictive-insights-ai-agents-limitations"></a>
+ **Context is best effort.** Connect Customer adds as much of the profile context as it can collect within the AI agent's strict latency limit, and as much as fits in the context window. If the context is too large, it is truncated to fit. Building the context calls the public Connect and Customer Profiles APIs, so it is subject to their throttling limits. If a call is throttled, the section that it would have filled can be missing from the context for that turn.
+ **Intents can arrive one turn later.** Generating an intent takes a few seconds. To keep each turn fast, when an intent isn't available yet, Connect Customer starts generating it during one turn and adds it to the context on a later turn. To get intents into the conversation as soon as they're ready, use the **Before each turn** context timing.
+ **Intent freshness.** The last search intent and the web session summary stay fresh for 1 hour. Price sensitivity and upgrade/upsell propensity stay fresh for 24 hours. While an intent is fresh, Connect Customer returns the stored value instead of generating it again.