Contents

GenerationOptions.ToolCallingMode

A value you use to describe the model behavior when it comes to tool usage.

Declaration

struct ToolCallingMode

Mentioned in

Overview

Use this to control how the model interacts with tools for a given request. Tool calling mode supports three modes:

allowed

The model may call tools. This is the default behavior.

required

The model must call one or more tools before it can respond.

disallowed

The model can’t call any tools and responds using only its own knowledge.

The following changes the mode from required to allowed after the first tool call, which lets the model produce a final response:

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
        }
    }
}

Topics

Getting the tool calling modes

Accessing the content

See Also

Configuring options