Domain

Domain Example

You are viewing documentation for our open source project which is maintained by the community. If you want to get started building assistants with Rasa please check out our latest documentation here.

Here is a full example of a domain, taken from the concertbot example:

version: "3.1"

intents:
  - affirm
  - deny
  - greet
  - thankyou
  - goodbye
  - search_concerts
  - search_venues
  - compare_reviews
  - bot_challenge
  - nlu_fallback
  - how_to_get_started

entities:
  - name

slots:
  concerts:
    type: list
    influence_conversation: false
    mappings:
      - type: custom
  venues:
    type: list
    influence_conversation: false
    mappings:
      - type: custom
  likes_music:
    type: bool
    influence_conversation: true
    mappings:
      - type: custom

responses:
  utter_greet:
    - text: "Hey there!"
  utter_goodbye:
    - text: "Goodbye :("
  utter_default:
    - text: "Sorry, I didn't get that, can you rephrase?"
  utter_youarewelcome:
    - text: "You're very welcome."
  utter_iamabot:
    - text: "I am a bot, powered by Rasa."
  utter_get_started:
    - text: "I can help you find concerts and venues. Do you like music?"
  utter_awesome:
    - text: "Awesome! You can ask me things like \"Find me some concerts\" or \"What's a good venue\""

actions:
  - action_search_concerts
  - action_search_venues
  - action_show_concert_reviews
  - action_show_venue_reviews
  - action_set_music_preference

session_config:
  session_expiration_time: 60  # value in minutes
  carry_over_slots_to_new_session: true

## Multiple Domain Files

The domain can be defined as a single YAML file or split across multiple files in a directory. When split across multiple files, the domain contents will be read and automatically merged together.

Using the [command line interface](https://legacy-docs-oss.rasa.com/docs/rasa/command-line-interface#rasa-train), you can train a model with split domain files by running:

```bash
rasa train --domain path_to_domain_directory

Intents

The intents key in your domain file lists all intents used in your NLU data and conversation training data.

Ignoring Entities for Certain Intents

To ignore all entities for certain intents, you can add the use_entities: [] parameter to the intent in your domain file like this:

intents:
  - greet:
      use_entities: []

To ignore some entities or explicitly take only certain entities into account you can use this syntax:

intents:
  - greet:
      use_entities:
        - name
        - first_name
  - farewell:
      ignore_entities:
        - location
        - age
        - last_name

You can only use_entities or ignore_entities for any single intent.

Excluded entities for those intents will be unfeaturized and therefore will not impact the next action predictions. This is useful when you have an intent where you don't care about the entities being picked up.

If you list your intents without a use_entities or ignore_entities parameter, the entities will be featurized as normal.

It is also possible to ignore an entity for all intents by setting the influence_conversation flag to false for the entity itself. See the entities section for details.

Entities

New in 3.1

As of 3.1, you can use the influence_conversation flag under entities. The flag can be set to false to declare that an entity should not be featurized for any intents. It is a shorthand syntax for adding an entity to the ignore_entities list of every intent in the domain. The flag is optional and default behavior remains unchanged.

The entities section lists all entities that can be extracted by any entity extractor in your NLU pipeline.

For example:

entities:
  - PERSON  # entity extracted by SpacyEntityExtractor
  - time    # entity extracted by DucklingEntityExtractor
  - membership_type  # custom entity extracted by DIETClassifier
  - priority  # custom entity extracted by DIETClassifier

When using multiple domain files, entities can be specified in any domain file, and can be used or ignored by any intent in any domain file.

If you are using the feature Entity Roles and Groups you also need to list the roles and groups of an entity in this section.

For example:

entities:
  - city:  # custom entity extracted by DIETClassifier
      roles:
        - from
        - to
  - topping:  # custom entity extracted by DIETClassifier
      groups:
        - 1
        - 2
  - size:  # custom entity extracted by DIETClassifier
      groups:
        - 1
        - 2

By default, entities influence action prediction. To prevent extracted entities from influencing the conversation for specific intents you can ignore entities for certain intents.

To ignore an entity for all intents, without having to list it under the ignore_entities flag of each intent, you can set the flag influence_conversation to false under the entity:

entities:
  - location:
      influence_conversation: false

This syntax has the same effect as adding the entity to the ignore_entities list for every intent in the domain.

Slots

Slots are your bot's memory. They act as a key-value store which can be used to store information the user provided (e.g their home city) as well as information gathered about the outside world (e.g. the result of a database query).

Slots are defined in the slots section of your domain with their name, type and if and how they should influence the assistant's behavior.

The following example defines a slot with name "slot_name", type text and predefined slot mapping from_entity.

slots:
  slot_name:
    type: text
    mappings:
      - type: from_entity
        entity: entity_name

Slots and Conversation Behavior

You can specify whether or not a slot influences the conversation with the influence_conversation property.

If you want to store information in a slot without it influencing the conversation, set influence_conversation: false when defining your slot.

The following example defines a slot age which will store information about the user's age, but which will not influence the flow of the conversation. This means that the assistant will ignore the value of the slot each time it predicts the next action.

slots:
  age:
    type: text
    influence_conversation: false

When defining a slot, if you leave out influence_conversation or set it to true, that slot will influence the next action prediction, unless it has slot type any. The way the slot influences the conversation will depend on its slot type.

The following example defines a slot home_city that influences the conversation. A text slot will influence the assistant's behavior depending on whether the slot has a value. The specific value of a text slot (e.g. Bangalore or New York or Hong Kong) doesn't make any difference.

slots:
  home_city:
    type: text
    influence_conversation: true

As an example, consider the two inputs "What is the weather like?" and "What is the weather like in Bangalore?". The conversation should diverge based on whether the home_city slot was set automatically by the NLU. If the slot is already set, the bot can predict the action_forecast action. If the slot is not set, it needs to get the home_city information before it is able to predict the weather.

Slot Types

Text Slot

slots:
  cuisine:
    type: text
    mappings:
      - type: from_entity
        entity: cuisine

Boolean Slot

slots:
  is_authenticated:
    type: bool
    mappings:
      - type: custom

Categorical Slot

slots:
  risk_level:
    type: categorical
    values:
      - low
      - medium
      - high
    mappings:
      - type: custom

Float Slot

slots:
  temperature:
    type: float
    min_value: -100.0
    max_value: 100.0
    mappings:
      - type: custom

List Slot

slots:
  shopping_items:
    type: list
    mappings:
      - type: from_entity
        entity: shopping_item

Any Slot

slots:
  shopping_items:
    type: any
    mappings:
      - type: custom

Custom Slot Types

You can define a custom slot class to handle specific behaviors and featurization.

Slot Mappings

As of 3.0, slot mappings are defined in the slots section of the domain. You will need to explicitly define slot mappings for each slot in the slots section of domain.yml.

from_entity

The from_entity slot mapping fills slots based on extracted entities.

slots:
  slot_name:
    type: any
    mappings:
      - type: from_entity
        entity: entity_name