
Foundation Models On Device
- 5.6k installs
- 238k repo stars
- Updated August 5, 2026
- affaan-m/everything-claude-code
foundation-models-on-device is an agent skill documenting Apple FoundationModels on-device LLM patterns for iOS 26: availability checks, sessions, @Generable output, tools, and snapshot streaming.
About
The foundation-models-on-device skill documents patterns for integrating Apple's on-device language model into iOS apps using the FoundationModels framework on Apple Intelligence. It covers checking SystemLanguageModel availability before sessions, creating LanguageModelSession for single-turn and multi-turn flows with role instructions, structured generation via @Generable types with @Guide range and count constraints, custom Tool calling for domain-specific actions, and snapshot streaming with PartiallyGenerated types for real-time SwiftUI updates. Key design notes include on-device execution for privacy and offline use, a 4096 token limit requiring chunked inputs, one request per session via isResponding, and accessing results through response.content. Best practices stress availability checks, instruction tuning, GenerationOptions temperature, and Instruments profiling. Anti-patterns include concurrent session requests, raw string parsing when @Generable applies, and assuming model readiness across devices. Activate for privacy-sensitive text generation, structured extraction from natural language, offline AI features, progressive streaming UI, and tool-augmented domain lookup.
- Check SystemLanguageModel availability before creating LanguageModelSession on each device
- @Generable structured output with @Guide constraints replaces fragile string parsing
- Custom Tool implementations let the model invoke domain search and lookup code
- Snapshot streaming with PartiallyGenerated types powers progressive SwiftUI list updates
- On-device 4096-token sessions enforce privacy, offline use, and single-request discipline
Foundation Models On Device by the numbers
- 5,560 all-time installs (skills.sh)
- +219 installs in the week ending Aug 5, 2026 (Skillselion tracking)
- Ranked #31 of 1,039 Mobile Development skills by installs in the Skillselion catalog
- Security screen: MEDIUM risk (skills.sh audit)
- Data as of Aug 5, 2026 (Skillselion catalog sync)
foundation-models-on-device capabilities & compatibility
- Capabilities
- systemlanguagemodel availability checks before s · single turn and multi turn languagemodelsession · @generable structured output with @guide numeric · custom tool protocol implementations with toolca · snapshot streaming via streamresponse and partia
- Use cases
- frontend · api development
- Platforms
- macOS
- Runs
- Runs locally
- Pricing
- Free
What foundation-models-on-device says it does
Patterns for integrating Apple's on-device language model into apps using the FoundationModels framework.
Always check model availability before creating a session
Need privacy-preserving AI (no data leaves the device)
npx skills add https://github.com/affaan-m/everything-claude-code --skill foundation-models-on-deviceAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 5.6k |
|---|---|
| repo stars | ★ 238k |
| Security audit | 3 / 3 scanners passed |
| Last updated | August 5, 2026 |
| Repository | affaan-m/everything-claude-code ↗ |
What it does
Integrate Apple on-device FoundationModels for privacy-preserving text generation, structured output, tool calling, and streaming UI in iOS apps.
Who is it for?
iOS developers adding Apple Intelligence text generation, structured extraction, offline AI, or tool-augmented features with FoundationModels.
Skip if: Skip for server-side LLM integration, non-Apple platforms, or tasks unrelated to on-device LanguageModelSession APIs.
When should I use this skill?
Activate when building Apple Intelligence on-device features, structured @Generable output, custom tool calling, snapshot streaming UI, or privacy-preserving offline inference.
What you get
Agents implement availability-safe LanguageModelSession flows, @Generable structured responses, tool calling, and streaming SwiftUI UI aligned with Apple on-device constraints.
- SwiftUI on-device LLM integration code
- @Generable structured output models
- Tool-calling and streaming service implementations
By the numbers
- Targets iOS 26+ with Apple's FoundationModels on-device LLM framework
- Covers four integration patterns: text generation, @Generable output, tool calling, and snapshot streaming
Files
FoundationModels: On-Device LLM (iOS 26)
Patterns for integrating Apple's on-device language model into apps using the FoundationModels framework. Covers text generation, structured output with @Generable, custom tool calling, and snapshot streaming — all running on-device for privacy and offline support.
When to Activate
- Building AI-powered features using Apple Intelligence on-device
- Generating or summarizing text without cloud dependency
- Extracting structured data from natural language input
- Implementing custom tool calling for domain-specific AI actions
- Streaming structured responses for real-time UI updates
- Need privacy-preserving AI (no data leaves the device)
Core Pattern — Availability Check
Always check model availability before creating a session:
struct GenerativeView: View {
private var model = SystemLanguageModel.default
var body: some View {
switch model.availability {
case .available:
ContentView()
case .unavailable(.deviceNotEligible):
Text("Device not eligible for Apple Intelligence")
case .unavailable(.appleIntelligenceNotEnabled):
Text("Please enable Apple Intelligence in Settings")
case .unavailable(.modelNotReady):
Text("Model is downloading or not ready")
case .unavailable(let other):
Text("Model unavailable: \(other)")
}
}
}Core Pattern — Basic Session
// Single-turn: create a new session each time
let session = LanguageModelSession()
let response = try await session.respond(to: "What's a good month to visit Paris?")
print(response.content)
// Multi-turn: reuse session for conversation context
let session = LanguageModelSession(instructions: """
You are a cooking assistant.
Provide recipe suggestions based on ingredients.
Keep suggestions brief and practical.
""")
let first = try await session.respond(to: "I have chicken and rice")
let followUp = try await session.respond(to: "What about a vegetarian option?")Key points for instructions:
- Define the model's role ("You are a mentor")
- Specify what to do ("Help extract calendar events")
- Set style preferences ("Respond as briefly as possible")
- Add safety measures ("Respond with 'I can't help with that' for dangerous requests")
Core Pattern — Guided Generation with @Generable
Generate structured Swift types instead of raw strings:
1. Define a Generable Type
@Generable(description: "Basic profile information about a cat")
struct CatProfile {
var name: String
@Guide(description: "The age of the cat", .range(0...20))
var age: Int
@Guide(description: "A one sentence profile about the cat's personality")
var profile: String
}2. Request Structured Output
let response = try await session.respond(
to: "Generate a cute rescue cat",
generating: CatProfile.self
)
// Access structured fields directly
print("Name: \(response.content.name)")
print("Age: \(response.content.age)")
print("Profile: \(response.content.profile)")Supported @Guide Constraints
.range(0...20)— numeric range.count(3)— array element countdescription:— semantic guidance for generation
Core Pattern — Tool Calling
Let the model invoke custom code for domain-specific tasks:
1. Define a Tool
struct RecipeSearchTool: Tool {
let name = "recipe_search"
let description = "Search for recipes matching a given term and return a list of results."
@Generable
struct Arguments {
var searchTerm: String
var numberOfResults: Int
}
func call(arguments: Arguments) async throws -> ToolOutput {
let recipes = await searchRecipes(
term: arguments.searchTerm,
limit: arguments.numberOfResults
)
return .string(recipes.map { "- \($0.name): \($0.description)" }.joined(separator: "\n"))
}
}2. Create Session with Tools
let session = LanguageModelSession(tools: [RecipeSearchTool()])
let response = try await session.respond(to: "Find me some pasta recipes")3. Handle Tool Errors
do {
let answer = try await session.respond(to: "Find a recipe for tomato soup.")
} catch let error as LanguageModelSession.ToolCallError {
print(error.tool.name)
if case .databaseIsEmpty = error.underlyingError as? RecipeSearchToolError {
// Handle specific tool error
}
}Core Pattern — Snapshot Streaming
Stream structured responses for real-time UI with PartiallyGenerated types:
@Generable
struct TripIdeas {
@Guide(description: "Ideas for upcoming trips")
var ideas: [String]
}
let stream = session.streamResponse(
to: "What are some exciting trip ideas?",
generating: TripIdeas.self
)
for try await partial in stream {
// partial: TripIdeas.PartiallyGenerated (all properties Optional)
print(partial)
}SwiftUI Integration
@State private var partialResult: TripIdeas.PartiallyGenerated?
@State private var errorMessage: String?
var body: some View {
List {
ForEach(partialResult?.ideas ?? [], id: \.self) { idea in
Text(idea)
}
}
.overlay {
if let errorMessage { Text(errorMessage).foregroundStyle(.red) }
}
.task {
do {
let stream = session.streamResponse(to: prompt, generating: TripIdeas.self)
for try await partial in stream {
partialResult = partial
}
} catch {
errorMessage = error.localizedDescription
}
}
}Key Design Decisions
| Decision | Rationale |
|---|---|
| On-device execution | Privacy — no data leaves the device; works offline |
| 4,096 token limit | On-device model constraint; chunk large data across sessions |
| Snapshot streaming (not deltas) | Structured output friendly; each snapshot is a complete partial state |
@Generable macro | Compile-time safety for structured generation; auto-generates PartiallyGenerated type |
| Single request per session | isResponding prevents concurrent requests; create multiple sessions if needed |
response.content (not .output) | Correct API — always access results via .content property |
Best Practices
- Always check `model.availability` before creating a session — handle all unavailability cases
- Use `instructions` to guide model behavior — they take priority over prompts
- Check `isResponding` before sending a new request — sessions handle one request at a time
- Access `response.content` for results — not
.output - Break large inputs into chunks — 4,096 token limit applies to instructions + prompt + output combined
- Use `@Generable` for structured output — stronger guarantees than parsing raw strings
- Use `GenerationOptions(temperature:)` to tune creativity (higher = more creative)
- Monitor with Instruments — use Xcode Instruments to profile request performance
Anti-Patterns to Avoid
- Creating sessions without checking
model.availabilityfirst - Sending inputs exceeding the 4,096 token context window
- Attempting concurrent requests on a single session
- Using
.outputinstead of.contentto access response data - Parsing raw string responses when
@Generablestructured output would work - Building complex multi-step logic in a single prompt — break into multiple focused prompts
- Assuming the model is always available — device eligibility and settings vary
When to Use
- On-device text generation for privacy-sensitive apps
- Structured data extraction from user input (forms, natural language commands)
- AI-assisted features that must work offline
- Streaming UI that progressively shows generated content
- Domain-specific AI actions via tool calling (search, compute, lookup)
Related skills
Forks & variants (1)
Foundation Models On Device has 1 known copy in the catalog totaling 1.4k installs. They canonicalize to this original listing.
- affaan-m - 1.4k installs
How it compares
Choose foundation-models-on-device over generic LLM integration skills when the app must use Apple's on-device FoundationModels rather than OpenAI or Anthropic cloud APIs.
FAQ
What must I check before creating a LanguageModelSession?
Always inspect SystemLanguageModel.default.availability and handle device eligibility, Apple Intelligence disabled, model downloading, and other unavailable cases before starting a session.
How should structured model output be requested?
Define @Generable Swift types with @Guide constraints and call session.respond(to:generating:) instead of parsing raw strings from response.content.
What on-device limits does the skill document?
Sessions accept one request at a time, share a 4096 token budget across instructions prompt and output, and require chunking for large inputs.
Is Foundation Models On Device safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.