Developing a multilingual Agent in Dialogflow
Dialogflow is a great tool for designing and building out Agents that can run in a variety of Messaging Platforms. In my interactions with customers, a frequent request that comes up is about support for multiple languages. Not just that but complex scenarios like “Can an Agent support more than 1 language in a single utterance?”, etc.
The objective of this blog post is to show you step by step how you can start designing an Agent in Dialogflow that can support two languages. It will cover just about enough to give you a start and you can build upon it.
Pre-requisites
I shall assume that you know how to use Dialogflow to build out an Agent and are familiar with the environment and key building blocks like Intents, Entities, etc.
I am going to use English and Hindi as two languages that the Agent understands, so I will expect you to make sense of the Hindi that you see in this blog post.
What are we going to build?
We are going to build an Agent for a Hotel chain that lets you book a room in one of the cities that it has resorts in. We are not going to make things complex here since the idea is to show you the multilingual feature.
Here is a sample interaction with my Agent in Hindi:
And here is the same interaction in English:
Let’s get started
Log in to the Dialogflow flow console with your account and click on Create New Agent, as shown below:
This will bring up a form as shown below. Provide a name to your Agent, go with all other defaults, including English as the default language and click on Create. Let’s assume that the name of the Agent for this tutorial is MyMultilingual Agent.
You will see screenshots with the Agent name as Romin-MultilingualBot but for your reading, you can assume the name is MyMultilingual Agent
On successful creation, you will have the standard two intents : Default Fallback Intent and Default Welcome Intent created for you.
Go to the Settings page for the Agent and then to the Languages. You will only see English — en listed, which is the default language that we had selected at the time of creation of the Agent. Click on Select Additional Language and then select Hindi from the list.
If you are upto it, pick another language that you are familiar with instead of Hindi and follow along accordingly.
You should see something similar to the screen shown below. Also notice , how on the left-pane, you now see two chips indicating the two languages that the Agent now supports i.e. en and hi. Click on Save button.
Important → Every time that you have to work with a specific language, make sure to select the language chip from the Top Left. This way you know which language you are in and for which, you are now configuring Intents, Entities and so on.
Support for English
For the default English language, we are not going to do anything special. If you are familiar with the default Intents (Welcome and Fallback) that are generated, we are good. We are not going to modify anything over there.
Ensure that you have select the English language en for the Agent. Then let’s do a couple of things for this Agent.
- Add a resort-location Entity
We don’t want users to select any city in which this Hotel chain has resorts in. We would like to restrict it only to cities in which they have resorts. To do this, we are going to define a Custom Entity named resort-location and restrict the values over there.
Go ahead to Entities and create a Custom Entity resort-location as shown below and click on Save.
- Add a new Intent Book Holiday Intent
Click on Intents and then add a New Intent named Book Holiday Intent. In the sample phrases give the following and make sure that the custom entity @resort-location is detected currently for the parameter.
Go to Actions and Parameters section and mark the resort-location parameter as required.
If the user does not provide us with the required parameter, we need to prompt them for the value. For that, I set the Prompt text for this variable (last column in the above table) as follows:
Finally, provide a simple Text Response that the Intent gives out as follows:
Click Save and let the training get completed.
There we go ! We have our Agent ready and you can test it out in the Test console on the right. Remember that you have already selected the English Language (en) for the Agent, hence the Test console will assume an interaction in English language.
Give it a spin as shown below:
We are looking good now for our English support. Let’s figure out Hindi language support now.
Support for Hindi
First thing that you need to do now (I am sure you know what that is…) is to switch to Hindi language. From just below the Agent name, switch to Hindi by choosing the language chip as shown below:
Now, visit the Intents section and you will see all the 3 intents that we have so far:
- Default Welcome Intent
- Default Fallback Intent
- Book Holiday Intent
Click on either the Welcome or the Fallback Intent and you will notice that Dialogflow has provided us with sample phrases in the language for both the intent. Wonderful, isn’t it? Sample screenshots for the two intents are given below:
and the Fallback Intent is given below:
This means that if you would like to test these two intents right away in the language, go ahead and test them out in the console.
Let’s get back to the two things that we need to modify for Hindi language:
- resort-location entity
- Book Holiday Intent
First, up visit the Entities section. You will see that the resort-location entity is present but it will not have any values in Hindi language. So go ahead and enter the Hindi specific values as given below and remember to click the Save button.
Next up, visit the Intents and click on Book Holiday Intent. The values will once again be empty, but let’s fill them up in the right sequence as given below.
First up, provide the sample phrases for booking a room as given below. You can use your own nuances too in Hindi (and please excuse my language skills).
See how it is able to map the city value to the resort-location entity.
Next up, in the Actions and Parameters section, we need to provide a prompt for our parameter in Hindi language. Click on prompt for the resort-location parameter and provide some text. An example is shown below:
Finally, let’s provide the text response too as shown below:
Remember to Save. That’s it. We can now go and test the same in the console. Ensure that the language selected is still Hindi. A sample interaction in the Test Console is shown below:
and another interaction:
Testing the Integration
You can even test it out in the Integrations → Dialogflow Messenger , which is in Beta:
It will show you a snippet of code that you can insert into your web site or you can try it out there itself. For those of you with sharp eyes , you will notice that the language is indicated in the iframe snippet.
Click on TRY IT NOW button and experience your Agent.
Hope you liked the tutorial. Let a thousand multilingual Agents bloom !