# Context conditions

### Context Conditions

Context conditions are used to store information during the dialog, which can then be used to provide different answers.

Take the example of a site that offers several products. If the question of the user does not specify what type of product is concerned by his question, we will ask him. Once he has responded, the bot retains the information and will be able to give him the answer directly for the product concerned. The information is then stored in such a way that the question is not asked if the user asks more questions about the product.

### Practical case

In this practical case, the user declares an intention for which the bot needs to adjust its response according to a condition to be met. Here, the condition to be met is to be 18 years old. The bot will therefore detect whether the user is of age or not by means of a context condition based on a mathematical expression. It will adjust its response according to Success or Failure in relation to the implemented context condition.

{% embed url="<https://youtu.be/HiO5T7ufKzw>" %}

### Creating a context condition

1. Go to **Content > Context conditions**.
2. To create a new condition, click **Add condition**.
3. Fill in the fields:
   * **Condition name**: enter the name of the condition that will appear in the branches.
   * **Condition**: select the name of the variable that will determine the condition.
   * **Operation and value**: select a combination between an operation (*is defined, is, is contained or contains*) and a value.
   * **Usage**: displays the knowledge that uses this context condition.
4. Click **+** to confirm the addition of a context condition.

Note that you can create priority groups by clicking **...** located at the right of the context condition: **Move in a group**.

<figure><img src="https://264031769-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPMvi3Izk7dvjl9HitZpp%2Fuploads%2FlVFRzddsPw80emWwFIdu%2Fimage.png?alt=media&#x26;token=924415d8-a664-47ff-b96d-807dab0d88ff" alt=""><figcaption></figcaption></figure>

You can then create a priority group or select an existing one to associate it with the condition you selected.

You can then easily manage the hierarchy of your groups/conditions using the small arrows at the left of the context condition.

### Usage of a condition

You can then use these conditions in a decision tree and different answer in each case:

<figure><img src="https://264031769-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPMvi3Izk7dvjl9HitZpp%2Fuploads%2FoqyS61cDQm61IoRqObE4%2Fimage.png?alt=media&#x26;token=233680bb-46cd-446e-aefe-b53891ee16d9" alt=""><figcaption></figcaption></figure>

1. To add a context condition to a knowledge, click on the ![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACEAAAAiCAIAAABeEieWAA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j6OMRpjsizLMpNlWimVCkbJGKMj2y0byGJVVUVRaK2NMb1eT0ppjGGMOecQsayq4FxRFCEEpZQxRmudZUZr1a1IWx9pR5TiyY1z3jlL9bJzzntPfz38628qxjjwna0fKbxKKa211hkBpmtR+t3A/svyyQfnXErhnBNCUCFDjCwz5BsA8jznnCulCEON2Zr6X52D0sNW16HaAAAAAElFTkSuQmCC) button.

<figure><img src="https://264031769-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPMvi3Izk7dvjl9HitZpp%2Fuploads%2FAhAxbhSrptow3GbbzQZf%2Fimage.png?alt=media&#x26;token=506438f0-a90d-4ce3-8617-f3dec9eca31e" alt="" width="264"><figcaption></figcaption></figure>

The **current action** option will allow you to create the success of the condition on the current window.

The **empty action** option will allow you to create the success of the condition on a new window.

The left branch represents the success of applying the condition while the branch on the right represents its failure.

2. Select the context condition via the drop-down list.

In our example, we have determined that if the user did not order product B, we check if he ordered the product A. If it did not order the product A, then it is necessary to recover the information on the product which it ordered.

3. In order to retrieve the information, make a redirection to the condition tree (in our example, it is choice\_products) which will allow the user to choose the type of product that concerns him if he does not have already been informed in his question.
4. Create the decision tree that will allow you to retrieve the information:
5. To create the "Product A" and "Product B" knowledge, click the ![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAVCAIAAADNQonCAAAAA3NCSVQICAjb4U/gAAAAGXRFWHRTb2Z0d2FyZQBnbm9tZS1zY3JlZW5zaG907wO/PgAAAMdJREFUOI1j/P//PwNlgIlC/YPGCBY469vPX89evkWTlhIX5mJnI9aIpy/eTF++FU06M9JbVV6KWCMgoK8idfvhs3cfPc+J9inqmM3AwHD74TP8RiOMkJYQyYz0RlMnLSECYSCLo5mIMIKLnQ3NzXAufr/QIFKLOmbvPnru3uPnkIAgBqAHJ5q3STPi7cfPpy/f8rAxJtUIhEfeffi868g5UvUzDL48AgE7jpwl3wguDnYlWck7D58T1KMkK8nFwQ7nMg6XUgsA1ZhCPvMNPoIAAAAASUVORK5CYII=) icon and choose **Constant**.

<figure><img src="https://264031769-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPMvi3Izk7dvjl9HitZpp%2Fuploads%2FdBIeAAFglOasHA3CTgF3%2Fimage.png?alt=media&#x26;token=859a4c21-5c0a-4fc4-b792-21b856d80ad0" alt=""><figcaption></figcaption></figure>

<figure><img src="https://264031769-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPMvi3Izk7dvjl9HitZpp%2Fuploads%2FvKwUGWcCZiItRhNSplEZ%2Fimage.png?alt=media&#x26;token=97433ba8-5a1c-4aa9-8ef1-8eac17fbe48e" alt=""><figcaption></figcaption></figure>

6. Click the small arrow at the right of **Constant**.
7. Enter the name you have defined for your variable (please repeat exactly the variable name you created in your context conditions beforehand) and enter **Ok** as the value (or the value you previously determined).
8. Click **Update**.

The registration of your variable is done.

9. You must now indicate that you want to eliminate the other variable. To do so, place your cursor following product\_A:=ok then click on the ![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAVCAIAAADNQonCAAAAA3NCSVQICAjb4U/gAAAAGXRFWHRTb2Z0d2FyZQBnbm9tZS1zY3JlZW5zaG907wO/PgAAAMdJREFUOI1j/P//PwNlgIlC/YPGCBY469vPX89evkWTlhIX5mJnI9aIpy/eTF++FU06M9JbVV6KWCMgoK8idfvhs3cfPc+J9inqmM3AwHD74TP8RiOMkJYQyYz0RlMnLSECYSCLo5mIMIKLnQ3NzXAufr/QIFKLOmbvPnru3uPnkIAgBqAHJ5q3STPi7cfPpy/f8rAxJtUIhEfeffi868g5UvUzDL48AgE7jpwl3wguDnYlWck7D58T1KMkK8nFwQ7nMg6XUgsA1ZhCPvMNPoIAAAAASUVORK5CYII=) icon.
10. Choose *Empty* and enter the name of the capture to be dumped. In our example, it is product\_B. Click **Update**.
11. Repeat the operation to create the product choice B.
12. Once all the variables are saved, you have to replay the previous interaction that accessed the knowledge "Product question". You can now access this knowledge, knowing that the user has ordered product A or product B and will be given the answer "Product A" or "Product B". In order to replay the previous interaction, click **More options** and fill in the field **Redirect to another knowledge** ${replay\_interaction:-1}
13. Click **Update**.

Here is a summary of the user's path:

1. The user asks his question "Question product" without specifying the type of product, it is then redirected to the tree "choice\_product".
2. The selected product is registered and returns to the "Question product" knowledge to direct it to the branch of the chosen product.
3. The user asks another question which knowledge also uses the two conditions on the type of product, it is now directed directly in the branch corresponding to the previously registered product.

### Using context conditions with the LLM

Using an LLM context condition allows the bot to analyze a situation automatically using a prompt. Everything is configured simply in a dedicated tab.

For this evaluation to work, the classic trigger tab must remain empty.

1. Create a new knowledge.
2. Validate and close this knowledge.
3. Click on the add context condition button.
4. Once the success or failure branch is selected, the context condition appears. Then click on the "LLM" tab.

<figure><img src="https://264031769-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPMvi3Izk7dvjl9HitZpp%2Fuploads%2FC0RqapuypseAVyemKYKO%2Fimage.png?alt=media&#x26;token=4e3fbdf0-13c7-4495-b263-ac26129a9616" alt="" width="458"><figcaption></figcaption></figure>

5. Give a name to the condition bubble.
6. Add the prompt containing the instructions to validate or invalidate the condition.

<figure><img src="https://264031769-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPMvi3Izk7dvjl9HitZpp%2Fuploads%2FDGHW0hxn0BT53lE58NxY%2Fimage.png?alt=media&#x26;token=2c263690-6950-4eef-81ed-4e262321c910" alt="" width="366"><figcaption></figcaption></figure>

{% hint style="warning" %}
The prompt must precisely indicate the format of the response that the artificial intelligence must formulate, such as the word TRUE or FALSE.
{% endhint %}

7. Select the type of operation to use as well as the expected validation value in case of success.

This success value must be strictly identical to the word returned by the prompt for the condition to work.

Once the configuration is validated, the system automatically handles the evaluation of the condition in the background.

### Mathematical expression

Here is a simple case of the use of mathematical expressions within a context condition.

1. Go to the **Knowledge** page and create a **Simple** knowledge "I want X meters" by adding the group **Number** in order to capture the number and assign a variable name that will be used in the context condition.

<figure><img src="https://264031769-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPMvi3Izk7dvjl9HitZpp%2Fuploads%2F2FSoPSo89kCVr6mqKid0%2Fimage.png?alt=media&#x26;token=00a9091c-11dc-4a94-aadd-ef169eea6157" alt=""><figcaption></figcaption></figure>

1. Then go to **Content >Context conditions** then click **Add a condition**. Set up your context condition (with mathematical expression) like this:

<figure><img src="https://264031769-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPMvi3Izk7dvjl9HitZpp%2Fuploads%2FSTVa37VkAMfbYBhiKhF9%2FCapture%20d%E2%80%99e%CC%81cran%202023-09-25%20a%CC%80%2015.13.40.png?alt=media&#x26;token=86317821-1175-4844-902b-af37c4f04c58" alt=""><figcaption></figcaption></figure>

3. Click **+** to confirm the creation of your condition and return to the initially created knowledge.
4. Add the newly created context condition and build your knowledge as follows:

<figure><img src="https://264031769-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPMvi3Izk7dvjl9HitZpp%2Fuploads%2Fq9g8UVjLtKtR51QM0mrB%2Fimage.png?alt=media&#x26;token=8d7f7ae4-42c4-4e55-9bc7-96ea4e75be5e" alt=""><figcaption></figcaption></figure>

### Schedule management[​](https://dev.docs.dydu.ai/docs/Complementary_items/context_conditions#schedule-management) <a href="#schedule-management" id="schedule-management"></a>

You can manage the schedules of Livechat operators via the context conditions. This option allows you to manage time slots in a different way compared to the Livechat parameters option.

To do this, go to **Content > Context conditions**.

Click the **Add Condition** button and then, in the first field, select the condition **IsDateDayAndHour (...)**. A window opens with the possibility to easily manage the time slots.

<figure><img src="https://264031769-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPMvi3Izk7dvjl9HitZpp%2Fuploads%2FO7FJUIDL83wBR1IwOCex%2Fimage.png?alt=media&#x26;token=daff2df6-c389-496b-bbeb-46ca017368bd" alt=""><figcaption></figcaption></figure>

Fill in the other fields and click **Ok**to validate the creation of your context condition.
