Whenever a user connects to your Chainlit app, a new chat session is created. A chat session goes through a life cycle of events, which you can respond to by defining hooks.
The on_chat_end decorator is used to define a hook that is called when the chat session ends either because the user disconnected or started a new chat session.
Copy
@cl.on_chat_enddef on_chat_end(): print("The user disconnected!")
The on_chat_resume decorator is used to define a hook that is called when a user resumes a chat session that was previously disconnected. This can only happen if authentication and data persistence are enabled.
Copy
from chainlit.types import ThreadDict@cl.on_chat_resumeasync def on_chat_resume(thread: ThreadDict): print("The user resumed a previous chat session!")