Agent Embedding: Actions
Actions allow certain parts of a response to be converted into user interactive elements, like hyperlinks or buttons.
This feature is actively under development. We want feedback and use cases and are happy to partner with you to make sure these work as expected. Email us at help@llmasaservice.io for advice
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, so here are some tips:
- LLMs can be inconsistent even when you say "Exactly do x" they often do "close to x." Test thoroughly, and account for different capitalization, extra spaces, etc.
- Responses stream back in LLMAsAService.io. You ONLY want the match to happen after the full content of the token is finished. Often this means using a regex lookahead to the first whitespace character or some other token marker you add to the end indicating "OK, this token is complete"
- Generate a few responses and then use 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)
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 that you can call.
openUrlActionCallback = opens the first URL it finds in a new window (tab) in match (the match starts with http or mailto), then the groups in order (the fist group that starts with http or mailto) copyToClipboardCallback = if there are groups, copies the first group into the clipboard, else the entire match into the clipboard as text showAlertCallback = if there are groups, pops up a browser alert dialog with the contents of the first group, else the match text