Domains
These docs are for version 1.x of Rasa Open Source.
User Guide
- Installation
- Tutorial: Rasa Basics
- Tutorial: Building Assistants
- Command Line Interface
- Architecture
- Messaging and Voice Channels
- Evaluating Models
- Validate Data
- Configuring the HTTP API
- Deploying your Rasa Assistant
- Cloud Storage
NLU
- About
- Using NLU Only
- Training Data Format
- Choosing a Pipeline
- Language Support
- Entity Extraction
- Components
Core
- About
- Stories
- Domains
- Responses
- Actions
- Policies
- Slots
- Forms
- Retrieval Actions
- Interactive Learning
- Fallback Actions
- Knowledge Base Actions
Conversation Design
API Reference
- Action Server
- HTTP API
- Jupyter Notebooks
- Agent
- Custom NLU Components
- Rasa SDK
- Events
- Tracker
- Tracker Stores
- Event Brokers
- Lock Stores
- Training Data Importers
- Featurization of Conversations
- Migration Guide
- Rasa OSS Change Log
Migrate from (beta)
Reference
Domains
The Domain defines the universe in which your assistant operates. It specifies the intents, entities, slots, and actions your bot should know about. Optionally, it can also include responses for the things your bot can say.
An example of a Domain
As an example, the DefaultDomain has the following yaml definition:
intents:
- greet
- goodbye
- affirm
- deny
- mood_great
- mood_unhappy
- bot_challenge
actions:
- utter_greet
- utter_cheer_up
- utter_did_that_help
- utter_happy
- utter_goodbye
- utter_iamabot
responses:
utter_greet:
- text: "Hey! How are you?"
utter_cheer_up:
- text: "Here is something to cheer you up:"
image: "https://i.imgur.com/nGF1K8f.jpg"
utter_did_that_help:
- text: "Did that help you?"
utter_happy:
- text: "Great, carry on!"
utter_goodbye:
- text: "Bye"
utter_iamabot:
- text: "I am a bot, powered by Rasa."
session_config:
session_expiration_time: 60
carry_over_slots_to_new_session: true
Custom Actions and Slots
To reference slots in your domain, you need to reference them by their module path. To reference custom actions, use their name. For example, if you have a module called my_actions containing a class MyAwesomeAction, and module my_slots containing MyAwesomeSlot, you would add these lines to the domain file:
actions:
- my_custom_action
...
slots:
- my_slots.MyAwesomeSlot
Responses
Responses are messages the bot will send back to the user. There are two ways to use these responses:
- If the name of the response starts with
utter_, the response can directly be used as an action. You would add the response to the domain:
responses:
utter_greet:
- text: "Hey! How are you?"
- You can use the responses to generate response messages from your custom actions using the dispatcher:
dispatcher.utter_message(template="utter_greet").
from rasa_sdk.actions import Action
class ActionGreet(Action):
def name(self):
return 'action_greet'
def run(self, dispatcher, tracker, domain):
dispatcher.utter_message(template="utter_greet")
return []
Images and Buttons
Responses defined in a domain’s yaml file can contain images and buttons as well:
responses:
utter_greet:
- text: "Hey! How are you?"
buttons:
- title: "great"
payload: "great"
- title: "super sad"
payload: "super sad"
utter_cheer_up:
- text: "Here is something to cheer you up:"
image: "https://i.imgur.com/nGF1K8f.jpg"
Custom Output Payloads
You can also send any arbitrary output to the output channel using the custom: key. Note that since the domain is in yaml format, the json payload should first be converted to yaml format.
responses:
utter_take_bet:
- custom:
blocks:
- type: section
text:
text: "Make a bet on when the world will end:"
type: mrkdwn
accessory:
type: datepicker
initial_date: '2019-05-21'
placeholder:
type: plain_text
text: Select a date
Channel-Specific Responses
For each response, you can have multiple response templates. If you have certain response templates that you would like sent only to specific channels, you can specify this with the channel: key.
responses:
utter_ask_game:
- text: "Which game would you like to play?"
channel: "slack"
custom:
- # payload for Slack dropdown menu to choose a game
- text: "Which game would you like to play?"
buttons:
- title: "Chess"
payload: '/inform{"game": "chess"}'
- title: "Checkers"
payload: '/inform{"game": "checkers"}'
- title: "Fortnite"
payload: '/inform{"game": "fortnite"}'
Variables
You can also use variables in your responses to insert information collected during the dialogue.
responses:
utter_greet:
- text: "Hey, {name}. How are you?"
Variations
If you want to randomly vary the response sent to the user, you can list multiple response templates and Rasa will randomly pick one of them:
responses:
utter_greeting:
- text: "Hey, {name}. How are you?"
- text: "Hey, {name}. How is your day going?"
Ignoring entities for certain intents
If you want all entities to be ignored for certain intents, you can add the use_entities: [] parameter to the intent in your domain file.
intents:
- greet:
use_entities: []
Session configuration
A conversation session represents the dialogue between the assistant and the user. Conversation sessions can begin in three ways:
- the user begins the conversation with the assistant,
- the user sends their first message after a configurable period of inactivity,
- a manual session start is triggered with the
/session_startintent message.
You can define the period of inactivity after which a new conversation session is triggered in the domain under the session_config key.
session_config:
session_expiration_time: 60 # value in minutes, 0 means infinitely long
carry_over_slots_to_new_session: true # set to false to forget slots between sessions