Variable answers using Code and Rule cells

Variable Answers

With Syntphony CAI, it is possible to predict in your flow different responses for the same Intent. The mechanism can be very useful in several use cases in dialogs.

For example, in the dialog below:

User message: What are the required documents to open a bank account?

Virtual agent answer 1: I am glad to know that you want to open an account at Bank XYZ! The documents required are ID, proof of residence, proof of income, and an up-to-date photo.

Now, imagine that the user spends some time talking to the virtual agent and repeats the same question. In this case, the virtual agent can vary the answer, for example:

Virtual agent answer 2: I’ve got it! No problem, I can give you the information again ;-) The required documents are ID, proof of residence, proof of income, and an up-to-date photo.

Important: To create Variable Answers, you will need to use Code and Rule cells. Learn more about them at the links 😉

There are two types of Variable Answers:

I) Sequential: as the name suggests, it delivers the answers in sequence, from the first predicted answer to the last one.

To create them, you need to create a Code cell and a Rule cell for each answer, as illustrated in the image below:

In cases of sequential answers, the code in the Code cell will always be:

if (hiddenContext.seq == null || hiddenContext.seq == number of answers)
	hiddenContext.seq = 0
else
  hiddenContext.seq++;

For example, if three (3) sequential answers are predicted, the code will be:

if (hiddenContext.seq == null || hiddenContext.seq == 3)
	hiddenContext.seq = 0
else
  hiddenContext.seq++;

If eleven (11) sequential answers are predicted, the code will be:

if (hiddenContext.seq == null || hiddenContext.seq == 11)
	hiddenContext.seq = 0
else
  hiddenContext.seq++;

And the Rule cell codes will vary in this way:

For the first answer:

hiddenContext.seq == 0

For the second answer:

hiddenContext.seq == 1

If you want to add other answers, simply change the number in the code (2 for the third answer, 3 for the fourth answer, 4 for the fifth answer, and so on).

II) Random: Also as the name suggests, it delivers answers randomly. To create them, you need to create a Code cell and a Rule cell for each answer, as illustrated in the image below:

In cases of random answers, the code in the Code cell will always be:

hiddenContext.seq = Math.floor(Math.random() * number of answers);

For example, if three (3) random answers are predicted, the code will be:

hiddenContext.seq = Math.floor(Math.random() * 3);

If eleven (11) random answers are predicted, the code will be:

hiddenContext.seq = Math.floor(Math.random() * 11);

And the codes in the Rule cells will vary like this:

For the first answer

hiddenContext.seq == 0

For the second answer

hiddenContext.seq == 1

If you want to add other answers, simply change the number in the code (2 for the third answer, 3 for the fourth answer, 4 for the fifth answer, and so on).

Tip: Using this same method, you can also perform A/B Tests

In this case, the code cell will always be:

hiddenContext.seq = Math.floor(Math.random() * 100);

The rule cell codes, on the other hand, will be:

Answer A

hiddenContext.seq <= 50

Answer B

 hiddenContext.seq >= 50

To get the metrics of which answer did better, you need a webhook. There are two alternatives: Either predict a transactional answer (with webhook) on each response that will be evaluated or provide a Service cell in the flow.

Last updated