foundation-models-on-device

Generate text and structured responses with Apple FoundationModels on iOS devices.

Updated Sep 13, 2025
One-click install
npx skills add https://github.com/llmh333/employee_management_spring --skill foundation-models-on-device-llmh333
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: foundation-models-on-device
Source: https://github.com/llmh333/employee_management_spring/tree/main/.gemini/skills/foundation-models-on-device
Command: npx skills add https://github.com/llmh333/employee_management_spring --skill foundation-models-on-device-llmh333

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you build on-device LLM features that generate text, produce structured outputs, and call app-specific tools without relying on cloud services, improving privacy and offline capability.

Core Features & Use Cases

  • Model availability handling: Safely detect eligibility and readiness before starting a session, and present appropriate UI for unavailability states.
  • Text and multi-turn generation: Generate responses with single-turn prompts or maintain conversational context with reusable sessions.
  • Structured output with @Generable: Turn natural-language requests into strongly typed results using Generable and guide constraints.
  • Tool calling for domain actions: Let the model invoke custom Swift tools for search, lookup, or other app-defined operations.
  • Snapshot streaming for real-time UI: Stream partially generated structured data to progressively update SwiftUI views.

Quick Start

Implement a SwiftUI screen that checks SystemLanguageModel availability, creates a LanguageModelSession when available, and streams a structured @Generable response into the interface.

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 LLM text generation in an iOS app without cloud services?

On-device LLM text generation runs locally using Apple FoundationModels, requiring availability checks before creating a LanguageModelSession to handle single-turn and multi-turn conversational flows privately.

How do I get structured output from an on-device Apple FoundationModels session?

Structured output is generated using the @Generable macro to turn natural-language requests into strongly typed Swift results, applying guidance constraints to ensure the on-device model returns the correct schema.

Can I stream partially generated LLM responses directly into SwiftUI views?

Yes, snapshot streaming streams partially generated structured data from the on-device model to progressively update SwiftUI views in real-time during the LanguageModelSession response generation.

How do I implement custom tool calling for an on-device language model in Swift?

Custom tool calling is implemented by defining Swift tools that the on-device model can invoke for app-specific domain actions like search or lookup during a LanguageModelSession response.

What should I check before starting an on-device FoundationModels session?

Before starting an on-device FoundationModels session, you must check SystemLanguageModel availability and readiness to safely detect eligibility, handling unavailability states by presenting appropriate UI.

How do I access the generated content from a FoundationModels LanguageModelSession?

Access the generated content from a LanguageModelSession via the response.content property, ensuring correct session lifecycle handling throughout the on-device generation process.