The Action class is designed to create and manage actions to be sent and displayed in the chatbot user interface. Actions consist of buttons that the user can interact with, and these interactions trigger specific functionalities within your app.

Attributes

name
str

Name of the action, this should be used in the action_callback

value
str

The value associated with the action. This is useful to differentiate between multiple actions with the same name.

label
str

The label of the action. This is what the user will see. If not provided the name will be used.

description
str

The description of the action. This is what the user will see when they hover the action.

collapsed
bool

Show the action in a drawer menu

Usage

import chainlit as cl

@cl.action_callback("action_button")
async def on_action(action):
    await cl.Message(content=f"Executed {action.name}").send()
    # Optionally remove the action button from the chatbot user interface
    await action.remove()

@cl.on_chat_start
async def start():
    # Sending an action button within a chatbot message
    actions = [
        cl.Action(name="action_button", value="example_value", description="Click me!")
    ]

    await cl.Message(content="Interact with this action button:", actions=actions).send()