You can combine multiple Dialogflow agents, called sub-agents, into a single agent, called a mega agent. When you perform a detect intent request against a mega agent, all of the sub-agents are considered, and the best response from the sub-agents is returned.
There are a variety of reasons that you may want to use mega agents:
- Better governance: If you have multiple teams building an agent, each team can be responsible for one sub-agent, which simplifies change conflicts across teams.
- More intents: If you have agents with a large number of intents, you may approach the intent count limit. In this case, you could create multiple sub-agents and one mega agent.
Limitations
The following limitations apply to mega agents:
- As with all agents, you can only create one agent per GCP project, so each sub-agent and mega agent will be associated with its own GCP project.
- A mega agent can have at most 10 sub-agents.
- Small talk does not work for mega agents.
- Sub-agent intent priority has no effect on intent matching when sending requests to a mega agent.
- Partner built-in telephony integrations (AudioCodes, Avaya, Genesys, SignalWire, Voximplant) are not supported.
Creating sub-agents
You create sub-agents like any other agent. Add any intents, contexts, entities, etc. as necessary to build your agents.
Creating or updating a mega agent
You can use the Dialogflow Console to create a mega agent and link it to sub-agents.
Dialogflow takes most agent settings from the mega agent into account and logs data to the mega agent. For example:
- Dialogflow takes agent-wide logging, sentiment, speech-to-text and text-to-speech settings from the mega agent.
- Dialogflow stores analytics, conversation history and data for the training tool in the mega agent.
Web UI
1. Create a mega agent
- Go to the Dialogflow ES Console.
- Click Create Agent in the left sidebar menu. (If you already have other agents, click the agent name, scroll to the bottom and click Create new agent.)
- Enter your agent's name, default language, default time zone and GCP project.
- Set the Agent Type as Mega Agent.
- Click the Create button.
2. Add and manage sub-agents
- Click Sub Agents in the left sidebar menu.
- Select a sub-agent you wish to add to the mega agent.
- The sub-agent Environment defaults to Draft, but you can update this as needed.
- If you want to use the Knowledge Base associated with the sub-agent, change the field from Excluded to Included.
- Click Save.
Set up roles
Depending on how you plan to use your mega agent, you need to set up members with specific roles in your sub-agent projects, so the mega agent has permission to make calls to the sub-agents. To set up these roles:
- Create the mega agent and sub-agent GCP projects as you normally would, and ensure you have enabled the "Dialogflow API" for each.
- If you plan on
using the API
to interact with your mega agent,
you must add the service account you use for mega agent API calls
as a member of each of your sub-agent projects,
and the applied role should have permission to make detect intent calls.
The following
roles
will provide this access:
Project Owner, Project Editor, Dialogflow API Admin,
or Dialogflow API Client.
To get this service account's email address:
- Visit the IAM service account page.
- Select the project for your mega agent.
- Either select a service account you already created for API calls or add a new service account that has the desired role. Follow the setup instructions to create a new service account and download a private key.
- Take note of the chosen service account email address. You will need this below.
If you plan on using any integrations for the mega agent, automatically created service-project-number@gcp-sa-dialogflow.iam.gserviceaccount.com service account for the mega agent's project needs to be a member of all sub-agent projects, and the applied role should have permission to make detect intent calls. The following roles will provide this access: Project Owner, Project Editor, Dialogflow API Admin, or Dialogflow API Client. To get this service account's email address:
- Visit the IAM page.
- Select the project for your mega agent.
- Enable the Include Google-provided role grants option on the right.
- Find the service account that matches the pattern:
service-project-number@gcp-sa-dialogflow.iam.gserviceaccount.com. - Take note of the chosen service account email address. You will need this below.
For each sub-agent project, add the mega agent service accounts you collected above as members of the sub-agent project:
- Visit the IAM main page.
- Select the project for your sub-agent.
- Add your mega agent's service account email addresses as members of the project, and grant them with the desired roles.
Detect intent
To detect intent, call the request like any other detect intent request and use the mega agent's project ID. Dialogflow will consider all of the sub-agents, and the best response from the sub-agents is returned.
For example, consider the following sub-agents:
Sub-agent | Intent | Training Phrases |
---|---|---|
Orders | Books | "I want to buy a book" "Add a book to my cart" |
Hats | "I want to purchase a hat" "I want a hat" |
|
Account | Balance | "What is my balance?" "How much is left in my account?" |
Address | "I want to change my address" "I have a new address" |
If an end-user says "I want to buy a hat please",
a detect intent request sent to the mega agent
will result in a match for the Hats
intent in the Orders
agent.
To specify one or more sub-agents for a detect intent request,
set the subAgents
field of
QueryParameters
.
For example, the REST JSON for this request would look like:
{ "queryInput": { "text": { "text": "reserve a meeting room for six people", "languageCode": "en-US" } }, "queryParams": { "subAgents": [ {"project": "projects/sub-agent-1-project-id"}, {"project": "projects/sub-agent-2-project-id"} ] } }
Invoking events
To invoke an event from a webhook service, you can specify the sub-agent for the intent you wish to trigger. Use the following event name format:
sub-agent-project-id.event-name
For example, if the sub-agent project ID is 123
,
and the event name is alarm
for the desired intent,
use 123.alarm
for the event name.
If you do not specify a sub-agent for the event, the event will be sent back to the sub-agent that contains the previously matched intent.
Setting output context
To set output contexts from a webhook service, you can specify the sub-agent that the context belongs to. Use the following format:
projects/mega_agent_project_id/agent/sessions/session_id/contexts/sub_agent_project_id.context_name
For example, if the session is
projects/mega_agent_project_id/agent/sessions/session_id
,
and you want to set a context named music_context
for a sub-agent with project ID sub_project_1
,
you can set the output context with the following name:
projects/mega_agent_project_id/agent/sessions/session_id/contexts/sub_project_1.music_context
If you don't specify a sub-agent prefix for the context name, the system will consider it as a context of the mega agent.