Skip to main content
Event handlers are asynchronous functions that are called when events occur throughout the lifecycle of a session. Event handlers are particularly useful for sending data to external systems, like your database or a third-party analytics service. Event handlers don’t return data; they just respond to events. Sessions are never blocked by the logic in your event handlers, so it’s fine to put slow asynchronous operations in your event handlers. Event handlers are defined as fields on the Agent, as shown in the “Usage” sections below. An agent emits the following events:

on_agent_started_speaking

Called when the agent begins speaking.

Usage

Parameters

Object
required
Example input parameter:

on_user_started_speaking

Called when the user starts speaking.

Usage

Parameters

Object
required
Example input parameter:

on_user_stopped_speaking

Called when the user stops speaking.

Usage

Parameters

Object
required
Example input parameter:

on_agent_stopped_speaking

Called when the agent finishes speaking.

Usage

Parameters

Object
required
Example input parameter:

on_user_message_added

Called when the user’s message is added to the chat history during the session.

Usage

Parameters

Object
required
Example input parameter:

on_agent_message_added

Called when the agent’s message is added to the chat history during the session.

Usage

Parameters

Object
required
Example input parameter:

on_agent_interrupted

Called if the agent is interrupted by the user while speaking.

Usage

Parameters

Object
required
Example input parameter:

on_function_calls_collected

Called when Jay receives the complete set of functions to execute from the LLM.

Usage

Parameters

Object
required
Example input parameter:

on_function_calls_executed

Called after Jay has executed all the functions the model requested.

Usage

Parameters

Object
required
Example input parameter: