View on GitHub

rasa-java-action-service

A Java based Rasa Action Server

rasa-java-action-service

A Java based Rasa Action Server

The rasa-java-action-service is an environment for building your Rasa Custom Actions with Java.

The rasa-java-action-service is inspired by Rafał Bajek’s Action Server implementation and uses his SDK

Version

current version: 0.2.0 (unstable)

Installation

The rasa-java-action-service is not a ‘ready to use’ application. It functions as a template and starting point to build your Rasa assistant’s fulfillment. Therefore, just clone this repo and start.

You need to install Docker and Docker Compose.

Use Case

Use the rasa-java-action-service if you consider building your Rasa Action Server with Java.

Background

Almost every advanced, business integrated conversational AI system has the ability to perform business logic procedures during a conversation with the user - be it a calculation, a database query or an API call. This ability is called fulfillment and is typically organized in so-called Actions. An Action is a part of code which is responsible for one independent business logic procedure.

In Rasa, Actions are placed within the Rasa Action Server. If Rasa predicts an Action to be executed, it calls the Action Server which executes the Action thereupon and responds with an enriched response object to the Rasa Server.

Usage

The rasa-java-action-service provides an initial set-up configuration which makes a quick development start possible.

Start

Development

See the Rasa Docs if you want to know how to build conversational assistants with Rasa.

Build your Actions with the rasa-java-action-service by just implementing the Action interface and declaring them with the Spring @Component annotation:

@Component
public class ActionSample implements Action {
    
    @Override
    public String name() {
        return "<name of you Action as defined in domain.yml file>";
    }

    @Override
    public List<AbstractEvent> run(CollectingDispatcher dispatcher, Tracker tracker, Domain domain) {
        
        List<AbstractEvent> eventList = null;
        //your Custom Action code
        //...
        
        //provide your responses
        dispatcher.utterMessage("<your message>");
        
        //provide events
        return eventList;
    }

}

See also the sample Action ActionSample in the actions package.

For local development just edit the .yml files in the rasabot folder. Afterwards you need to re-train your bot. See start section how to train the bot and start a conversation in the Rasa Shell.

Deployment

If your Actions are implemented, then your Action Server is ready for deployment. You can deploy your Action Server everywhere where you have Docker and Docker Compose installed and access to your project.

After Deployment

After your Action Server and Rasa are deployed, you can talk with or train your Rasa bot either in the Rasa Shell as shown in the start section or using the Rasa Open Source HTTP API.

If you want to build your Rasa assistant with Java you should use the rasa-java-client-library.

Experimental

Within the rasa_server container a flask application will be started listening on exposed port 4000. Attention! This is an experimental feature! The flask server provides an endpoint called http://localhost:4000/commands/rasa and can be used to control Rasa by requesting Rasa CLI commands. Interactive commands like rasa shell or rasa interactive won’t work.

Usage

A request like this:

curl -X POST -H 'Content-Type: application/json' -d '{"args": ["train", "--num-threads", "4"]}' http://localhost:4000/commands/rasa

… will return a JSON response like this:

{
   "key": "123456",
   "result_url": "http://localhost:4000/commands/rasa?key=123456",
   "status": "running"
}

now you can poll on the delivered key:

curl http://localhost:4000/commands/rasa?key=123456

… to get the result when the command returns:

{
  "report": "<rasa train output>",
  "key": "123456",
  "start_time": 1593019807.7754705,
  "end_time": 7593019807.782958,
  "process_time": 6.00748753547668457,
  "returncode": 0,
  "error": null
}