Mega agents

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.

Set up roles

To use the API to detect intent for the mega agent, your mega agent service account needs a role with detect intent access for all sub-agents and the mega agent. The following roles will provide this access: Project Owner, Project Editor, Dialogflow API Admin, or Dialogflow API Client.

To interact with a mega agent in the Dialogflow simulator, the service account that is linked to your mega agent in the Dialogflow Console needs a role with detect intent access for all sub-agents (the mega agent already has the necessary role). This is a special service account created by Dialogflow when you created the agent. You should not use this service account when making API calls. The following roles will provide this access: Project Owner, Project Editor, Dialogflow API Admin, or Dialogflow API Client.

See Access control for details on these roles.

To setup these roles:

  1. Create the mega agent and sub-agent GCP projects as you normally would, and ensure you have enabled the "Dialogflow API" for each.
  2. Get the service account for your mega agent that you use for API calls:
    1. Visit the IAM service account page.
    2. Select the project for your mega agent.
    3. Either select or add a service account that has the desired role.
    4. Take note of the chosen service account email address. You will need this below.
    5. If you have not already, download a service account key for this service account, and set the GOOGLE_APPLICATION_CREDENTIALS environment variable to its path.
  3. Get the service account linked to your mega agent in the Dialogflow Console (optional step if you plan on using the Dialogflow simulator):
    1. Visit the Dialogflow Console.
    2. Select your mega agent.
    3. Click the settings settings button next to the agent's name.
    4. See the Service Account on the General tab. Take note of the service account email address. You will need this below.
  4. For each sub-agent, add your mega agent service account(s) as a member:
    1. Visit the IAM main page.
    2. Select the project for your sub-agent.
    3. Add your mega agent's service account email address(es) as a member of the project, and grant it with the desired role.

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.

Web UI

1. Create a mega agent

  1. Go to the Dialogflow Console.
  2. 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.)
  3. Enter your agent's name, default language, default time zone and GCP project.
  4. Set the Agent Type as Mega Agent.
  5. Click the Create button.

2. Add and manage sub-agents

  1. Click Sub Agents in the left sidebar menu.
  2. Select a sub-agent you wish to add to the mega agent.
  3. The sub-agent Environment defaults to Draft, but you can update this as needed.
  4. If you want to use the Knowledge Base associated with the sub-agent, change the field from Excluded to Included.
  5. Click Save.

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.