Tools
Code tool
Use your own logic during a call. Run JavaScript or TypeScript in an isolated sandbox.
Export one async function. It receives the arguments the model filled in, your environment variables and details of the call. Whatever it returns is handed to the model.
TypeScript
export default async function ({ args, env, call }) {
const res = await fetch(`https://api.example.com/orders/${encodeURIComponent(args.order_id)}`, {
headers: { Authorization: `Bearer ${env.API_KEY}` },
})
if (!res.ok) return { found: false }
const order = await res.json()
console.log('order status', order.status)
return { found: true, status: order.status, eta: order.eta }
}#What the function receives
argsobject- The parameters the model filled in.
envobject- Your environment variables, such as API keys. Names are UPPER_SNAKE_CASE; up to 30 of them.
callobjectid,number,direction,channel,business,assistant,assistant_idandvariables.
#The sandbox
- Code runs with Deno, so
fetch,URL,cryptoand other web APIs are available, and you can import modules by URL. - Each run has up to 30 seconds (10 by default) and about 96 MB of memory.
- It runs as an unprivileged user in a separate container, with no access to BluePenguin's data or other businesses.
- The code can be up to 100,000 characters.
#Logs and errors
console.log output (up to 200 lines) is shown in the test panel and on the call page. If the function throws, the error and stack trace are shown, and the model is told the tool failed.
Tip
Return small objects with only what the caller needs. The model reads the whole result, and long results make replies slower.