Rasa: How to pass parameters to a custom action

Created on 1 Mar 2018  ·  10Comments  ·  Source: RasaHQ/rasa

Rasa Core version: 0.8.2

Python version: 2.7

Operating system (windows, osx, ...): Ubuntu 16.04

Issue:
When creating a custom action like the ApiAction example (https://core.rasa.ai/patterns.html#storing-api-responses-in-the-tracker), we could need some parameters (API URL, etc....).
The idea behind this is to be able to define only one action to make as many REST call on different and not known APIs.

How can we pass those parameters in the story ?

* Example Story * :

## story_a
* greetings
  - utter_greetings
  - webhook_action # -> we need parameters here : which API do we call ?

Content of domain file (if used & relevant): Not relevant here.

Most helpful comment

i have a similar requirement we are using our custom UI which interacts with the flask api .Flask uses the rasa core agent to get an answer back . We would like to pass the logged in customer id to the custom action so the utter_message is dynamic from the custom action .

Any thoughts would help

All 10 comments

@Kaijiro You can write your own defined function to call the API and call the function using your custom action. I am not sure if you are trying to do anything different.

The idea behind this is to create a UI where you can build many stories.

When building a story, the user can choose between many actions : sending a message, calling an API, etc ...
I would like the user to choose which API to call, which parameters to send, etc., but without creating an action class for each API we can call.
The actions will be stored in a database and when the user trains the agent, we will transform the stored actions in a story file.

We would like to have something like that :

## story_a
* greetings
  - utter_greetings
  - webhook_action_b07b9ef2-1df4-11e8-b467-0ed5f89f718b

where b07b9ef2-1df4-11e8-b467-0ed5f89f718b is the UUID of the action. When calling my ApiAction, I would Rasa to pass it the UUID. Is it possible ?

Option 1:
Right now, this is the solution that would require the least changes on the existing code base.
There is a so called action_factory that defines how the action classes are instantiated based on the
actions listed in the domain file. So what you'd need to do is:

  1. create your own action factory, quite similar to the remote action factory that is used for the HTTP endpoint (https://github.com/RasaHQ/rasa_core/blob/master/rasa_core/actions/factories.py#L82) - it basically gets passed the names of the actions from the domain file and then creates class instances from it
  2. add your factory to https://github.com/RasaHQ/rasa_core/blob/master/rasa_core/actions/factories.py#L18
  3. specify your factory in the domain file using:
slots: ...
factory: my_factory
actions: ...

Option 2:
An alternative would be to directly use the remote action factory: It will instantiate the same class, RemoteAction for all the actions defined in the domain. So instead of modifying Rasa Core, you could communicate with the Core HTTP server http://core.rasa.ai/http.html and run the actions on your end.

@Kaijiro that is what we did for rasa-ui. Instead of modifying rasa core we are dealing with “utter_webook” and “utter” type of actions only. First one a reserved word in rasa ui and the second reserved for rasa core. The plan is to have the ui route to appropriate webhook with the tracker info after calling corehttp server.

i have a similar requirement we are using our custom UI which interacts with the flask api .Flask uses the rasa core agent to get an answer back . We would like to pass the logged in customer id to the custom action so the utter_message is dynamic from the custom action .

Any thoughts would help

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically closed due to inactivity. Please create a new issue if you need more help.

Did you find a solution for this issue ?

Hi @Kaijiro , we have the same issue and we want to call multi API at run time, we need to pass these APIs as parameters through the tracker, to use it in the custom action, what is the idea of your final solution for this issue?

any help will be appreciated

Thanks

Hi @Kaijiro , we have the same issue and we want to call multi API at run time, we need to pass these APIs as parameters through the tracker, to use it in the custom action, what is the idea of your final solution for this issue?

any help will be appreciated

Thanks

Where you able to find any way ?. i see some suggesting to use the slots to store and retrieve on the custom actions function.!

Was this page helpful?
0 / 5 - 0 ratings