Install
openclaw skills install js-literals-protocolImplements a JavaScript literal syntax-based protocol for LLM tool calls. Invoke when needing to enable LLM to call local JS functions using template literal syntax.
openclaw skills install js-literals-protocolThis skill establishes a new protocol for LLM to call tools using JavaScript's template literal syntax. It allows seamless integration between LLM prompts and local JavaScript functions through a tag function mechanism.
The protocol uses JavaScript template literals with tag functions to enable LLM to invoke local functions. This provides a natural, JavaScript-native way for LLMs to interact with tools.
// Define variables
const var1 = value1;
const var2 = value2;
// Define tag function (tool)
function toolTag(strings, ...expressions) {
// Process the strings and expressions
// Return the result
}
// LLM invokes the tool using template literal syntax
const result = toolTag`Template ${var1} with ${var2} expressions`;
// Define variables
const person = "Mike";
const age = 28;
// Define a simple tool function
function describePerson(strings, personExp, ageExp) {
const str0 = strings[0]; // "That "
const str1 = strings[1]; // " is a "
const str2 = strings[2]; // "."
const ageStr = ageExp > 99 ? "centenarian" : "youngster";
return `${str0}${personExp}${str1}${ageStr}${str2}`;
}
// LLM invokes the tool
const output = describePerson`That ${person} is a ${age}.`;
console.log(output);
// Output: That Mike is a youngster.
// Define a calculation tool
function calculate(strings, ...nums) {
const operation = strings.join(' ').trim();
let result;
if (operation.includes('add')) {
result = nums.reduce((a, b) => a + b, 0);
} else if (operation.includes('multiply')) {
result = nums.reduce((a, b) => a * b, 1);
}
return `${operation} ${nums.join(', ')} = ${result}`;
}
// LLM invokes with multiple parameters
const sum = calculate`add ${5} ${3} ${7}`;
const product = calculate`multiply ${2} ${4} ${6}`;
console.log(sum); // Output: add 5, 3, 7 = 15
console.log(product); // Output: multiply 2, 4, 6 = 48
strings as the first parameter and variable expressions as rest parameters${} placeholders