foundation-models

A development guide for Apple's Foundation Models framework, which runs AI models on supported devices. It covers text generation, streaming responses, structured output, and availability checks on iOS 26 and later.

In plain words
What is it for?
Building iOS features that generate or stream text and return structured data from on-device models.
Why use it?
It provides implementation instructions for adding on-device AI while checking whether the device supports Apple's model.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/moasq/ios-dev-agent/foundation-models
Any agent
npx skills add moasq/ios-dev-agent --skill foundation-models
Clone the repo
git clone --depth 1 https://github.com/moasq/ios-dev-agent

Made for: Claude Code, Codex.

Per session 28 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 537 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00028 $0.00537
Opus 5 $0.00014 $0.00269
Sonnet 5 $0.00006 $0.00107
Haiku 4.5 $0.00003 $0.00054

Measured 2d ago against content hash edaeeae8121a, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

foundation-models scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.agents/skills/foundation-models/SKILL.md · 86 lines

How it starts

The opening of the file, as written. The whole thing — 86 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Foundation Models (On-Device AI)

Use this guide when implementing or modifying on-device AI features.

Framework

import FoundationModels — iOS 26+ only

Availability Check (MANDATORY)

The model may not be available on all devices. Always check first:

guard SystemLanguageModel.default.isAvailable else {
    // Show "This feature requires Apple Intelligence" message
    return
}

Basic Text Generation

let session = LanguageModelSession()
let response = try await session.respond(to: "Summarize this text: \(userText)")
print(response.content)  // String

With System Instructions

let session = LanguageModelSession(
    instructions: "You are a helpful health assistant. Keep responses concise and empathetic."
)
let response = try await session.respond(to: prompt)

Streaming Generation

let stream = session.streamResponse(to: prompt)
for try await partial in stream {
    displayText += partial.text
}

Structured Output with @Generable

@Generable
struct RecipeSuggestion {
    @Guide(description: "Name of the dish") var name: String
    @Guide(description: "Estimated prep time in minutes") var prepTime: Int
    @Guide(description: "Main ingredients") var ingredients: [String]
}

let session = LanguageModelSession()
let recipe: RecipeSuggestion = try await session.respond(
    to: "Suggest a quick pasta dish",
    generating: RecipeSuggestion.self
)

Guardrails

  • Model output is filtered by Apple's safety system — some prompts may be refused
  • No internet required — fully on-device
  • Context window is limited (~4K tokens) — keep prompts concise
  • Use session.respond() for single turns; keep session alive for multi-turn conversations
  • Wrap in do/catch — generation can fail for safety or resource reasons

Service Pattern

@MainActor @Observable
final class AIService {
    var isAvailable: Bool { SystemLanguageModel.default.isAvailable }

    func generate(prompt: String) async -> String? {
        guard isAvailable else { return nil }
        do {
            let session = LanguageModelSession(instructions: "...")
            let response = try await session.respond(to: prompt)
            return response.content
        } catch {
            return nil
        }
    }
}

Read the full file on GitHub · 86 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 86 lines · 28 tokens per session scan A edaeeae8121a

Subscribe to this mod's changes

foundation-models is a skill published in the GitHub repository moasq/ios-dev-agent (4 stars, last pushed 3mo ago), licensed MIT. It adds 28 tokens to every session and 537 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

model-authoring

Empirical rules for authoring PyTorch models for on-device execution on Apple platforms, covering energy-efficient inference, scalable compute, and correctness testing. Use this skill whenever the user is writing, debugging, or reviewing PyTorch model code intended for on-device execution — even if they don't…

apple/coreai-models · 95 tokens

working-with-coreai

Use this skill whenever the user mentions coreai-torch, TorchConverter, coreai-build, AIModel, AIProgram, .aimodel, or wants to export/compile/run a PyTorch model on Apple silicon (iPhone, iPad, Mac). Also triggers for "deploy on device", "optimize for on-device performance", onboarding new models to Core AI, or…

apple/coreai-models · 91 tokens

ai-model-wechat

Use this skill for WeChat Mini Program AI via wx.cloud.extend.AI (小程序, 企业微信小程序, wx.cloud apps). Features generateText and streamText with callbacks (onText, onEvent, onFinish). Models via wx.cloud.extend.AI.createModel with groups hunyuan-exp (小程序成长计划), cloudbase (main managed), or custom-. Model IDs…

TencentCloudBase/CloudBase-AI-Toolkit · 254 tokens

firebase-ai

Use when setting up firebaseai, generating text/chat with Gemini, streaming AI output, building multimodal prompts, or handling AI errors.

evanca/flutter-ai-rules · 30 tokens

litert-compiled-model-migration

Rapidly migrate an Android application from legacy TensorFlow Lite (TFLite) to modern LiteRT CompiledModel API v2.1.6 in Open Source GitHub repositories. Supports True Async Execution (runAsync), Zero-Copy I/O Buffers, NPU JIT compilation, and automated 2-stage verification self-testing.

google-ai-edge/litert-samples · 76 tokens

foundation-models

On-device LLM integration using Apple's Foundation Models framework. Use when implementing AI text generation, structured output, or tool calling.

rshankras/claude-code-apple-skills · 29 tokens