Skip to main content

Language and Models

user "What is a colang model?"
bot "A colang model is composed of one or more .co files."

Colang is a modeling language for conversational experiences. It enables us to create models of how a conversational bot should interact with a human, via text or voice. A colang model is composed of one or more .co files. To create a model and play with it, you can use the Playground.

info

The colang model described in the following sections is also covered in the blog post Conversational AI using only natural language.

Greeting

Let's look at how a colang model for greeting the user might look like.

define user express greeting
"Hi"
"Hello!"
"Hey there!"

define flow greeting
user express greeting
bot "Hey there! How are you feeling today?"

The first four lines define the greeting intent i.e. what the user can say as a greeting. The last three lines define a flow i.e. the sequence of steps, for how the bot should react to a greeting.

tip

You can play with the model we are defining on this page using the chat on the right.

info

You will probably be tempted to start testing the model with various expressions e.g. "yo!" for greeting. The NLU models included in the documentation have limited data for training, so they will only recognize a limited number of user utterances.

Bot Responses

The last line in the colang snippet above, defines a bot response i.e. what the bot should say to the user. This is called an in-line definition, and it works great for simple models and when prototyping. However, as the model grows, a good practice is to define separately the bot responses, in a similar way to the user intents:

define bot express greeting
"Hey there!"

define bot ask how are you
"How are you feeling today?"

And then, the updated greeting flow will look like this:

define flow greeting
user express greeting
bot express greeting
bot ask how are you

Conversation Flow

Next, let's add some conversational logic to our bot and ask the user: "How are you?". To this question they might respond with "I'm good", or "Not so good". Let's model this behavior:

define user express feeling good
"I'm feeling good"
"Good"
"Perfect"
...

define user express feeling bad
"Not so good"
"Bad"
"Sad"
...

define flow greeting
user express greeting
bot express greeting
bot ask how are you

when user express feeling good
bot express positive emotion
else when user express feeling bad
bot express empathy
info

When you see the three dots ("...") in the colang snippets, like the one above, that means there are bits that were not included in order to keep the snippet short. You can always check out the full model in the playground.

Notice the use of when and else when to define the various paths that the conversation can take. This is a basic way of branching the conversation. You will learn other techniques in the following sections.

Sample Conversations

Below are two sample conversations with the bot model we've just defined. Colang can be used to document conversations in the initial phase of a project, during the design, as well as during testing to make sure the bot works as expected. More on this later.

sample 1
user "hi"
bot "Hey there!"
bot "How are you feeling today?"
user "Feeling great!"
bot "Great!"

sample 2
user "Hello!"
bot "Hey there!"
bot "How are you feeling today?"
user "I'm quite bored"
bot "I'm sorry to hear that..."

Next

We've just created our first colang model for greeting the user! You can check out the full model here: model/simple-greeting. You can also check out an extended version, with more training data here: model/simple-greeting/extended. Later on, we will learn how to encapsulate this as a reusable component that we can include in other bot models.