Agent Actions
Actions allow certain parts of a response to be converted into user interactive elements, like hyperlinks or buttons.
The Actions Array
As part of embedding an agent you can pass an array of actions.
[
{
"pattern": "...", // the regular expression that needs to match, returning groups if necessary
"type": "markdown" // the type of action, markdown means markdown, can also be button or callback
"markdown": "[$match]($1)", // the markdown to replace the matched regex with. Special tokens $match and $1, $2 ... for each match group
}
]
Pattern
This is a regular expression that will match in your response. Typically you would prompt the response to output a specific placeholder Link:http....
and write a regular expression that matches the whole token, AND has a captured group with just the URL. These can be tricky to get right, we suggest using https://regex101.com/ to create your pattern.
Types
markdown replaces the entire match provided in the pattern with the markdown you provide. button replaces the match with a button that when clicked calls the specified callback function (see below for the supported callbacks) response waits until the end of the response then calls the callback specified (we use this to update suggestions)
Match Tokens
The pattern regular expression can include captured groups. You can refer to those groups in the markdown string.
$match will be replaced with the entire match of the regular expression $1, $2 ... will be replaced with the group match of the regular expression.
You can use these to build the markdown text that is used as replacement for the entire match, or the button text.
Callbacks
We provide callback functions in the agent embedded iFrame that you can call (not, at the moment these won't work in the preview window when editing an agent, but will work when a panel is embedded as an iframe or previewed in the agents page).
openUrlActionCallback,
This action opens a url in a new browser tab. It first looks for any supplied arguments eg. openUrlActionCallback(args) for the URL (you can use the match tokens $1, $2 in this argument). If not found it will look in the first capture group of your regex pattern, and if thats not present it uses the entire regax pattern match.
Example, in your agent instructions add: "Always add ::bookademo:: at the end of your responses."
Then in your agent actions
[{
"pattern":"::bookademo::",
"type":"button",
"markdown":"*Book a demo*",
"callback":"openUrlActionCallback(https://calendly.com/troy-magennis-predictabilityatscale/30min)"
}]
copyToClipboardCallback
This action ocopies text to the users clipboard. It first looks for any supplied arguments eg. copyToClipboardCallback(args) for the text (you can use the match tokens $1, $2 in this argument). If not found it will look in the first capture group of your regex pattern, and if thats not present it uses the entire regax pattern match.
Example, in your agent instructions add: "Always format email addresses as ::email:<email>::
."
Then in your agent actions
[{
"pattern":"::email:(.*)::",
"type":"button",
"markdown":"*Copy email: $1*",
"callback":"copyToClipboardCallback"
}]
showAlertCallback
Pops open a model alert. Can be useful for debugging actions.
sendFollowOnPromptCallback
This action continues the chat with a new prompt. It first looks for any supplied arguments eg. sendFollowOnPromptCallback(args) for the prompt (you can use the match tokens $1, $2 in this argument). If not found it will look in the first capture group of your regex pattern, and if thats not present it uses the entire regax pattern match.
Example, in your agent instructions add: "Always add ::Answer again like a pirate:: at the end of your responses."
Then in your agent actions
[{
"pattern":"::Answer again like a pirate::",
"type":"button",
"markdown":"*Piratize the response*",
"callback":"sendFollowOnPromptCallback(Respond with the same response but like a pirate)"
}]
setFollowUpQuestionsCallback
This action will change the suggested follow-on prompts shown after the most recent response. These are intended to keep conversations going, and are best when they change with context. The suggestes are supplied as a pipe | delimited string, for example setFollowUpQuestionsCallback(how do I measure WIP?|What other metrics matter?) as the callback. This callback works best when the type is set to response.
[{
"pattern":"WIP",
"type":"response,"
"markdown":"WIP",
"callback":"setFollowUpQuestionsCallback(how do I measure WIP?|What other metrics matter?)"
}]
openIframeCallback
This action opens a modal iFrame to a url you supply within the chat panel. It first looks for any supplied arguments eg. openIframeCallback(args) for the URL (you can use the match tokens $1, $2 in this argument). If not found it will look in the first capture group of your regex pattern, and if thats not present it uses the entire regex pattern match.
Example, in your agent instructions add: "Always add ::bookdemo:: at the end of your responses."
Then in your agent actions
[{
"pattern":"::bookdemo::",
"type":"button",
"markdown":"*Book a demo*",
"callback":"openUrlActionCallback(https://calendly.com/troy-magennis-predictabilityatscale/30min)"
}]