Functions are the building blocks of your Inferable workflows, they are regular JavaScript functions (other languages coming soon) that are made available for use by Inferable.

Anything you can describe in code can be performed in an Inferable function, from sending an email to updating a database record.

Once you have registered a function with Inferable, you can interact with it using natural language commands in the Inferable application.

Registering a function

Let’s register a function for recording support tickets.

inferable/support.ts
import { Inferable } from "inferable";
import { z } from "zod";

// Data store for our support tickets
const supportTickets: { userName: string; userEmail: string; issue: string }[] =
  [];

// Setup a the Inferable client
const client = new Inferable();

// Register a new service "SupportService" with the client
const service = client.service({ name: "SupportService" });

// Register a new function "submitTicket" with the service
service.register({
  name: "submitTicket",
  // A human-readable description of the function used by the agent
  description: "Submit a support ticket",
  schema: {
    // Define the input schema for the function
    input: z.object({
      userName: z.string(),
      userEmail: z.string(),
      issue: z.string(),
    }),
  },
  func: async (input: {
    userName: string;
    userEmail: string;
    issue: string;
  }) => {
    console.log("Submitting support ticket", { input });
    supportTickets.push(input);
    console.log("Support tickets", supportTickets);
  },
});

// Start listening for work
service.start();

That’s it!

You have now registered a function submitTicket with the service SupportService. Agents within the same cluster can now invoke this function as needed.

Check it out in the Inferable console.

Decorators

masked()

The masked() decorator is used to encrypt parts of the return value of a function before it is sent to Inferable. This can be useful when you need to return sensitive information, for example to a customer service agent.

Once the data is encrypted, it cannot be decrypted by Inferable, the agent or the model provider. This means that your agent can’t use the data other than:

  • Displaying it to the user in the app where it is decrypted within the users browser
  • Using it as input to other functions (coming soon)

blob()

The blob() decorator is used to return non-text object as part of a function result. This can be used to return images and other binary data.

Options

name (required)

The name of the function that will be visible in the Inferable console and provided to the agent.

schema (required)

A zod schema that defines the input shape of the function. The schema is used to explain how to use the function, and to validate the input before the function is executed.

func (required)

The function that will be executed when the agent invokes the function.

description

A human-readable description of the function, use this to augment the agent’s understanding of the function and when to use it.

config

Additional configuration options for the function.

config.requiredApproval

When enabled, the agent will require approval from the user before executing the function.

config.retryCountOnStall

The number of times Inferable will retry the function call if the function stalls.

A function can stall if it does not complete within the alotted time. This usually happens if:

Without this configuration, Inferable will not retry the function call.

config.timeoutSeconds

The number of seconds Inferable will wait before timing out the function call.

config.executionIdPath

Used for enforcing idempotency and tracking the execution of a function. The path (described using JSONPath) to the unique identifier in the function’s input.

config.cache

Used to cache the result of the function for a specified amount of time.

  • ttl - The time in milliseconds that the result of the function will be cached.
  • keyPath - The path (described using JSONPath) to the unique identifier in the function’s input.

config.private

When set to true, the function will not be available for use by Inferable run.

This is used by result handler functions.