foundation-models-on-device

Implements on-device LLM text generation, structured output, and tool calling with Apple FoundationModels.

Updated Mar 18, 2026
One-click install
npx skills add https://github.com/freedom909/real-estate-saas --skill foundation-models-on-device-freedom909
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: foundation-models-on-device
Source: https://github.com/freedom909/real-estate-saas/tree/main/.trae/skills/foundation-models-on-device
Command: npx skills add https://github.com/freedom909/real-estate-saas --skill foundation-models-on-device-freedom909

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Integrating Apple's on-device language model into iOS apps requires handling model availability, structured output, tool calling, and streaming correctly, and mistakes like exceeding the 4,096 token limit or using the wrong response property cause runtime failures. ## Core Features & Use Cases - Availability Checks & Sessions: Verify SystemLanguageModel availability and create single-turn or multi-turn LanguageModelSession instances with instructions. - Guided Generation: Produce structured Swift types with @Generable and @Guide constraints instead of parsing raw strings. - Tool Calling & Streaming: Define custom Tool implementations for domain actions and stream PartiallyGenerated snapshots into SwiftUI views. - Use Case: Build a recipe assistant that checks model availability, calls a custom recipe search tool, and streams structured trip or recipe ideas into a live-updating SwiftUI list, all offline on-device. ## Quick Start Use the foundation-models-on-device skill to add an availability-checked LanguageModelSession with @Generable structured output to my SwiftUI view.

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 generate structured output with Apple FoundationModels?▼

Define a Swift struct with the @Generable macro and pass it to session.respond(to:generating:). Use @Guide constraints like .range or .count to control field values, then read results from response.content.

How to check if Apple Intelligence is available on a device?▼

Check SystemLanguageModel.default.availability before creating a session. Handle cases like deviceNotEligible, appleIntelligenceNotEnabled, and modelNotReady to show appropriate UI fallbacks.

Does FoundationModels support tool calling in Swift?▼

Yes, FoundationModels supports custom tool calling by defining a Tool struct with a name, description, @Generable Arguments, and a call function. Pass tools when creating the LanguageModelSession and catch ToolCallError for failures.

What is the token limit for on-device 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 to stay within the limit.

Why does my FoundationModels session fail when sending concurrent requests?▼

A LanguageModelSession handles one request at a time, and isResponding blocks concurrent calls. Check isResponding before sending, or create multiple sessions if parallel requests are needed.