Dialogflow recently introduced the Mega Agent feature.
In this tutorial, I explain how you can get started with these Mega Agents.
Why use the Mega Agent
As the documentation mentions, there are a couple of main reasons to use mega agents:
If you have a really large agent (>2000 intents), you have no option but to use mega-agents at this point.
But if you are looking to use it to “simplify” your agent management across multiple teams, mega-agent is not an obvious solution to that problem.
Also, I am not going to tell you whether you should use mega agents for your particular use case. The answer to that question depends on many factors and you need to consider a few tradeoffs which we will discuss later in this article. Instead, I will take an example (which is a little contrived, to be quite honest) to explain what is going on so you can think about these tradeoffs.
I have been building a web app called BotFlo, which helps people manage Dialogflow bots which have a lot of intents. It is very much in beta, and you can guess that by looking at the design of the home page. 🙂
When you create a large FAQ bot, it is very tedious to use the Dialogflow interface to add training phrases and responses. One way around this is to specify all the training phrases and responses for your intents in a spreadsheet, and write a script which will convert it into a Dialogflow agent.
Or you could use a web app like BotFlo which can do this conversion (from spreadsheet CSV to Dialogflow Agent ZIP file) for you.
TOFU, MOFU, BOFU and POFU
Recently I was watching a video where they talk about how you can use the following four acronyms to write knowledge base articles for web apps like BotFlo.
TOFU = Top of Funnel (user is problem-aware, doesn’t know there is a solution)
MOFU = Middle of Funnel (user is aware of your solution, is evaluating whether they should use it)
BOFU = Bottom of Funnel (user has tried your solution, but hasn’t purchased)
POFU = Post Funnel (paid user, has a question while using the app)
Let us make this more specific to the CSV to agent ZIP file converter tool in BotFlo.
TOFU = user has realized that it is very tedious to type out all the training phrases and responses for a large FAQ bot. They are asking “how can I bulk upload intents to Dialogflow” or something similar
MOFU = user knows that it is possible to write a script to do this task, and they know that BotFlo automates this for them. They don’t know how to use BotFlo and haven’t logged in to the web app yet.
BOFU = user has logged in to the app, they have used BotFlo for a small spreadsheet with a few training phrases and a few responses. They haven’t become a paid user yet. (A paid user will be able to convert larger spreadsheet files into a Dialogflow bot). They have questions about the difference between free and paid tiers.
POFU = user has paid for the BotFlo app. They need help doing the conversion for their specific use case – e.g. “how can I use BotFlo for followup intents?” (the answer is that you cannot).
So I created four bots to represent these four types of questions.
In the reminder of this article, I will explain how you can set up the Mega Agent.
How to create the Mega Agent in Dialogflow
So here are the steps to create a mega-agent in Dialogflow.
Create a new agent and mark it as mega-agent
First create a new agent, and mark it as a “Mega Agent”.
Next, click on the Sub-agents link under the agent name.
You will go to a page which looks like this:
Add all your sub-agents
Here, I have already created the four funnel bots and named them TopBot, MiddleBot, BottomBot and PostBot.
When you add a sub-agent, you can usually leave the default settings for the Environment and Knowledge Base. In my case, I use the “draft” environment and I don’t use a knowledge base in the funnel bots.
Try a query in your simulator
After adding all the sub-agents, try using the Dialogflow simulator in the mega-agent. You will see an error.
Copy the service account email address
Go to the settings page of your Mega Agent and copy the service account email address.
In the Dialogflow documentation, notice that it says the following:
Go to the IAM page
Visit the IAM page.
IAM stands for Identity and Access Management. I am not going to explain what it means here. But if you want to learn more about it, you can check out my Dialogflow REST API v2 course.
Select the project
You will now select the project corresponding to the sub-agent.
You can see that the project ID will be based on the name of your bot and will have some additional characters at the end. I have blurred out the project IDs of the funnel bots, but you can see their names in the left column.
I selected TopBot from the list.
Add new role
Now you should add a new role in your project.
Once again, I am not going to explain what a role is in this tutorial, but if you are interested, you can take a look at the REST API v2 course I mentioned earlier.
Use the service account email of your mega-agent
In the Add role popup, use the Service Account Email ID you got from your mega-agent.
You will also be asked to select a role. Type the word “dialogflow” into the search box to filter all the available roles down to the ones relevant to us.
You will see the following roles (as of Feb 2020) – Dialogflow API Admin, Dialogflow API Client, Dialogflow Console Agent Editor and Dialogflow API Reader.
Select “Dialogflow API Client” from that filtered list
Once you confirm, you will be taken to a page which will list all the roles of the current project.
Loosely speaking, this means the service account email address associated with the Mega-agent can now perform “DetectIntent” API calls on the TopBot agent.
You have completed the steps required for the TopBot agent.
Repeat the same steps for the other sub-agents
Now do the same for MiddleBot.
Try the old query in the Dialogflow simulator
Now you can try the old query (which failed in the first step) in the Dialogflow simulator. This time, you will be able to see a response.
If you see a response, then you have successfully created a Mega-agent! Congrats!
Now let us analyze how the Mega Agent works.
The first thing you should do is to look at the Diagnostic Info popup. You will learn a lot of things in Dialogflow by using the Diagnostic Info button.
Since the response JSON in the Diagnostic Info popup doesn’t fit into a single screen, I copied the entire JSON and pasted it into my IDE, which also formats it nicely.
Notice the following:
- there is an autogenerated field called __most_recent_agent_ids__
- there is an entirely new autogenerated output context called __mega_agent_context__ which we didn’t create
- the Intent Detection Confidence score is included
When user types a query asking about how to bulk upload intents in Dialogflow, the query is answered by the TopBot. TopBot will ask them if the response was Helpful or Not Helpful. It also sets an output context called await_helpful.
There are two more intents in TopBot for handling the Helpful and Not Helpful response from user.
This is the choice.HELPFUL intent:
And this is the choice.NOTHELPFUL intent:
And to make things more interesting, let us add the same phrase into the BottomBot, this time without an input context.
When user types a query which triggers the intent called bulk-upload in TopBot, notice the context set by the Dialogflow simulator – it has a prefix called topbot.
Suppose the user now types the following response: not helpful
In theory, this could map to either the choice.NOTHELPFUL intent in TopBot, or the not.helpful intent in BottomBot.
As it happens, here the behavior is quite similar to a single agent behavior in Dialogflow. When the same phrase can be mapped to an intent with no input context vs an intent with an active input context, Dialogflow chooses the latter. The same thing happens here.
Note: The context lifespan will get decremented even if another agent had responded in the step above.
That is, if user
a) says “dialogflow bulk upload intents” and triggers the bulk-upload intent.
b) types a query such as “paid app row limit” which is answered by another agent (BottomBot),
you will still see that the context which was set in step a) will be decremented when step b) completes.
How will the web demo work now that we have set up the Dialogflow Simulator properly.
There are no surprises here.
Let us delete the intent called choice.NOTHELPFUL from TopBot.
This still works as expected. Because the “better” intent mapping (choice.NOTHELPFUL in TopBot) is no longer available, Dialogflow chooses the next best mapping – the not.helpful intent in BottomBot.
Let us now consider the original question from the beginning of this article – should you use a mega-agent?
As a Dialogflow consultant, my default answer to questions of this type is the same: it depends. 🙂
But I will mention some limitations (and remember that the feature is in beta and the limitation could go away later), and you can decide for yourself.
No History/Training in sub-agent
You will notice that there is no History or Training in the sub-agents. All of it is only recorded in the Mega-agent at the moment.
And unfortunately, even the Training feature in the Mega-agent isn’t very helpful.
For one, the information about the intent mapping is incorrect.
In addition, you cannot really select an intent inside a sub-agent from this window.
For all intents and purposes, at the moment the Training feature in Mega-agents (as of Feb 10th 2020) is useless.
A reader once asked me why they need to learn about all this boring candidate intents stuff (and he also mentioned that the terminology was a little confusing).
This is what he was asking (paraphrasing):
“Can I just get to the interesting part where everything just auto-magically works?”
I was reminded of this joke about the patient who goes to the dentist:
To be honest, I am not sure if that joke really applies here. But I just wanted to use that joke somewhere, someday 🙂
But – whether or not you wish to learn about candidate intents, the intent mapping in your agent will be based around that concept anyway. You might as well understand how candidate intents work.
And once you do understand how they work, you can see another problem with the Mega-agent.
All intents without an input context are perennial candidate intents.
In a mega-agent, all the intents without an input context across all the sub-agents are perennial candidate intents, effectively multiplying the total number of candidates at each step.
And theoretically at least, once a specific intent has fired in a sub-agent, the candidate intents in the rest of the sub-agents are usually surplus intents. This could lead to poorer intent mapping.
Now, sometimes you can avoid learning about candidate intents and still build a reasonably good Dialogflow bot. But I don’t think that is possible if you are planning to create a Mega-agent.
- Dialogflow CX vs ES: First look
- Seven ways to integrate a Dialogflow chatbot into your website
- Dialogflow Zobot: Selection Triggers the next intent
- Dialogflow Architecture
- Dialogflow Python webhook tutorial
- Dialogflow training
- Dialogflow vs Lex vs LUIS vs Watson vs Chatfuel
- Convert your WordPress website into a Dialogflow FAQ chatbot
- When NOT to use follow up intents in DialogFlow
- Dialogflow Context Lifespan