foundation-models
Foundation Models
Production rules for Apple’s FoundationModels framework (on-device AFM and Private Cloud Compute) in Swift apps. Baseline: iOS/macOS 26.0+ for core APIs; OS 27.0+ / Xcode 27+ for Dynamic Profiles depth, Evaluations, and the fm CLI on macOS 27. Complements swift (concurrency, SwiftUI architecture). Not classic Foundation (URLSession/FileManager) and not third-party cloud LLM SDKs.
Core Principle
Treat the on-device model as a small, typed co-processor: check availability, one request at a time, put structure in @Generable and facts in Tools, keep secrets and authorization in app code. Prefer looking up unfamiliar symbols in Apple documentation (and apple/foundation-models-utilities for the experimental package) over inventing initializers.
| Need | Default | Escape hatch |
|---|---|---|
| Output shape | @Generable + respond(to:generating:) |
Free-text only for prose UX, then still validate |
| Live facts / side effects | Tool with app-owned authority |
Disallow tools (toolCallingMode: .disallowed) for pure generation |
| UI updates while generating | streamResponse → PartiallyGenerated snapshots |
Non-streaming respond for background / rate-limit sensitive work |
| Mid-session behavior change (OS 27+) | Dynamic Profiles | New session when transcript should not carry over |
| Siri multi-step (OS 27+) | App Intents + Skills.skillsbundle |
In-app session only if Siri is out of scope |
Implementation checklist
Follow the ordered checklist in recipe-availability-to-tool (availability → session → Generable → prewarm/schema → stream/respond → tools → single-flight). For OS 27+ Profiles, app skills, Evaluations, or fm, also satisfy the matching dynamic- / intent- / eval- rules.