apple-foundation-models
Skill4 starsChanged 5 months agoMITView on GitHub
Apple Foundation Models framework for on-device AI. LanguageModelSession, @Generable macro, structured output, token management, and availability checking.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- Vvlladd/iOSskillsCollectiontheir own version, first seen Oct 13, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- Vvlladd/iOSskillsCollection★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository101 other files it gives its agents.
- ai-video-understandingSkill
- arch-dddSkill
- arch-decision-recordsSkill
- arch-diagramsSkill
- arch-eventsSkill
- arch-mvp-roadmapSkill
- arch-python-modernSkill
- aws-app-runnerSkill
- aws-cicd-patternsSkill
- aws-security-hardeningSkill
- azure-functions-python-v2Skill
- azure-identity-m2m-authSkill
- azure-service-bus-messagingSkill
- azure-workflow-execution-modelsSkill
- caddy-tls-proxySkill
- compliance-frameworksSkill
- design-system-workflowSkill
- dev-debugging-strategiesSkill
- dev-standardsSkill
- docker-python-poetrySkill
- docker-pythonSkill
- fastapi-patternsSkill
- ffmpeg-laravel-videoSkill
- formik-yup-react-nativeSkill
- frontend-accessibilitySkill
- frontend-angular-aiSkill
- frontend-angularSkill
- frontend-angular-toolingSkill
- frontend-design-systemsSkill
- frontend-material-chatSkill
- frontend-material-design-3Skill
- frontend-svelteSkill
- gcp-cicd-patternsSkill
- gcp-cloud-runSkill
- gcp-cloudsql-infrastructureSkill
- gcp-finopsSkill
- gcp-observabilitySkill
- gcp-security-hardeningSkill
- github-actions-cicdSkill
- healthkit-biofeedbackSkill
- infra-terraformSkill
- ios-app-qualitySkill
- ios-audio-hapticsSkill
- jest-nestjs-testingSkill
- langchain-azure-openai-patternsSkill
- laravel-auth-hardeningSkill
- laravel-ci-mysqlSkill
- laravel-mix-webpackSkill
- laravel-modern-patternsSkill
- laravel-pint-patternsSkill
- laravel-s3-storageSkill
- laravel-sail-dockerSkill
- mobile-app-deploymentSkill
- mobile-e2e-testingSkill
- mobile-offline-syncSkill
- mobile-push-notificationsSkill
- mobile-video-uploadSkill
- mongodb-asyncmongoclient-patternsSkill
- mongodb-atlas-patternsSkill
- nestjs-patternsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 36
@Generable shadow type pattern: Keep the FM-coupled @Generable struct guarded by #if canImport(FoundationModels) + @available(iOS 26, *).
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Apple Foundation Models
On-device AI using Apple's Foundation Models framework (iOS 26+, now shipping). FM is the primary AI provider; MLX and pre-authored templates serve as fallbacks.
When to Use
- Generating personalized coaching content on-device
- Structured output from on-device language models
- Managing the 4096-token context limit
- Building AI features that work offline with no cloud dependency
Core Concepts
Availability Checking
Foundation Models is available now on supported iOS 26+ / watchOS 26+ devices. Availability varies by device capability and region. A two-layer check — #if canImport(FoundationModels) at compile time plus LanguageModelSession.isAvailable at runtime — covers both Xcode compatibility and device detection. See reference.md for detailed checking patterns.
Basic Text Generation
LanguageModelSession accepts system-level instructions and produces text responses from a prompt. Instructions set the persona and guardrails (e.g., prohibiting medical advice). See examples.md for a complete BreathCoach implementation.
Structured Output with @Generable
The @Generable macro paired with @Guide constraints produces typed Swift structs instead of free-form text. Field-level constraints (options lists, numeric ranges) steer the model toward valid output. See examples.md for the BreathingRecommendation pattern.
@Guide constraint gap: @Guide(.anyOf(...)) and @Guide(.range(...)) are NOT available in the current FoundationModels SDK (as of iOS 26.2). Use @Guide(description: "...") strings that enumerate valid values, add redundant enumeration in the prompt body, and validate output after respond(to:generating:). Cross-field constraints ("stage 1-4 for ujjayi, 1-2 for viloma") cannot be expressed in @Generable — handle them in code with allowlists, range checks, and length caps. Fall through to the deterministic fallback on any validation miss.
@Generable shadow type pattern: Keep the FM-coupled @Generable struct guarded by #if canImport(FoundationModels) + @available(iOS 26, *). Convert at the call site to a plain Sendable struct that crosses the protocol boundary. The protocol type has zero FM dependency, so mocks, fallbacks, and tests stay simple:
#if canImport(FoundationModels)
import FoundationModels
@available(iOS 26, *)
@Generable
struct ReadinessRecommendationDraft {
// internal (not private) — @Generable macro expansion requires non-private access
@Guide(description: "Technique ID. Valid: ujjayi, viloma, box, resonance")
var techniqueID: String
@Guide(description: "Session length in minutes. Valid: 5, 7, 10, 15, 20")
var sessionMinutes: Int
}
#endif
// Plain Sendable crosses the protocol boundary — no FM import needed in consumers
struct ReadinessRecommendation: Sendable {
let techniqueID: String
let sessionMinutes: Int
let rationale: String
}@Generable access requirement: The macro expansion references the type by name and fails with private types. Promote to file-scope internal (still safe inside #if canImport(FoundationModels)).
Token Management (4096 Limit)
The on-device model has a 4096-token context window. A summarize-and-reset strategy keeps multi-turn conversations within budget by periodically condensing history into a fresh session. See reference.md for the rationale and examples.md for the ManagedCoachSession implementation.
Tool Calling
Structured output doubles as a tool-calling mechanism: the model produces a typed request (e.g., RequestBiometrics), the app fulfills it locally, and feeds the result back. See reference.md for mechanics and examples.md for the pattern.
MLX Fallback (Secondary)
MLX is the secondary fallback for devices that run Apple Silicon but lack Foundation Models support (iOS 18-25). A ~1GB quantized Llama fits on iPhone but is marginal on Apple Watch due to memory constraints. For new projects, FM is the primary implementation target; MLX serves devices that can't run FM. See reference.md for when to prefer MLX vs. templates.
Provider Abstraction
A protocol-based provider chain (AICoachProvider) abstracts over Foundation Models, MLX, and pre-written templates. The chain tries each provider in order and falls back automatically. See examples.md for the full implementation.
AI Tier Detection
A detectAITier() pattern selects the best available AI backend at runtime: FM (primary) → MLX (secondary) → pre-authored templates (fallback). Guarding FM-specific code with #if canImport(FoundationModels) ensures compilation on Xcode versions that predate the framework. See examples.md for the implementation and reference.md for the tier selection rationale.
Anti-Patterns
| Anti-Pattern | Preferred Pattern |
| Assuming Foundation Models is available everywhere | Check LanguageModelSession.isAvailable at runtime |
| Long multi-turn conversations | Reset session after ~5 turns (4096 token limit) |
| Medical or diagnostic language in prompts | System instructions that prohibit medical advice |
| Loading MLX models on watchOS | Memory too constrained; use Foundation Models or templates |
| Hardcoding model names | Use provider abstraction for swappable backends |
| Treating MLX as co-equal to FM | FM is the primary provider; MLX is fallback for devices without FM support |
Using @Guide(.anyOf(...)) or @Guide(.range(...)) | Not in current SDK — use @Guide(description:) with enumerated values + post-generation validators |
private access on @Generable struct | Macro expansion fails — promote to file-scope internal inside #if canImport(FoundationModels) |
Returning @Generable type across protocol boundary | Expose plain Sendable struct at boundary; convert from shadow draft type at call site |
Key References
- WWDC25: Foundation Models deep dive
- AzamSharp: Foundation Models Guide
- Apple ML Research: Core ML Llama
Sibling Files
reference.md-- Detailed explanations of availability, tokens, tool calling, MLX rationale, provider designexamples.md-- All Swift code examples with section headers for navigation
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

