foundation-models-on-device

Implements on-device LLM features in Swift using Apple's FoundationModels framework on iOS 26.

Updated Mar 25, 2026
One-click install
npx skills add https://github.com/Femad-6/my-skills --skill foundation-models-on-device-femad-6
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: foundation-models-on-device
Source: https://github.com/Femad-6/my-skills/tree/main/.github/skills/foundation-models-on-device
Command: npx skills add https://github.com/Femad-6/my-skills --skill foundation-models-on-device-femad-6

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building AI features that respect user privacy and work offline is hard when relying on cloud LLM APIs. This Skill provides ready-to-apply patterns for Apple's FoundationModels framework so you can run text generation, structured output, and tool calling entirely on-device. ## Core Features & Use Cases - Availability Checks & Sessions: Verify SystemLanguageModel availability and create single-turn or multi-turn LanguageModelSession instances with custom instructions. - Guided Generation: Use @Generable and @Guide macros to produce strongly-typed Swift structs instead of parsing raw strings, with constraints like ranges and counts. - Tool Calling & Streaming: Define custom Tool implementations the model can invoke, and stream structured responses as PartiallyGenerated snapshots for real-time SwiftUI updates. - Use Case: Build a recipe assistant that extracts structured ingredients from natural language, calls a custom recipe search tool, and streams results into a SwiftUI list — all without any network request. ## Quick Start Ask the assistant to create a SwiftUI view that uses LanguageModelSession with @Generable structured output and handles all model availability states.

Frequently Asked Questions about foundation-models-on-device

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use Apple FoundationModels framework in Swift?

Create a LanguageModelSession, optionally with instructions, then call session.respond(to:) with your prompt. Always check SystemLanguageModel.default.availability first to handle cases where the device is ineligible or Apple Intelligence is disabled.

How to get structured output from on-device LLM in iOS?

Define a Swift struct annotated with @Generable, add @Guide constraints like .range or descriptions to properties, then pass the type to session.respond(to:generating:). The response.content property returns a fully typed instance instead of a raw string.

Does FoundationModels work offline on iPhone?

Yes, the FoundationModels framework runs entirely on-device, so no data leaves the device and features work without network connectivity. However, the device must be eligible for Apple Intelligence and the model must be downloaded and ready.

What is the token limit for Apple FoundationModels sessions?

The on-device model has a 4,096 token context window covering instructions, prompt, and output combined. Break large inputs into chunks across multiple sessions when exceeding this limit.

Why does my LanguageModelSession fail when sending multiple requests?

A session handles only one request at a time, enforced by the isResponding property. Check isResponding before sending a new request, or create multiple sessions if you need concurrent generation.