Implementing the Generative Loop
The most common way to handle an action is to use it to generate a new response. This is done by sending theaction.llmFriendlyMessage
to your backend, which then calls the C1 API to get a new response.
Here is a complete example of this flow in a React component:
The onAction
Callback
C1Component accepts a callback function. It is called when a user performs an action.
The Action Event Object
TheonAction
callback receives a single argument: the action
event object. This object contains the context of the user’s interaction.
Attributes
-
userFriendlyMessage
(string): User visible; concise, human-readable label for the action. It is used to display the action to the user. In a conversational UI, this is add as user message to the conversation. -
llmFriendlyMessage
(string): Sent to the LLM; context describing what happened. If a form was submitted, this will contain the form values.
Actions in Custom Components
To add handling for actions in custom components, you can use theuseOnAction
hook. See Custom Components for more details.