Skip to main content
A lock store keeps one turn of a conversation running at a time, so user messages are processed in the order they arrive. If a second message for the same conversation arrives while the first is still running, it waits for its ticket. Mantle ships in_memory, redis, and concurrent_redis lock stores. Write your own when your backend is none of those, or subclass the Redis store to change how it behaves.

Before you start

Put your code in a package next to agent.yml: a folder named addons/ with an empty __init__.py file. Start rasa from the project root so the package can be imported.

Subclass BaseLockStore

Import BaseLockStore from rasa.api.locks.v1 and subclass it. Do not subclass LockStore. That is the storage port BaseLockStore is built on. BaseLockStore adds the ticket ordering, so you only write storage methods.
addons/custom_lock_store.py
This example keeps locks in a dictionary, so it runs as written. A dictionary exists in one process only, so with more than one worker or replica, replace the dictionary calls with calls to a shared backend. Keep the four method names and signatures. connect runs once at startup. Use it to open your client with the settings from integrations.yml. Register the class under lock_store:
integrations.yml
Every key under lock_store except type arrives in settings.params. Use ${VAR} for secrets so they stay out of the file.

Subclass the built-in Redis store

To change one behavior of redis and keep the rest, subclass RedisLockStore from the same package. This example logs each save at debug level, using only the conversation ID:
addons/custom_redis_lock_store.py
integrations.yml
The Redis keys (host, port, username, password, and the others in lock_store) work the same way for your subclass. The built-in names redis and concurrent_redis still refer to the built-in classes. Use a module path only for your own class.

Versioning

The import rasa.api.locks.v1 is the version. YAML names only the class. A later version ships with its own BaseLockStore, and your import keeps working while v1 is supported. See Custom integrations: Versioning.