For a complete overview of the interactivity system, please read the Actions guide.
- Downloading a generated report.
- Opening a product-specific checkout modal.
- Triggering a function in your application, like creating a new project or sending an email.
Implementing a Custom Action
Let’s walk through an example of implementing adownload_report custom action. It involves two steps: defining the action on your backend and handling it on your frontend.
1. Define the Custom Action (Backend)
To make the LLM aware of your custom action, you must define its name and the parameters it accepts. This is done by passing ac1_custom_actions object within the metadata of your API call.
We recommend using a schema library (like Zod for TypeScript or Pydantic for Python) to define your action’s parameters.
download_report and the corresponding parameters to it.
2. Handle the Custom Action (Frontend)
On the frontend, you use the sameonAction callback from the core Actions guide. You simply add a new case to your switch statement to handle your custom action type.
Using <C1Component>
Your handler should check for the download_report action type and then trigger your application’s logic, like opening a modal or starting a file download.
<C1Chat>
If you are using persistence with the
useThreadManager hook, you need to pass the onAction callback directly to the hook.<C1Chat> component handles built-in actions automatically, so its onAction prop is used exclusively for your custom actions.