One Logo Pool Ball
FoundationModels · IOS API REFERENCE

GenerationOptions.ToolCallingMode

struct · iOS 27.0+ · SDK 27.1

struct ToolCallingMode

A value you use to describe the model behavior when it comes to tool usage. Use this to control how the model interacts with tools for a given request. Tool calling mode supports three modes: - term ``GenerationOptions/ToolCallingMode/allowed``: The model may call tools. This is the default behavior. - term ``GenerationOptions/ToolCallingMode/required``: The model must call one or more tools before it can respond. - term ``GenerationOptions/ToolCallingMode/disallowed``: The model can't call any tools and responds using only its own knowledge. The following changes the mode from ``GenerationOptions/ToolCallingMode/required`` to ``GenerationOptions/ToolCallingMode/allowed`` after the first tool call, which lets the model produce a final response: ```swift extension SessionPropertyValues { @SessionPropertyEntry var toolCallCount: Int = 0 } struct RecipeDynamicProfile: LanguageModelSession.DynamicProfile { @SessionProperty(\.toolCallCount) var toolCallCount var body: some LanguageModelSession.DynamicProfile { Profile { BreadDatabaseTool() } .toolCallingMode(toolCallCount < 1 ? .required : .allowed) .onToolCall { toolCallCount += 1 } } } ``` > Important: When you set the mode to ``GenerationOptions/ToolCallingMode/required``, you must define an exit condition by either throwing an error from a tool's ``Tool/call(arguments:)`` method or by changing the mode dynamically using a ``LanguageModelSession/DynamicProfile``; otherwise, the model continues to call the tool.

Members (5)

get · iOS 27.0+

disallowed

TypeScript
static get disallowed(): GenerationOptions_ToolCallingMode
Swift declaration
static let disallowed: GenerationOptions.ToolCallingMode

The model may not call any tool.

get · iOS 27.0+

kind

TypeScript
get kind(): GenerationOptions_ToolCallingMode_Kind
Swift declaration
var kind: GenerationOptions.ToolCallingMode.Kind
set · iOS 27.0+

kind

TypeScript
set kind(value: GenerationOptions_ToolCallingMode_Kind)
Swift declaration
var kind: GenerationOptions.ToolCallingMode.Kind
get · iOS 27.0+

allowed

TypeScript
static get allowed(): GenerationOptions_ToolCallingMode
Swift declaration
static let allowed: GenerationOptions.ToolCallingMode

The model may or may not call tools. This is the default.

get · iOS 27.0+

required

TypeScript
static get required(): GenerationOptions_ToolCallingMode
Swift declaration
static let required: GenerationOptions.ToolCallingMode

The model must call one or multiple tools. Please note that ``LanguageModelSession`` will loop until a `Tool` throws an error or this value is changed dynamically via `LanguageModelSession.Manifest`.

Skipped declarations

No declarations were skipped in this snapshot.

All FoundationModels types →