Skip to main content

Multi-Intents

When the user says something to the bot, the message can contain multiple intents. For example, when the user says "Hello! My name is Jason Smith and I want to make an appointment for tomorrow.", we can model this has having three intents:

  1. "Hello!" which is a greeting,
  2. "My name is Jason Smith" which is an inform name, and
  3. "and I want to make an appointment for tomorrow" which is an ask appointment.

The support for multi-intent is highly dependent on the capabilities of the NLU component. Colang allows us to explicitly model multi-intents from an NLU perspective and also use them in conversational flows.

Defining Multi-Intents

Working with the above example, let's define the single intents first:

define user greeting
"hi"
"hello"
...

define user inform name
entity $name as string

"my name is $name"
"I am $name"
...

define user ask appointment
entity $when as datetime

"i want an appointment"
"i want to make an appointment $when"
...

Next, we can model the fact that we expect certain combinations of intents, as follows:

define user greeting and inform name
greeting and inform name

"Hey! I'm $name"
...

The second line above, which is highlighted, means that we expect all combinations of greeting and inform name to be treated as a multi-intent. In addition to that, we can also add specific examples which should be interpreted directly as a multi-intent.

We can include as many intents as needed in a definition, for example:

define user greeting and inform name and ask appointment
greeting and inform name and ask appointment
greeting and ask appointment and inform name

"Yo!" and ask appointment and inform name

Using Multi-Intents In Flows

Working with multi-intents in flows is no different from working with single intents. For example:

schedule_appointment:
# If we get the name upfront, we remember it
when user inform name and ask appointment
$appointment_name = $name

# If we don't get the name, we ask for it
else when user ask appointment
bot "What should be the name for the reservation?"
user inform name
$appointment_name = $name

bot "When do you want to make the reservation?"
...

On line 3, we're defining a branch for when the user says inform name and ask appointment in the same utterance.

Pattern Matching

When working with multi-intents, we can also work with patterns rather than exact names. For example, a common scenario at the beginning of a conversation is for the user to greet the bot and even introduce themselves. We would want the bot to respond to the greeting and acknowledge the name, and after that, proceed with the request. Here's an example of how we can achieve this type of behavior:

greeting_with_follow_up:
when user greeting and inform name and ...
bot "Hey, $name"
else when user greeting and ...
bot "Hey there!"

done with greeting

On lines 2 and 4 highlighted above, we are performing pattern matching on the intent name using the three dots i.e. "...". Line 7 on the other hand, says that "we're done with the greeting" and that the bot should continue to process whatever was left from the initial intent.

info

The three dots "..." will match any intent name, or part of an intent name. And when they are used at the end, they can also match multiple intents.

note

The three dots that we are using from time to time in the documentation to designate that only part of the code is included, are different from the three dots for pattern matching.

tip

You can also use "something" instead of "..." if you want to improve readability. Or even "something else".

  user greeting and something else
bot "Hey there!"

done with greeting