# Artificial Intelligence

You may connect an AI Integration like Wit.ai or Dialogflow to make your bot handle large volumes of messages. With AI, your bot can

* Detect the message **topic.**
* Detect **important values** and phrases from a message

<figure><img src="/files/IzpPJTMtEZtlniYw18B4" alt=""><figcaption><p>Message flow with AI integration</p></figcaption></figure>

{% hint style="info" %}
BotDistrikt works with a sub-topic of AI called Natural Language Understanding (NLU) only. BotDistrikt's Rules, Stories, and Engagement tools help assist with other topics like Natural Language Processing (NLP).
{% endhint %}

## Utterance

In every AI integration, a text message is also called an utterance. Utterances may be used to train and test AI integrations to detect intents, entities, and traits.

## Intent

The topic of an utterance. Every AI integration makes an assumption that there are several hundreds of ways of saying the same thing. With this assumption, AI integrations:

* Use utterances as questions
* Produce topics - or intents, as answers.&#x20;

An intent is trained with an initial set of utterances from the developer. After an intent is trained, the AI platform receives live utterances from Users through your bot and finds which intent value most closely answers an utterance.

![Several utterances can be answered with just 2 intents](/files/-MjjTdyTocyvOKPz9Nrr)

{% hint style="success" %}
Intents should only be used in Rules, but never for assignments or storage with Actions.
{% endhint %}

{% hint style="info" %}
Every AI platform allows you to train only **1 set** of intents.
{% endhint %}

## Entity

Important values in an utterance. Keywords and regular expressions are a good way to pick out important values, but they sometimes can be missed when handling large volumes of messages. Entities scale better on larger volumes and can have multiple types of values - text, numbers, dates, phrases, or even geographical coordinates.

Unlike an intent, an entity has 2 facets; a name and a value. Its type is a default value of the AI platform itself.

![Utterance and Entity](/files/-Mjmyn8lUpHt5ZTcR2OF)

{% hint style="success" %}
Entities can be used in Rules, but are better used for assignments or storage with Actions.
{% endhint %}

{% hint style="info" %}
Every AI platform allows you to train **multiple sets** of entities.
{% endhint %}

## Trait

An unstructured or non-obvious entity. Traits should be used for categorical classification of utterances for which there is no direct association between the keywords of an utterance with its meaning. Traits can only be of one type - Text.

![Traits detected from utterances](/files/-Mjjbeef2Vfh3sQnGCdT)

{% hint style="success" %}
Traits can be used in Rules, but are better used for assignments or storage with Actions.
{% endhint %}

{% hint style="info" %}
Every AI platform allows you to train **multiple sets** of traits.
{% endhint %}

## Confidence Level

A value between 0 and 1, indicates the intent probability, entity, or trait being detected correctly. When handling large volumes of utterances, AI platforms can never be perfectly right or wrong. There can sometimes be false positives.&#x20;

As a result, AI platforms provide confidence levels to indicate the likeliness of an intent, entity, or trait detected as correct.

Confidence levels can also be used in your Rules to ensure your bot only responds to minimum confidence thresholds that you set.

![Intents are detected with confidence levels](/files/-MjjdEY4djlwOfX8MfYe)

## NLP Attributes

After an AI integration detects intents, entities, and traits, the detected values are stored in your bot's [NLP context](broken://pages/-MjJVh1pSLJxumjAwcRU#nlp-attribute) in a conversation session with a User. They can then be used in your Rules to make your bot respond to Messages.

For example, using the above confidence level table, let's assume we have connected the Dialogflow integration. Then we can create a Rule called "user said hello" with 2 conditions

![We set a minimum confidence threshold of 0.8 for the "greeting" intent in our Rule](/files/-MjjfEJ2ZHDpTwRiTCFm)

After this, this conversation can occur with a user

> **User:** Hello!\
> `Bot detected greeting intent, AND its confidence exceeds the minimum threhold`\
> **Bot:** Greetings! How are you today?

However, this conversation can occur with a user as well

> **User:** Yo, how you doin\
> `Bot recognizes greeting intent, but its confidence does not exceed the minimum threshold`\
> **Bot:** I'm sorry, I don't understand what that means

If you use an AI integration, it is imperative to train your bot with very similar words and tonality to how you expect your users to speak with your bot.&#x20;

This way, it can be trained to answer questions for your ideal customer profiles, and not for any random person who will not get any value from your bot.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.botdistrikt.com/how-botdistrikt-works/artificial-intelligence.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
