pika,
sql, file, kafka, concurrent_kafka, and http brokers. Write your own
when your messaging system is none of those, or subclass a built-in to change
what it sends.
Before you start
Put your code in a package next toagent.yml: a folder named addons/ with an
empty __init__.py file. Start rasa from the project root so the package can
be imported.
Subclass EventBroker
Import EventBroker from rasa.api.brokers.v1 and implement connect and
publish. close is optional. The base class does nothing, so override it only
when your broker holds a connection it needs to release.
addons/custom_event_broker.py
publish receives each event as a dictionary. The dictionary has envelope
fields, such as conversation_id, timestamp, and sequence, and one payload
key, such as user, bot, or memory_set. See
Conversation events for the full shape. publish is
synchronous, so keep it fast. Hand slow work to a queue or a background worker.
Register the class under event_broker:
integrations.yml
Subclass a built-in broker
To change what a built-in broker sends and keep the rest, subclass it fromrasa.api.brokers.v1 and override publish. Mantle sends events through
publish_batch, which calls publish once per event unless you override
publish_batch too.
This example uses KafkaEventBroker and drops agent replies, so the topic
receives only user messages:
addons/custom_kafka_broker.py
integrations.yml
event_broker apply to
your subclass. Keep type set to the class path, because the built-in name
kafka selects the built-in class.
Versioning
The importrasa.api.brokers.v1 is the version. YAML names only the class. See
Custom integrations: Versioning.