Tool use
Enable AI models to interact with external functions and data sources using tools.
Tools allow you to give AI models access to external functions or data sources, enabling them to perform actions beyond simple text generation. You can define custom tools or use Latitude’s built-in tools.
Tool support depends on the specific AI provider and model. Check your provider’s documentation for compatibility.
Enabling Tools in a Prompt
To make tools available to your prompt, list them under the tools
key in the prompt’s configuration block (---
).
Built-in Latitude Tools
Latitude provides several powerful built-in tools that you can enable directly:
latitude/search
: Performs web searches to find up-to-date information.latitude/code
: Executes code snippets.latitude/extract
: Extracts structured data from text.
Simply include their names (e.g., latitude/search
) in the tools
list.
Learn more about using Latitude Tools.
Defining Custom Tools
For capabilities beyond the built-in tools, you can define your own custom tools. When the model decides to use a custom tool, Latitude will request its execution from your application via the SDK.
Define custom tools directly within the configuration block, outside the main tools
list:
Each custom tool definition requires:
description
: A clear explanation for the AI model of what the tool does.parameters
: A JSON Schema defining the expected input arguments for the tool.
Handling Custom Tool Calls
When the AI model decides to use get_stock_price
, the Latitude SDK in your application will receive a tool call request. Your code needs to:
- Execute the actual logic (e.g., call a financial API).
- Return the result back to Latitude.
Refer to the SDK documentation (TypeScript, Python) for details on handling tool calls.
JSON Schema for Parameters
Tool parameters must be defined using JSON Schema to specify their structure, types, and requirements. This helps the model understand how to call the tool correctly.
Key schema components:
type
:object
,string
,number
,integer
,boolean
,array
.description
: Essential for explaining parameters to the model.properties
(forobject
type): Defines nested parameters.required
(forobject
type): Lists mandatory properties.enum
(forstring
,number
): Specifies allowed values.items
(forarray
type): Defines the schema for array elements.
See the official JSON Schema guide for more details.
Example (Object with multiple parameters):
Next Steps
- Explore Latitude’s Built-in Tools in more detail.
- Learn how to build powerful Agents that leverage tools.
- Test tool interactions in the Playground.