Vision and audio-capable models require companion files. Bundles embed these references; GGUF
checkpoints expect siblings such as
mmproj-*.gguf (vision) and audio decoder/tokenizer files.
When detected, you can attach ChatMessageContent.image and ChatMessageContent.audio parts to
your messages and tool responses.Register functions to conversations
To enable function calling, function definitions should be registered to theConversation instance before content generation.
Conversation.registerFunction takes a LeapFunction instance as the input, which describes the name, parameters and ability of the function.
Handle Function Calling Response
Function calling requests by the model will be presented asfunctionCall enum value of MessageResponse, which contains a list of function calls.
LeapFunctionCall instance contains names and arguments of the function call request. The arguments field is a map from String to Any?.
The app needs to check whether the required parameters are filled by the models. It is possible (even though very unlikely to happen) that some
parameters are missing or the function name is invalid.
generateResponse flow:
Function Definition
Functions for models to call are defined byLeapFunction instances. It has three fields:
name is the function name. It is recommended to use only English letters, underscores, and digits (not starting with digits) to compose the
function names because this format is supported by most models. description tells the model what this function is doing. parameters is
the array to declare what arguments (parameters) this function accepts.
The items of parameters are instances of LeapFunctionParameter.
nameThe name of the parameter.typeData type of the parameter.descriptionTells the model what this parameter is about.optionalWhether the parameter is optional.
LeapFunctionParameterType describes the data types of the parameters. They will be translated into JSON Schema for the model to understand.
Following types are supported:
StringType, NumberType and IntegerType have a field of enumValues to restrict the legit values for this parameter.
ArrayType has a field of itemType to describe the type of array items.
ObjectType has a properties field, which is a map from the property names (String) to the property types (LeapFunctionParameterType).
It also has a required field, which is an array of names of required properties.
Each enum value includes a struct to describe the type. All type except NullType has an optional field of description to describe the purpose of this type.
It will be overridden if it is directly used as LeapFunctionParameter.type. It only plays a role if the type instance is used as ArrayType.itemType or the types
in object properties.
Here is a more comprehensive example on defining a function:
Function Call Parser
Function call parsers translate the modelβs tool-call tokens intoLeapFunctionCall values. Different models
emit tool calls in different formats, so pick the parser that matches your checkpoint.
By default, LFMFunctionCallParser is used. It supports Liquid Foundation Model (LFM2) Pythonic-style control tokens (<|tool_call_start|> ... <|tool_call_end|>).
For Qwen3 models and other models that are using Hermes function calling format,
apply HermesFunctionCallParser by injecting a parser instance on the generation options: