foundation-models-on-device

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

1|Updated Oct 11, 2025
One-click install
npx skills add https://github.com/ibytechaos/claude --skill foundation-models-on-device-ibytechaos
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: foundation-models-on-device
Source: https://github.com/ibytechaos/claude/tree/main/plugins/everything-claude-code/skills/foundation-models-on-device
Command: npx skills add https://github.com/ibytechaos/claude --skill foundation-models-on-device-ibytechaos

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 proven Swift patterns for Apple's FoundationModels framework, letting you run language model inference entirely on-device in iOS 26+ apps. ## Core Features & Use Cases - Text Generation Sessions: Create single-turn or multi-turn LanguageModelSession instances with instructions, availability checks, and proper error handling. - Structured Output with @Generable: Generate strongly-typed Swift structs directly from prompts using the @Generable macro and @Guide constraints instead of parsing raw strings. - Tool Calling & Streaming: Define custom Tool implementations the model can invoke, and stream partial structured results via PartiallyGenerated types for real-time SwiftUI updates. - Use Case: Build a recipe assistant that extracts structured ingredients from natural language, searches a local database via a custom tool, and streams results into a SwiftUI list — all without any network request. ## Quick Start Ask the AI to write 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 do I get structured output from an on-device LLM in Swift?

Annotate a Swift struct with @Generable and pass it as the generating parameter to session.respond(to:generating:). Use @Guide with descriptions and constraints like .range or .count to control individual property generation.

Does Apple FoundationModels work offline on iOS 26?

Yes, FoundationModels runs entirely on-device, so no data leaves the device and features work without a network connection. Availability still depends on device eligibility and Apple Intelligence being enabled in Settings.

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 concurrent requests?

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