# Rasa 1.0 Mapping Policy

**URL:** <https://forum.rasa.com/t/rasa-1-0-mapping-policy/10893>\
**Category:** Rasa Open Source\
**Created:** [June 3, 2019, 5:06pm UTC](https://forum.rasa.com/t/rasa-1-0-mapping-policy/10893 "2019-06-03T17:06:27Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikki](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nikki/32/2921_2.png) [@Nikki](https://forum.rasa.com/u/Nikki)\
**Post date:** [June 3, 2019, 5:06pm UTC](https://forum.rasa.com/t/rasa-1-0-mapping-policy/10893/1 "2019-06-03T17:06:27Z")

</div>

Hi, I had been figuring out the Mapping Policy for a while, at first with rasa 0.14.4 but now I have updated to rasa 1.0 hoping it will work there.

Right now, I get an error:

```auto
...Anaconda3\envs\lewis\lib\site-packages\rasa_sdk\interfaces.py", line 175, in name
    raise NotImplementedError("An action must implement a name")
NotImplementedError: An action must implement a name

```

The steps I followed for the Mapping Policy were:

Add MappingPolicy() to the training:

```auto
async def train_core():
    """Trains the core"""
    agent = Agent(
        DOMAIN,
        policies=[
            MemoizationPolicy(max_history=10),
            MappingPolicy()],
    )

    training_data = await agent.load_data(STORIES)
    agent.train(training_data)

    # Attention: agent.persist stores the model and all meta data into a folder.
    # The folder itself is not zipped.
    agent.persist(os.path.join(MODEL_PATH, MODEL_NAME, "core"))

```

Add a trigger to the intent in the domain.yml

```auto
intents:
  - faq_enrollment:
      triggers: action_faq_enrollment

actions:
  - utter_faq_enrollment
  - action_faq_enrollment

```

Create a new file called actions.py and put this in there:

```auto
from rasa_sdk import Action
from rasa_sdk.events import UserUtteranceReverted

class FaqEnrollment(Action):
    """Revertible mapped action for utter_faq_enrollment"""

  def name(self):
      return "action_faq_enrollment"

  def run(self, dispatcher, tracker, domain):
    
 
 dispatcher.utter_template("utter_faq_enrollment", tracker)
    return [UserUtteranceReverted()] 

```

And then I ran `python -m rasa_sdk --actions actions`, as stated in the [docs](http://rasa.com/docs/rasa/core/actions/#custom-actions). That’s when I got the error.

And when I just train and test the bot, it stops whenever the FAQ is asked.

Can anybody help me setting up the Mappig Policy? Or does anybody have another idea for handling FAQ’s randomly throughout the conversation without disturbing the story?

---

<div class="post-metadata">

**Author:** ![lgrinberg](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/lgrinberg/32/1659_2.png) [@lgrinberg](https://forum.rasa.com/u/lgrinberg)\
**Post date:** [June 5, 2019, 2:22am UTC](https://forum.rasa.com/t/rasa-1-0-mapping-policy/10893/2 "2019-06-05T02:22:43Z")

</div>

I think your format in domain.yml might be wrong try this:

# add your intents

- stop: {triggers: action\_stop}
- wait: {triggers: action\_waiting}

---

<div class="post-metadata">

**Author:** ![XufengXufengXufeng](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/xufengxufengxufeng/32/2380_2.png) [@XufengXufengXufeng](https://forum.rasa.com/u/XufengXufengXufeng)\
**Post date:** [June 5, 2019, 2:55am UTC](https://forum.rasa.com/t/rasa-1-0-mapping-policy/10893/3 "2019-06-05T02:55:15Z")

</div>

hi @Nikki, how did you import the MappingPolicy? I can’t find it.

---

<div class="post-metadata">

**Author:** ![Nikki](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nikki/32/2921_2.png) [@Nikki](https://forum.rasa.com/u/Nikki)\
**Post date:** [June 5, 2019, 8:17am UTC](https://forum.rasa.com/t/rasa-1-0-mapping-policy/10893/4 "2019-06-05T08:17:07Z")

</div>

Hi @lgrinberg!

I think it changed with rasa 1.0 to what I did, but I tried your solution and unfortunately it did not work

---

<div class="post-metadata">

**Author:** ![Nikki](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nikki/32/2921_2.png) [@Nikki](https://forum.rasa.com/u/Nikki)\
**Post date:** [June 5, 2019, 8:19am UTC](https://forum.rasa.com/t/rasa-1-0-mapping-policy/10893/5 "2019-06-05T08:19:40Z")

</div>

Hi @XufengXufengXufeng!

I imported it in my training file. Just to be sure I did nothing weird there, it looks like this:

```auto
# pylint: disable=E0611, E0001, R0801
"""From the Rasa Restaurantbot example
https://github.com/RasaHQ/rasa/blob/master/examples/restaurantbot/run.py"""
import os
import asyncio
from rasa.core.agent import Agent
from rasa.core.policies.memoization import MemoizationPolicy
from rasa.core.policies.mapping_policy import MappingPolicy
from rasa.nlu.training_data import load_data
from rasa.nlu import config
from rasa.nlu.model import Trainer

DOMAIN = "nlu_db/domain.yml"
MODEL_PATH = "nlu_db/models"
MODEL_NAME = "current"
STORIES = "nlu_db/data/stories.md"
CONFIG = "nlu_db/config.yml"
NLU = "nlu_db/data/nlu.md"

async def train_core():
    """Trains the core"""
    agent = Agent(
        DOMAIN,
        policies=[
            MemoizationPolicy(max_history=10),
            MappingPolicy()],
    )

    training_data = await agent.load_data(STORIES)
    agent.train(training_data)

    # Attention: agent.persist stores the model and all meta data into a folder.
    # The folder itself is not zipped.
    agent.persist(os.path.join(MODEL_PATH, MODEL_NAME, "core"))

def train_nlu():
    """Trains the NLU"""
    training_data = load_data(NLU)
    trainer = Trainer(config.load(CONFIG))
    trainer.train(training_data)

    # Attention: trainer.persist stores the model and all meta data into a folder.
    # The folder itself is not zipped.
    model_directory = trainer.persist(os.path.join(MODEL_PATH, MODEL_NAME), fixed_model_name="nlu")
    return model_directory

if __name__ == " __main__":
    LOOP = asyncio.get_event_loop()
    print("Training Lewis' NLU..")
    train_nlu()
    print("Training Lewis' core..")
    LOOP.run_until_complete(train_core())
    print("Training bot for Rasa X..")
    os.chdir("nlu_db/")
    os.system("rasa train")

```

But I made an `actions.py` file for custom actions, which is in the root folder. However, I am not sure how to include this file in my training… How does Rasa know it should use `actions.py`?

**EDIT:**

When I run `python -m rasa_sdk --actions actions` it now gives no error (I’dput `actions.py` in the wrong folder at first), but this:

```auto
2019-06-05 10:20:03 INFO rasa_sdk.endpoint - Starting action endpoint server...
2019-06-05 10:20:03 INFO rasa_sdk.executor - Registered function for 'action_faq_enrollment'.
2019-06-05 10:20:03 INFO rasa_sdk.endpoint - Action endpoint is up and running. on ('0.0.0.0', 5055)

```

And it keeps running. What is the point there?

**EDIT #2:**

I’m thinking it uses some server? But we use our own local server. I just want to include the `actions.py` file when training to use Mapping Policy…

---

<div class="post-metadata">

**Author:** ![Nikki](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nikki/32/2921_2.png) [@Nikki](https://forum.rasa.com/u/Nikki)\
**Post date:** [June 6, 2019, 9:58am UTC](https://forum.rasa.com/t/rasa-1-0-mapping-policy/10893/6 "2019-06-06T09:58:37Z")

</div>

OK, in case anyone is still struggling with the Mapping Policy of Rasa 1.0, this is what I did to make it work:

Put this in `endpoints.yml`

```auto
action_endpoint:
  url: "http://localhost:5055/webhook"

```

Create an `actions.py` in your working folder with your custom action. For me, this was:

```auto
from rasa_sdk import Action
from rasa_sdk.events import UserUtteranceReverted

class FaqEnrollment(Action):
    """Revertible mapped action for utter_faq_enrollment"""

    def name(self):
        return "action_faq_enrollment"

    def run(self, dispatcher, tracker, domain):
        dispatcher.utter_template("utter_faq_enrollment", tracker)
        return [UserUtteranceReverted()]

```

Wherever you load your bot, put an argument `action_endpoint` along with it. You should do import the endpoint config (`from rasa.utils.endpoints import EndpointConfig`) and set `action_endpoint = EndpointConfig(url="http://localhost:5055/webhook")`. I had to do this in my training file and my file to run the chat. Just in case:

```auto
ENDPOINT = EndpointConfig(url="http://localhost:5055/webhook")

async def train_core():
    """Trains the core"""
    agent = Agent(
        DOMAIN,
        policies=[
            MemoizationPolicy(max_history=10),
            MappingPolicy()],
        action_endpoint=ENDPOINT
    )

```

Now put the trigger in your `domain.yml`. Example:

```auto
intents:
  - faq_enrollment:
      triggers: action_faq_enrollment

```

And don’t include any of these in your `stories.md`

Now, to run it you need to open your command prompt. Type: `rasa run actions --actions actions` (assuming your file is called `actions.py`, otherwise change the last “actions” in the command).

In another command prompt, train your bot and run the chat.

It should work now!

---

<div class="post-metadata">

**Author:** ![lingvisa](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/lingvisa/32/2125_2.png) [@lingvisa](https://forum.rasa.com/u/lingvisa)\
**Post date:** [June 25, 2019, 2:25pm UTC](https://forum.rasa.com/t/rasa-1-0-mapping-policy/10893/7 "2019-06-25T14:25:15Z")

</div>

Hi, all:

In my domain file, it always a domain syntax error:

```
 - request_music
      triggers: action_ask_weather

```

`rasa.core.domain.InvalidDomain: The provided domain file is invalid. You can use http://www.yamllint.com/ to validate the yaml syntax of your domain file.`

The problem occurs only after I added the ‘trigger:…’ part. Otherwise, it works well.

Something wrong here?

---

<div class="post-metadata">

**Author:** ![Nikki](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/nikki/32/2921_2.png) [@Nikki](https://forum.rasa.com/u/Nikki)\
**Post date:** [June 25, 2019, 2:53pm UTC](https://forum.rasa.com/t/rasa-1-0-mapping-policy/10893/8 "2019-06-25T14:53:36Z")

</div>

> [@lingvisa](#):
>
> - request\_music triggers: action\_ask\_weather

Don’t you miss a “:”?

```auto
- request_music:
      triggers: action_ask_weather

```

---

<div class="post-metadata">

**Author:** ![lingvisa](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/lingvisa/32/2125_2.png) [@lingvisa](https://forum.rasa.com/u/lingvisa)\
**Post date:** [June 25, 2019, 5:02pm UTC](https://forum.rasa.com/t/rasa-1-0-mapping-policy/10893/9 "2019-06-25T17:02:25Z")

</div>

> [@Nikki](#):
>
> triggers: action\_ask\_weather

Hi, Nikki: That’s a great observation, and it doesn’t report the syntax error anymore. But now I am encountering another issue. Although the custom action is already listed in domain, but it reports this error: `rasa.core.domain.InvalidDomain: Intent 'request_music' is set to trigger action 'action_ask_weather', which is not defined in the domain.`

My actions listed in domain.yml:

```
actions:
  - action_request_music
  - utter_change_music
  - utter_inform_robot

```

Any further idea?

---

<div class="post-metadata">

**Author:** ![erohmensing](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/erohmensing/32/1789_2.png) [@erohmensing](https://forum.rasa.com/u/erohmensing)\
**Post date:** [June 25, 2019, 5:32pm UTC](https://forum.rasa.com/t/rasa-1-0-mapping-policy/10893/10 "2019-06-25T17:32:06Z")

</div>

@lingvisa, well in your trigger you have

```auto
 - request_music
      triggers: action_ask_weather

```

Did you mean to trigger `action_request_music`?

```auto
 - request_music
      triggers: action_request_music

```

---

<div class="post-metadata">

**Author:** ![lingvisa](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/lingvisa/32/2125_2.png) [@lingvisa](https://forum.rasa.com/u/lingvisa)\
**Post date:** [June 25, 2019, 9:24pm UTC](https://forum.rasa.com/t/rasa-1-0-mapping-policy/10893/11 "2019-06-25T21:24:40Z")

</div>

@erohmensing Good catch. My silly question.

---

<div class="post-metadata">

**Author:** ![erohmensing](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/erohmensing/32/1789_2.png) [@erohmensing](https://forum.rasa.com/u/erohmensing)\
**Post date:** [June 26, 2019, 2:22pm UTC](https://forum.rasa.com/t/rasa-1-0-mapping-policy/10893/12 "2019-06-26T14:22:40Z")

</div>

No worries! It happens sometimes 😄

---

<div class="post-metadata">

**Author:** ![hezhefly](https://avatars.discourse-cdn.com/v4/letter/h/839c29/32.png) [@hezhefly](https://forum.rasa.com/u/hezhefly)\
**Post date:** [July 19, 2020, 6:41am UTC](https://forum.rasa.com/t/rasa-1-0-mapping-policy/10893/13 "2020-07-19T06:41:33Z")

</div>

As your solution, I didn’t do anything except giving “dispatcher.utter\_template” method a parameter as “tracker=tracker”, it works, Why 😭😭😭
