A new Instruments template for the Foundation Models framework lets you record, visualize, and debug on-device and server-based LLM sessions — showing sessions, requests, model inferences, tool calls, token counts, and latency breakdowns in a single timeline.
• Exposes the full chain of LLM activity (sessions → requests → inferences → tool calls) in a hierarchical tree view, making silent failures like a missing tool in a DynamicInstructions set immediately visible
• Provides three key performance metrics — Time to First Token, Tokens per Second, and Total Latency — directly in Instruments so you can tune prompt length and streaming strategy with data
• Captures prompt and response content locally during development (disabled in production builds), letting you read the exact prompt sent and response received at each inference step without adding logging code
Demonstrates how a DynamicInstructions setup with two tools is structured so Instruments can capture both tool registrations and the switchToTutorialMode transition — the exact pattern shown in the WWDC session.
import FoundationModels
import SwiftUI
// MARK: - Tools
struct GenerateCraftIdeaTool: Tool {
static let name = "generateCraftIdea"
static let description = "Generates a craft project idea based on the user's interests."
struct Input: Codable {
let theme: String
}
func call(input: Input) async throws -> String {
// In a real app this might query a database or use more logic
return "Here is a craft idea based on \(input.theme): Paper Butterfly Mobile"
}
}
struct SwitchToTutorialModeTool: Tool {
static let name = "switchToTutorialMode"
static let description = "Switches the experience from brainstorming to tutorial generation for the selected craft."
struct Input: Codable {
let selectedCraft: String
}
func call(input: Input) async throws -> String {
return "Switching to tutorial mode for: \(input.selectedCraft)"
}
}
// MARK: - Dynamic Instructions
struct BrainstormInstructions: DynamicInstructions {
// Both tools must be listed here — omitting SwitchToTutorialModeTool
// causes a silent failure visible only in Instruments.
var instructions: Instructions {
Instructions(
"""
You are a crafting assistant. Suggest creative craft projects.
When the user selects a craft, call switchToTutorialMode with the craft name.
""",
tools: [GenerateCraftIdeaTool(), SwitchToTutorialModeTool()]
)
}
}
// MARK: - Session
actor CraftSession {
private let model = SystemLanguageModel.default
private lazy var session = LanguageModelSession(
instructions: BrainstormInstructions()
)
func brainstorm(prompt: String) async throws -> String {
let response = try await session.respond(to: Prompt(prompt))
return response.content
}
}
// MARK: - SwiftUI View
struct CraftBrainstormView: View {
@State private var output = "Tap to brainstorm craft ideas..."
@State private var isLoading = false
private let craftSession = CraftSession()
var body: some View {
VStack(spacing: 20) {
Text("Craft Companion")
.font(.largeTitle.bold())
ScrollView {
Text(output)
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
}
.background(.secondarySystemBackground)
.clipShape(RoundedRectangle(cornerRadius: 12))
Button {
Task { await runBrainstorm() }
} label: {
Label(isLoading ? "Thinking…" : "Brainstorm Ideas", systemImage: "wand.and.sparkles")
.frame(maxWidth: .infinity)
}
.buttonStyle(.borderedProminent)
.disabled(isLoading)
}
.padding()
// Profile this view with the Foundation Models Instruments template
// (Product › Profile › Foundation Models) to see the full
// session › request › inference › tool call hierarchy in real time.
}
private func runBrainstorm() async {
isLoading = true
defer { isLoading = false }
do {
output = try await craftSession.brainstorm(
prompt: "Please generate 3 craft ideas suitable for a rainy afternoon."
)
} catch {
output = "Error: \(error.localizedDescription)"
}
}
}
#Preview {
CraftBrainstormView()
}Foundation Models is a new Apple framework introduced in iOS 27 that gives developers on-device access to the same Apple Intelligence language model powering system features, enabling text generation, structured output, and tool-calling entirely on-device without a network connection.
iOS 27 opens the Foundation Models framework to third-party LLM providers via a new public LanguageModel protocol, enabling anyone to integrate custom, server-based, or open-source models using the same Swift API as Apple's on-device system model.
App Schemas let developers describe their app's content and actions using pre-defined domain schemas (like the Calendar domain) so Siri can understand, search, and act on app data without custom NLP. Entities conforming to IndexedEntity are donated to Spotlight's semantic index, enabling natural-language queries over app content.
In-depth guide
iOS 27 On-Device AI & Apple Intelligence →Trace files contain raw prompt and response text (potentially sensitive data) — store them securely. The template only appears in Instruments when the app links against the FoundationModels framework. Silent failures (e.g., a missing tool in a toolset) produce no thrown errors, so Instruments is often the only way to detect them.
Requires an Apple Intelligence-capable device or server model access via Private Cloud Compute. Logging is active only during Instruments traces; disabled automatically in production builds.
Visual Intelligence brings iOS 17's Visual Look Up capabilities to a new developer-facing API surface in iOS 27, letting apps pipe live camera frames or static images through on-device scene understanding to extract subjects, text, barcodes, and rich semantic labels without any cloud round-trip.