Tools and Functions
The Vapi4k DSL allows you to assign tools and functions to assistants, which enables an LLM to perform tasks and calculations.
Tools
The tools{}
lambda can contain serviceTool()
, manualTool()
, externalTool()
, and transferTool()
calls.
ServiceTool
The serviceTool()
argument can be either an object instance or a reference to a Kotlin singleton object. The return value and method parameters are limited to types: String
, Int
, Double
, Boolean
, and Unit
.
If you want access to the requestContext value of the tool call in the serviceTool implementation, add a parameter of type RequestContext
to the method signature. It will be automatically injected along with the LLM arguments.
Here are some examples of serviceTool implementations.
In the case of a non-annotated function, only a single method is allowed in the object.
Non-annotated Function
The @ToolCall
and @Param
annotations are used to express intent to the LLM. The @ToolCall
annotation describes when a function or serviceTool should be called, and the @Param
annotation describes the parameters of the function or serviceTool. If a function or serviceTool is not annotated, the LLM will infer when to invoke the function based on the function name and the arguments from the parameter names.
Multiple methods can have @ToolCall
annotations. In addition, other non-annotated methods in the object are also allowed.
Annotated Function
This is an example of using a Kotlin singleton object.
Singleton Object Function
A tool{}
implementation object can also inherit from ToolCallService()
.
Singleton Object Function
ManualTool
A manualTool()
describes a function whose implementation is within the Vapi4k DSL. The parameters are manually extracted from the args
JsonElement, which is the JSON object included in the LLM request. A manualTool()
is not associated with a specific Kotlin object.
ExternalTool
An externalTool()
describes a function executed by a REST endpoint at a specified server.
TransferTool
A transferTool{}
describes a tool that transfers a user to an assistant or a phone/SIP number.
Functions
The functions{}
lambda contains function()
calls. The function()
argument is the same as serviceTool()
calls.