Skip to main content
For a complete overview of the interactivity system, please read the Actions guide.
This guide focuses on Custom Actions, which allow you to go beyond the built-in behaviors and trigger your application’s unique functions directly from the C1 UI. This makes the generative interface a true, interactive part of your application, enabling powerful workflows such as:
  • 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 a download_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 a c1_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.
When the LLM generates a UI that includes a “Download Report” button, it will attach the action type download_report and the corresponding parameters to it.

2. Handle the Custom Action (Frontend)

On the frontend, you use the same onAction 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.
Using <C1Chat>
If you are using persistence with the useThreadManager hook, you need to pass the onAction callback directly to the hook.
The <C1Chat> component handles built-in actions automatically, so its onAction prop is used exclusively for your custom actions.