Tools
Learn how to define tools in your prompts.
Overview
Latitude’s prompt editor allows you to define tools in your prompts. Tools are function calls made available to the AI model during the conversation, enabling it to perform tasks beyond its built-in capabilities.
Tools may not be available for all providers or models. Check the documentation of your provider to see if tools are supported.
Defining Tools
You can define tools as a list of functions. Each tool must include:
- A
name
- A
description
- An optional list of
parameters
When adding parameters to a tool, they must be defined using a JSON object schema, specifying the structure, type, and constraints.
Once defined, the AI may respond with a tool call request. To handle these requests, refer to the Latitude SDK guide here.
JSON Schema
A JSON schema defines the structure and constraints for tool parameters. It ensures the AI knows what inputs are expected and validates them accordingly.
For more details, refer to the official JSON Schema documentation.
General Guidelines:
- Required Properties:
type
(mandatory),description
(optional but recommended). - Flexibility: Additional properties like
minLength
,enum
, orpattern
can be added depending on the parameter type.
Object
An object is a collection of key-value pairs. It is defined with type: object
and can include:
properties
: Specifies the expected key-value pairs.required
: Lists required properties.additionalProperties
: Determines if extra properties are allowed (default:true
).
Example:
String
A string is a sequence of characters. Optional properties include:
enum
: Predefined list of acceptable text values.minLength
/maxLength
: Minimum/maximum string length.pattern
: Regular expression for string validation.
Example:
Number
A number can include:
enum
: Predefined list of acceptable numeric values.minimum
/maximum
: Value constraints.
To define integers, use type: integer
.
Example:
Boolean
A boolean is a true/false value.
Example:
Array
An array is a list of values. Properties include:
items
: Schema for array elements.minItems
/maxItems
: Minimum/maximum number of elements.
Example:
Example
Here’s an example of how you might define a tool to get the current weather for a specified location:
Handling Tool Calls
To handle the tool call response using the Latitude SDK, refer to the Latitude SDK Guide for implementation details.