Dynamic profiles let you switch language models, instructions, and tools within a single LanguageModelSession, enabling multi-agent orchestration patterns like baton-pass and phone-a-friend directly in your app. Combined with session properties and lifecycle modifiers, you can build context-aware, multi-stage AI workflows on-device and in the cloud.
⢠Route between on-device SystemLanguageModel and PrivateCloudComputeLanguageModel mid-session based on task complexity, cost, or privacy requirements
⢠DynamicInstructions and DynamicProfileModifier let you compose and reuse agent configurations across your codebase like SwiftUI views
⢠Lifecycle modifiers (onResponse) and session properties give you hooks to summarize transcripts, manage context windows, and share state across all agents in a session
Demonstrates a two-phase DynamicProfile session that brainstorms craft ideas using PrivateCloudComputeLanguageModel, then switches to SystemLanguageModel for in-progress technique review ā showing the baton-pass pattern with a shared session property.
import FoundationModels
import SwiftUI
// MARK: - Session Property for shared summary
extension SessionPropertyValues {
@SessionPropertyEntry var conversationSummary: String? = nil
}
// MARK: - Reusable DynamicInstructions component
struct CraftExpert: DynamicInstructions {
var body: some DynamicInstructions {
Instructions("You are an expert in paper crafts and textile arts.")
}
}
// MARK: - Orchestrator using DynamicProfile
@Observable
class CraftOrchestrator {
enum Mode { case brainstorm, review }
var mode: Mode = .brainstorm
var session: LanguageModelSession
init() {
session = LanguageModelSession {
DynamicProfile { [mode] in
switch mode {
case .brainstorm:
CraftExpert()
Instructions("Suggest 3 creative craft project ideas based on the user's input.")
ModelConfiguration(PrivateCloudComputeLanguageModel.default)
Temperature(1.0)
case .review:
CraftExpert()
Instructions("Give concise technique advice based on the user's in-progress photo description.")
ModelConfiguration(SystemLanguageModel.default)
// Trim history to tool calls only to stay within on-device context
HistoryTransform { entries in
entries.filter { $0.role != .tool }
}
}
}
.onResponse { context in
// After brainstorm response, store a summary and switch to review
if context.session.properties.conversationSummary == nil {
context.session.properties.conversationSummary = "User brainstormed craft ideas."
}
}
}
}
func brainstorm(prompt: String) async throws -> String {
mode = .brainstorm
let response = try await session.respond(to: prompt)
return response.content
}
func review(prompt: String) async throws -> String {
mode = .review
let response = try await session.respond(to: prompt)
return response.content
}
}
// MARK: - SwiftUI View
struct CraftOrchestratorView: View {
@State private var orchestrator = CraftOrchestrator()
@State private var output = "Tap a button to start."
@State private var isLoading = false
var body: some View {
VStack(spacing: 20) {
Text(output)
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
.background(.secondarySystemBackground)
.clipShape(RoundedRectangle(cornerRadius: 12))
if isLoading { ProgressView() }
Button("Brainstorm Ideas") {
Task {
isLoading = true
output = (try? await orchestrator.brainstorm(
prompt: "I have coloured paper and yarn. What can I make?"
)) ?? "Error"
isLoading = false
}
}.buttonStyle(.borderedProminent)
Button("Get Technique Advice") {
Task {
isLoading = true
output = (try? await orchestrator.review(
prompt: "My paper crane wings look uneven. What should I check?"
)) ?? "Error"
isLoading = false
}
}.buttonStyle(.bordered)
}
.padding()
}
}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.
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.
iOS 27 opens the Foundation Models framework to third-party LLM providers via a new public LanguageModel protocol, allowing anyone to integrate server-based or local models (e.g. Claude, Gemini, CoreAI, MLX) using the same API as Apple's on-device system model.
In-depth guide
iOS 27 On-Device AI & Apple Intelligence ā⢠historyTransform is non-destructive (local to the prompt), while the history session property is lossy and affects all profiles ā choose carefully
⢠DynamicProfile bodies are re-evaluated on every prompt, so avoid expensive side effects inside the declaration closure
⢠Foundation Models framework utilities is an open-source Swift package updated between OS releases; pin versions carefully in production apps
SystemLanguageModel requires an Apple Intelligence-capable device; PrivateCloudComputeLanguageModel requires network access and PCC availability ā not all requests may be fulfilled in all regions.
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.