<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "visionOS: 27.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "FoundationModels",
  "identifier" : "/documentation/FoundationModels/GenerationOptions/ToolCallingMode-swift.struct",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Foundation Models",
      "FoundationModels"
    ],
    "preciseIdentifier" : "s:16FoundationModels17GenerationOptionsV15ToolCallingModeV"
  },
  "title" : "GenerationOptions.ToolCallingMode"
}
-->

# GenerationOptions.ToolCallingMode

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

```
struct ToolCallingMode
```

## Overview

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

- [`allowed`](/documentation/FoundationModels/GenerationOptions/ToolCallingMode-swift.struct/allowed): The model may call tools.
  This is the default behavior.
- [`required`](/documentation/FoundationModels/GenerationOptions/ToolCallingMode-swift.struct/required): The model must call one or
  more tools before it can respond.
- [`disallowed`](/documentation/FoundationModels/GenerationOptions/ToolCallingMode-swift.struct/disallowed): The model can’t call any
  tools and responds using only its own knowledge.

The following changes the mode from [`required`](/documentation/FoundationModels/GenerationOptions/ToolCallingMode-swift.struct/required)
to [`allowed`](/documentation/FoundationModels/GenerationOptions/ToolCallingMode-swift.struct/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 ``doc://com.apple.foundationmodels/documentation/FoundationModels/GenerationOptions/ToolCallingMode-swift.struct/required``,
> you must define an exit condition by either throwing an error from a tool’s
> ``doc://com.apple.foundationmodels/documentation/FoundationModels/Tool/call(arguments:)`` method or by changing the mode dynamically using a
> ``doc://com.apple.foundationmodels/documentation/FoundationModels/LanguageModelSession/DynamicProfile``; otherwise, the model continues to call
> the tool.

## Topics

### Getting the tool calling modes

[`allowed`](/documentation/FoundationModels/GenerationOptions/ToolCallingMode-swift.struct/allowed)

The model may or may not call tools.

[`disallowed`](/documentation/FoundationModels/GenerationOptions/ToolCallingMode-swift.struct/disallowed)

The model may not call any tool.

[`required`](/documentation/FoundationModels/GenerationOptions/ToolCallingMode-swift.struct/required)

The model must call one or multiple tools.

### Accessing the content

[`kind`](/documentation/FoundationModels/GenerationOptions/ToolCallingMode-swift.struct/kind-swift.property)

[`Kind`](/documentation/FoundationModels/GenerationOptions/ToolCallingMode-swift.struct/Kind-swift.enum)

## Relationships

### Conforms To

[`Sendable`](/documentation/Swift/Sendable)

[`Equatable`](/documentation/Swift/Equatable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)