One Logo Pool Ball
FoundationModels · IOS API REFERENCE

Tool

protocol · iOS 26.0+ · SDK 27.1

protocol Tool<Arguments, Output> : Sendable

A tool that a model can call to gather information at runtime or perform side effects. Tool calling gives the model the ability to call your code to incorporate up-to-date information like recent events and data from your app. A tool includes a name and a description that the framework puts in the prompt to let the model decide when and how often to call your tool. A `Tool` defines a ``call(arguments:)`` method that takes arguments that conforms to ``ConvertibleFromGeneratedContent``, and returns an output of any type that conforms to ``PromptRepresentable``, allowing the model to understand and reason about in subsequent interactions. Typically, ``Output`` is a `String` or any ``Generable`` types. ```swift struct FindContacts: Tool { let name = "findContacts" let description = "Finds a specific number of contacts" @Generable struct Arguments { @Guide(description: "The number of contacts to get", .range(1...10)) let count: Int } func call(arguments: Arguments) async throws -> [String] { var contacts: [CNContact] = [] // Fetch a number of contacts using the arguments. let formattedContacts = contacts.map { "\($0.givenName) \($0.familyName)" } return formattedContacts } } ``` Tools must conform to <doc://com.apple.documentation/documentation/swift/sendable> so the framework can run them concurrently. If the model needs to pass the output of one tool as the input to another, it executes back-to-back tool calls. You control the life cycle of your tool, so you can track the state of it between calls to the model. For example, you might store a list of database records that you don't want to reuse between tool calls. Prompting the model with tools contributes to the available context window size. When you provide a tool in your generation request, the framework puts the tool definitions --- name, description, parameter information --- in the prompt so the model can decide when and how often to call the tool. After calling your tool, the framework returns the tool's output back to the model for further processing. For more information on managing the context window size, see <doc:managing-the-context-window>.

Members (3)

get · iOS 26.0+

parameters

Swift declaration
var parameters: GenerationSchema { get }

A schema for the parameters this tool accepts.

get · iOS 26.0+

includesSchemaInInstructions

Swift declaration
var includesSchemaInInstructions: Bool { get }

A Boolean value that indicates whether the tool's name, description, and parameters schema are injected into the instructions of sessions that leverage this tool. The default implementation is `true` - Note: This should only be `false` if the model has been trained to have innate knowledge of this tool. For zero-shot prompting, it should always be `true`.

get · iOS 26.0+

name

Swift declaration
var name: String { get }

A unique name for the tool, such as "get_weather", "toggleDarkMode", or "search contacts".

Skipped declarations

No declarations were skipped in this snapshot.

All FoundationModels types →