Skip to content

Default and Local Fallback

Gwendal Daniel edited this page Feb 1, 2021 · 1 revision

What is a fallback?

A fallback is the reaction of the bot when it receives an unexpected intent. In the example below the bot expects a number from the user, but receives a city name. Since the bot cannot continue the conversation it triggers a fallback and asks the user to rephrase.

[Bot]  Hi! Let's play a game, can you pick a number between 1 and 10?
[User] Barcelona
[Bot]  Sorry I didn't get it, can you try again?

Default vs. Local Fallbacks

A default fallback is the generic error reaction executed by the bot, such as the Sorry I didn't get it answer above. They are defined once for the entire application, and triggered every time an error occurs. Default fallback are usually not very helpful to the end user because they don't have access to much contextual information, and need to be generic enough to work at every possible failure point.

Local fallbacks are the opposite: they are defined at a specific failure point in your bot's conversation flow, and have access to contextual information. A local fallback can use this additional information to provide better feedback to the user (e.g. reply I am expecting a number here in the example above), print some examples of valid inputs, or even access a knowledge base to find a possible answer.

📚 While local fallbacks are the most adapted for customized feedback, it's usually a good practice to define a default fallback as a safety net for uncaught errors.

Fallbacks in Xatkit

Xatkit's DSL provides out of the box constructs to define local and default fallbacks. A Xatkit bot is a state machine containing states representing bot reactions, linked with transitions representing user intents.

The Xatkit state machine contains a mandatory defaultFallback state, that is executed when an unexpected intent is received and the current state does not define a local fallback:

model()
    .initState(myInitState)
    .defaultFallbackState(fallbackState()
	.body(context -> react.reply("Sorry I didn't get it"));
    )

Note that this fallback state does not contain any transition. The Xatkit engine will automatically return to the previous valid state once the fallback has been executed.

Xatkit local fallbacks are directly defined inside their containing state. The DSL provides the optional fallback construct after the transition definition, which accepts a context parameter containing all the contextual information of the current conversation.

state("MyState")
	.body(context -> {
		react.reply(context, "Hi! Let's play a game, can you pick a number between 1 and 10?"")
	})
	.next()
	.when(intentIs(IntegerValue)).moveTo(handleCity)
	.fallback(context -> {
		react.reply("Sorry, I am expecting a number here");
	})
Clone this wiki locally