Search code examples
ibm-cloudibm-watsonwatson-assistant

IBM Watson Assistant: How to set a 'jump to' target node dynamically (i.e. using context variables)


I want to jump from a dialog node to a node the ID of which is stored in a context variable.

I'm trying to solve a problem that has to do with a digression and which has been described here:

Conditionally return from digression in watson assistant

Especially this chart visualizes the problem:

In my opinion, A.H. posed a very reasonable and relevant question that has got no viable answer.

As far as I can see the problem can not be solved by digression settings. Either the root level node (triggered by matching the intent # Want_to_speak_to_someone) is set to 'return after digression' or it is not.

If the digression setting of this digression node is set to 'return' it will always return - no matter what happens further down in the dialog flow of this digression. Even if the user confirms that he wants to speak to a person (i.e. he does not want to return) the dialog will return to the node where the digression started.

This even happens when I jump from the yes-node (user confirms that he wants to speak to a person) out to any other node. As soon as the branch (or the branch the user jumped to) ends the dialog returns to the node where digression started.

If the digression setting of this digression node is set to 'does not return' however, a return is not possible - even if the user decides against speaking to a person and opts for returning to where he was.

What A.H. and I want is that the user can digress from a dialog flow and can still decide whether he wants to return or not. I think this is a pretty natural and important feature of a dialog. People like to reverse their decision or maybe they even digressed unintentionally from the given dialog flow.

Akaykay proposed to have two different nodes - a 'yes-node' which allows returning and a 'no-node' that does not allow returning. But this doesn't work, because before that I must have another node that asks the user for confirmation - and this 'confirmation-node' has to be set either to 'return' or 'does not return' (yielding the problems described above).

For this reason, I tried to figure out a workaround: I store the dialog node ID from which the dialog digresses in a context variable.

It is a context variable


"context": {
        "last_node": "<? output.nodes_visited [0]?>",
        ...
      },

which gets updated in every node of a dialog flow which allows digression.

In the example I could then jump back to the $last_node if the user wants to return and I could jump to another (fixed) node if the user wants to speak to a person - digressions settings of the 'digression node' would not interfere and could be set to 'does not return'.

Then I tried to edit the respective node (from which to return to the $last_node) in the json file of my skill:

"next_step": {
        "behavior": "jump_to",
        "selector": "user_input",
        "dialog_node": "$last_node"
      },

But when I reimport the skill-json-file again I get this error message:

Error - we could not import your skill. Can only contain word, underscore, space, ...

I would be fine with either solution - one that uses digression settings or one that allows setting the 'jump to' target node dynamically. I deeply appriciate any help - thanks!


Solution

  • If you want to prevent Watson Assistent from returning from digression just call <? clearDialogStack() ?> function in the node where you don't want Watson Assistant to return from digression and that's it.

    In your chart you would write "Ok, click here. <?clearDialogStack()?>" in the output text of the node "Ok, click here." and that should do the trick.

    Here it is in the doc in this section: https://cloud.ibm.com/docs/services/assistant?topic=assistant-dialog-runtime#dialog-runtime-digressions

    Also note that currently it is not possible to create dynamic gotos with Watson Assistant. Only thing you can do is to create a dialog node with all the needed gotos conditioned by something underneath it and then you would goto this node. It is hard to create this manually but it can be generated automatically. For more magic with WA check out this project:

    https://github.com/IBM/watson-assistant-workbench

    It is possible to develop chatbots with WA completely without UI.