Main Story - the starting point for a model

Every model begins with the main story, which must be named “main.yaml”.

The main story is special because, unlike normal stories which return to a parent story when it reaches the end, the main story has no parent. Instead, it automatically returns to its own start action once the end of the main story is reached. This effectively keeps the dialog running in a loop where it always comes back to the main starting point, allowing the user to start over with new input.

The main story is also different in that it may optionally specify init_actions, which is an action list that will be run only once when a Diatheke session is initialized from a model.

Example

In this tutorial, we will be building a model that allows zooming in and out and applying filters to a photo. This is a simplified version of the zoom story and apply_filter story defined in the Diatheke demo model the Diatheke demo page.

Like other stories, the main story defines lists of actions. There are different types of actions (which are enumerated here). In order to start simple, the example does not include all the available actions a main story could include. See main.yaml under Reference for a complete list of settings permitted in the main story.

When a Diatheke session is started, and the main story is first loaded, Diatheke will execute the actions under the init_actions. In this example, Diatheke plays a welcome message when the session first begins. That message is defined in a file called welcome_message.yaml in the replies directory. After the reply action, the next action in the list is the input action that has the id main_input. An input action tells diatheke to wait for the user to express various intents.

When Diatheke returns back to the main story from any one of the other stories, the actions under start_actions are executed. The start actions usually include an input action.

In this example, both the init_actions and the start_actions run the main_input action, which is defined under input_actions.
When the user inputs a phrase, the list of actions under the name main_input under input_actions are executed. If the intent is the apply_filter_intent it will run the apply_filter_story, and if the intent is the zoom_intent it will run the zoom_story. Both of those stories are defined in correspondingly named files under the stories folder, which we’ll show in subsequent pages of the tutorial.

There may be cases where the user provides input that is not recognized as either one of those intents. The setting no_intent_actions defines how the model should respond to utterances it doesn’t recognize. The main story defines the default response, and individual stories can override that response with something more specific when no intent is recognized in the context of that story.


init_actions:
  - type: reply
    id: welcome_message
  - type: input
    id: main_input

start_actions:
  - type: input
    id: main_input
    
input_actions:
  - name: main_input
    intents:
      - intent_id: apply_filter_intent
        actions:
          - type: story
            id: apply_filter_story
      - intent_id: zoom_intent
        actions:
          - type: story
            id: zoom_story

defaults:
  no_intent_actions:
    - type: reply
      id: no_intent_reply

language_data:
    en_US:
      - Welcome to the Diatheke tutorial!

language_data:
    en_US:
      - Sorry, I didn't understand that.

Next we’ll look deeper into how the Zoom intent is defined.