Setting up CI/CD

Setting up CI/CD

Even though developing a contextual assistant is different from developing traditional software, you should still follow software development best practices. Setting up a Continuous Integration (CI) and Continuous Deployment (CD) pipeline ensures that incremental updates to your bot are improving it, not harming it.

Continuous Integration (CI)

The best way to improve an assistant is with frequent incremental updates. No matter how small a change is, you want to be sure that it doesn’t introduce new problems or negatively impact the performance of your assistant.

It is usually best to run CI checks on merge / pull requests or on commit. Most tests are quick enough to run on every change. However, you can choose to run more resource-intensive tests only when certain files have been changed or when some other indicator is present. For example, if your code is hosted on Github, you can make a test run only if the pull request has a certain label (e.g. “NLU testing required”).

Data validation verifies that there are no mistakes or major inconsistencies in your domain file, NLU data, or story data.

rasa data validate --fail-on-warnings --max-history <max_history>

If data validation results in errors, training a model will also fail. By including the --fail-on-warnings flag, validation will also fail on warnings about problems that won’t prevent training a model, but might indicate messy data, such as actions listed in the domain that aren’t used in any stories.

Data validation includes story structure validation. Story validation checks if you have any stories where different bot actions follow from the same dialogue history. Conflicts between stories will prevent a model from learning the correct pattern for a dialogue. Set the --max-history parameter to the value of max_history for the memoization policy in your config.yml. If you haven’t set one, use the default of 5.

rasa train

Training a model verifies that your NLU pipeline and policy configurations are valid and trainable, and it provides a model to use for test conversations. If it passes the CI tests, then you can also upload the trained model to your server as part of the continuous deployment process.

rasa test --stories tests/conversation_tests.md --fail-on-prediction-errors

The --fail-on-prediction-errors flag ensures the test will fail if any test conversation fails.

You can do this by running NLU testing in cross-validation mode:

rasa test nlu --cross-validation

Continuous Deployment (CD)

To get improvements out to your users frequently, you will want to automate as much of the deployment process as possible.

CD steps usually run on push or merge to a certain branch, once CI checks have succeeded.

curl -k -F "model=@models/my_model.tar.gz" "https://example.rasa.com/api/projects/default/models?api_token={your_api_token}"

Example CI/CD pipelines

As examples, see the CI/CD pipelines for Sara, the Rasa assistant that you can talk to in the Rasa Docs, and Carbon Bot. Both use Github Actions as a CI/CD tool.

These examples are just two of many possibilities. If you have a CI/CD setup you like, please share it with the Rasa community on the forum.

👋 I can help you get started with Rasa and answer your technical questions.