Ask for the user to complete a custom element (fill a form) before continuing.
This allows agents to send interactive, consent-gated UI components to the front end, let users review or edit their values, and submit them back to the backend.If the user does not answer in time (see timeout), a TimeoutError will be raised or None will be returned depending on raise_on_timeout parameter.
If a project ID is configured, the messages will be uploaded to the cloud storage.
Attributes
str
The content of the message.
CustomElement
The CustomElement to display to the user for interaction.
str
default:"config.ui.name"
The author of the message, defaults to the chatbot name defined in your
config.
int
default:90
The number of seconds to wait for an answer before raising a TimeoutError.
bool
default:false
Whether to raise a socketio TimeoutError if the user does not answer in time.
Returns
AskElementResponse | None
The response from the user containing the submitted element data.
Example
Backend: Ask To Fill Jira Ticket Form
import chainlit as cl@cl.on_chat_startasync def on_start(): element = cl.CustomElement( name="JiraTicket", display="inline", props={ "timeout": 20, "fields": [ {"id": "summary", "label": "Summary", "type": "text", "required": True}, {"id": "description", "label": "Description", "type": "textarea"}, { "id": "due", "label": "Due Date", "type": "date", }, { "id": "priority", "label": "Priority", "type": "select", "options": ["Low", "Medium", "High"], "value": "Medium", "required": True, }, ], }, ) res = await cl.AskElementMessage( content="Create a new Jira ticket:", element=element, timeout=10 ).send() if res and res.get("submitted"): await cl.Message( content=f"Ticket '{res['summary']}' with priority {res['priority']} submitted" ).send()
Frontend: Jira Ticket Custom Element Implementation
The custom element should be implemented as a React component that handles form submission. Here’s an example for the LogExpense component: