Functions
Functions are the building blocks of Inferable
Functions within your code are registered using one of the Inferable SDKs, this makes the function available as a tool for the agent to use within Runs.
The execution of functions takes place within your environment. Inferable manages a job queue of function calls which is polled by the SDK. This means in order to use a function,
- Your service does not need to expose an endpoint to receive function calls.
- There are no network configuration changes required to run the function.
- The function will be executed in your own VPC, as long as it can connect to the Inferable cluster.
The snippet above registered a function submitTicket
with the default service.
Agents within the same cluster can now invoke this function as needed.
Failure
The result of a function’s handler is always returned to the agent for evaluation, this includes any Errors or Exceptions thrown.
It can be useful to enrich error messages with remediation information.
For example, authentication errors can explain how to re-authenticate if applicable.
Utilities
approvalRequest()
Node | Go | .Net |
---|---|---|
✅ | ✅ | ✅ |
The approvalRequest()
utility is used to pause a Run and request approval before continuing.
The the run can be paused indefinitely until approval is provided.
Approval can be provided via the Playground or manually via the API.
Within the handler, the call’s approval can be checked via context.approval
which is provided as the second argument.
Options
Valid options when registering a function with the SDK.
name
The name of the function that will be provided to the agent.
For best results, function names should be descriptive. Along with the
description
they are used to guide the agent.
description
A human-readable description of the function, use this to augment the agent’s understanding of the function and when to use it.
schema
schema
is only applicable to languages where the Inferable SDK cannot reflect the function type at runtime.
NodeJS require the schema
to be specified, however Go and .Net do not.
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
The handler that will be executed when Inferable invokes the function. This handler runs within your environment.
config
Additional configuration options for the function.
config.retryCountOnStall
Node | Go | .Net |
---|---|---|
✅ | ❌ | ❌ |
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 allotted time. This usually happens if:
- Function fails to complete within the allotted 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.cache
Node | Go | .Net |
---|---|---|
✅ | ❌ | ❌ |
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
Node | Go | .Net |
---|---|---|
✅ | ❌ | ❌ |
When set to true
, the function will not be made available to the agent. This is can be used for functions registered as onStatusChange handlers.
Limitations
Function return values must be JSON serializable
Since the LLM at the heart of Inferable is generating instructions based on the return values of your functions, it’s important that the return values are JSON serializable, so that the AI model can understand them.
Number of functions
Inferable currently supports a maximum of 1000 functions per cluster. This is a soft limit and customers can request an increase by contacting support at [email protected].
Go Struct Reference Limitation in JSON Schema Generation
This section is specific to the Golang SDK. Other language SDKs are not affected by this limitation.
When defining input arguments for your functions, avoid using struct references in Go. Our JSON schema generation doesn’t fully support $ref in the resulting schema, which can lead to issues during function registration and execution.
Here’s an example of what to avoid:
This will cause issues with function registration and execution.
Recommended Approach:
If the SDK detects that you’re using a struct reference, it will log a warning and not register the function.
Was this page helpful?