Functions
Functions are the building blocks of your Inferable services
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.
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:
- Function fails to complete within the alotted timeoutSeconds time.
- Worker stalls due to a machine crash or network problems. (See Recovering from machine failures for more information)
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.