foundation-models-on-device

Integrate on-device language models in iOS 26+ apps with @Generable outputs and tool calls.

1|Updated Mar 18, 2026
One-click install
npx skills add https://github.com/xxih/ai-harness-zh --skill foundation-models-on-device-xxih
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: foundation-models-on-device
Source: https://github.com/xxih/ai-harness-zh/tree/main/references/translations/everything-claude-code/docs/zh-CN/skills/foundation-models-on-device
Command: npx skills add https://github.com/xxih/ai-harness-zh --skill foundation-models-on-device-xxih

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Enable iOS applications to run language model generation and structured output entirely on device to protect user privacy, support offline scenarios, and avoid cloud dependency while providing predictable integration patterns.

Core Features & Use Cases

  • Availability checks: Verify device eligibility and model readiness before creating sessions to avoid runtime errors and poor UX.
  • Session patterns: Single-turn and multi-turn session management with guidance on instructions, isResponding checks, and lifecycle decisions.
  • Structured generation with @Generable: Define Swift types for reliable, typed outputs and use generated PartiallyGenerated types for streaming updates.
  • Tool invocation: Expose custom tools for domain-specific actions, handle tool call errors, and integrate tool results into responses.
  • Snapshot streaming for UI: Stream partially generated structured snapshots to SwiftUI for progressive rendering and responsive interfaces.
  • Best practices & constraints: Guidance on token limits, generation options, avoiding concurrent requests, and monitoring with Instruments.

Quick Start

Write Swift code that checks FoundationModels availability, creates a LanguageModelSession with a custom tool, and generates a TripIdeas @Generable stream for SwiftUI to consume.

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 run on-device LLMs in iOS apps to generate text privately?

To run on-device LLMs in iOS apps privately, check FoundationModels availability, create a LanguageModelSession, and generate text entirely offline without cloud dependency.

Can I extract structured data from text using on-device language models in Swift?

You can extract structured data in Swift by defining @Generable types for reliable, typed outputs and using PartiallyGenerated types to stream extraction updates directly.

What iOS version is required for FoundationModels on-device language model integration?

FoundationModels on-device language model integration requires iOS 26+ to access native text generation, structured data extraction, and custom tool invocation features.

How do I stream partially generated LLM responses into SwiftUI?

Stream partially generated LLM responses into SwiftUI by using real-time snapshot streaming from a LanguageModelSession, enabling progressive rendering for responsive interfaces.

How do I handle custom tool calls with on-device language models in iOS?

Handle custom tool calls in iOS by exposing domain-specific tools to the LanguageModelSession, managing tool invocation errors, and integrating tool results back into model responses.

What are the limitations of on-device language models for iOS applications?

On-device language model limitations in iOS include token limits, avoiding concurrent requests, and monitoring generation with Instruments to ensure predictable offline operation.