ToolChoice
Whether the model may call tools, must call one, or must call a specific one.
.auto lets the model decide, which is what you want almost always. The
other cases are for the moments when you need to take that decision away:
forcing a tool call on the first step, or forbidding tools while the model
writes its final answer.
Forcing a specific tool is a useful trick for structured extraction. Give the model one tool whose schema is the shape you want back.
let result = try await generateText(
model: AnthropicModel("claude-sonnet-5"),
prompt: prompt,
tools: [extractInvoice],
toolChoice: .tool("extract_invoice")
)Declaration
public enum ToolChoiceDefined in Sources/AI/Core/LanguageModel.swift.
Cases
case auto
case none
case required
case tool(String)