Event Handlers
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:
Event | Description |
---|---|
on_agent_started_speaking | Agent started speaking |
on_user_started_speaking | User started speaking |
on_agent_stopped_speaking | Agent stopped speaking |
on_user_stopped_speaking | User stopped speaking |
on_agent_message_added | Agent message added to the chat history during the session |
on_user_message_added | User message added to the chat history during the session |
on_agent_interrupted | Agent was interrupted by the user while speaking |
on_function_calls_collected | Jay received the complete set of functions to execute from the LLM |
on_function_calls_executed | Jay executed all of the functions that were collected |
on_agent_started_speaking
Called when the agent begins speaking.
Usage
Parameters
Example input
parameter:
on_user_started_speaking
Called when the user starts speaking.
Usage
Parameters
Example input
parameter:
on_user_stopped_speaking
Called when the user stops speaking.
Usage
Parameters
Example input
parameter:
on_agent_stopped_speaking
Called when the agent finishes speaking.
Usage
Parameters
Example input
parameter:
on_user_message_added
Called when the user’s message is added to the chat history during the session.
Usage
Parameters
Example input
parameter:
on_agent_message_added
Called when the agent’s message is added to the chat history during the session.
Usage
Parameters
Example input
parameter:
on_agent_interrupted
Called if the agent is interrupted by the user while speaking.
Usage
Parameters
Example input
parameter:
on_function_calls_collected
Called when Jay receives the complete set of functions to execute from the LLM.
Usage
Parameters
Example input
parameter:
on_function_calls_executed
Called after Jay has executed all the functions the model requested.
Usage
Parameters
Example input
parameter: