Skip to main content

Handling Events

The SDK provides various events, both on an Agent level and on a specific module level. Those events allow you to customise the behavior of your app or the agent as shown in the Headless Mode example. You can subscribe to these events using the 'subscribe' method and providing a callback function that will be called when the event is triggered:

window.Cartesian('subscribe', event, callback);
info

The different callback signatures can be found in our API Reference.

Available Events

EventDescription
'load'Triggered when the agent Javascript is fully loaded and initialized.
'ready'Triggered when the agent is ready to start or is already running (if autoStart is true).
'stopped'Triggered when the agent stops, including optional error information.
'agent-ui:visibility-changed'Triggered when the agent UI becomes visible or invisible.
'recommendations:received'Triggered when when the agent receives new recommendations.

Example, handling errors with the 'stopped' event

The 'stopped' event is triggered when the agent stops. One of the reasons for stopping the agent is when an error occurs. This makes the 'stopped' event the main place to handle errors in the agent.

window.Cartesian('subscribe', 'stopped', (error) => {
console.error('Agent stopped with error:', error);
});