Skip to content
SwiftSkills

Apple Foundation Models with AI agents: on-device LLM, guided generation and tool calling

Install an Apple Foundation Models skill so the agent checks SystemLanguageModel availability, uses LanguageModelSession with guided generation (@Generable) instead of parsing raw strings, and only falls back to Claude-for-Foundation-Models or a swappable SDK when on-device Apple Intelligence is unavailable or you need a larger server model.

Last updated:

This page is about getting a coding agent to ship on-device Apple Intelligence features with Foundation Models: availability checks, LanguageModelSession, guided generation and tool calling. For a Claude Code-only shopping list of SwiftUI skills, see Best Claude Code skills for SwiftUI. Antigravity IDE setup lives in Google Antigravity for iOS development.

What the agent has to get right

Apple's Foundation Models framework "provides access to any large language model, like the on-device and Private Cloud Compute models designed for Apple Intelligence." On-device models excel at summarization, entity extraction, text understanding, refinement, creative content and similar tasks. When you need more reasoning or context size, Apple points you to Private Cloud Compute or a server model provider.

Three layers show up in almost every PR:

  1. Availability — before any call, check SystemLanguageModel availability; it depends on device and region Apple Intelligence support.

  2. Session and generation — use LanguageModelSession with instructions; prefer guided generation (@Generable) over parsing raw strings.

  3. Product rules — follow Generative AI in the Human Interface Guidelines: keep people in control, disclose AI use, set expectations, and keep a non-AI path when features are unavailable.

From Apple's generating-content article: the on-device model is a good fit for summarize / extract / refine / classify / creative writing prompts, and a poor fit for basic math, creating code or heavy logical reasoning — skills should stop the agent inventing cloud-chat APIs for those cases without an explicit server fallback.

Rules worth adding to AGENTS.md or CLAUDE.md:

Foundation Models: always read SystemLanguageModel.default.availability before creating a session. Prefer LanguageModelSession + @Generable types over string parsing. Do not invent OpenAI-style chat clients for on-device work. If Apple Intelligence is unavailable, degrade UI per HIG Generative AI and only then consider a documented server adapter (Claude for Foundation Models) or a swappable inference SDK.

Step 1: install a Foundation Models skill

Ask the agent to:

  1. Install Apple Foundation Models Agent Skill (npx skills add https://github.com/alessiorubicini/Apple-Foundation-Models-Agent-Skill --skill apple-foundation-models-skill).

  2. Or install Apple Platforms 27 Skills when the same agent also needs iOS 27 / App Intents / Core AI context (npx skills add hechen/apple-platforms-27-skills --skill '*').

  3. Apple Native Skills (npx skills add Yar177/appleNativeSkills --skill apple-ai) covers Foundation Models plus Vision, Speech and on-device RAG in one pack.

Honest limit: do not install every FM-adjacent skill at once; overlapping triggers waste context. One primary FM skill plus Platforms 27 when you also need OS 27 platform guidance is enough.

Step 2: availability before session

Point the agent at Apple's SystemLanguageModel page. Sketch (API names from Apple's doc):

swift

let model = SystemLanguageModel.default
switch model.availability {
case .available:
    let session = LanguageModelSession(model: .default)
    // respond…
case .unavailable(.deviceNotEligible):
    // show non-AI UI
case .unavailable(.modelNotReady):
    // wait / retry later
case .unavailable(let other):
    // unknown reason — degrade gracefully
}

Reject PRs that call respond without an availability branch.

Step 3: guided generation instead of string parsing

When the agent needs structured output, require a @Generable type and session.respond(to:generating:) as in Apple's guided-generation article. Example shape from that doc:

swift

let prompt = "How many tablespoons are in a cup?"
let session = LanguageModelSession(model: .default)
let response = try await session.respond(to: prompt, generating: Float.self)

For app-owned types, add short Generable / Guide descriptions — Apple warns that long descriptions consume context and add latency.

Step 4: server fallback only when documented

  1. Claude for Foundation Models — SPM package so Claude conforms to the Foundation Models LanguageModel protocol (streaming, guided generation, tool calling). Beta; needs App Attest client ID or API key per README.

  2. InferKit — MIT inference toolkit with swappable backends including Apple's on-device Foundation Models companion package; use when the app already needs Core ML / remote / MLX behind one protocol.

  3. Keep product copy and disclosure on the HIG Generative AI rules above; do not silently swap models without telling the user.

Tools compared (5)

ToolBest forAgents (README)Install (README)LicenseStarsLast push
Apple Foundation Models Agent Skill (alessiorubicini)Deep FoundationModels skill: SystemLanguageModel, sessions, @Generable, streaming, Tool calling across OS 26/27Claude Code, Cursor, Codexnpx skills add https://github.com/alessiorubicini/Apple-Foundation-Models-Agent-Skill --skill apple-foundation-models-skillMIT1515 Sep 2026 ⚠
Claude for Foundation Models (anthropics)Swift package: Claude as a Foundation Models LanguageModel for the same session/guided-generation API (server-side, beta)Xcode / SPM.package(url: "https://github.com/anthropics/ClaudeForFoundationModels.git", from: "0.1.0")Apache-2.03477 Oct 2026
Apple Platforms 27 Skills (hechen)Eight OS 27 skills including Foundation Models / Core AI beside SwiftUI and App IntentsClaude Code, Cursor, Codex, Gemini, Windsurf, Antigravitynpx skills add hechen/apple-platforms-27-skills --skill '*'MIT227 Sep 2026 ⚠
Apple Native Skills (Yar177)Monorepo apple-ai skill: Foundation Models, Vision, Speech, Core ML, on-device RAG and system AI featuresClaude Code, Cursor, Codex, Gemini, Windsurfnpx skills add Yar177/appleNativeSkills --skill apple-aiMIT017 Jun 2026 ⚠
InferKit (belisoful)Swappable inference SDK (Core ML, remote, MLX, Foundation Models companion) behind one protocol for Mac/iOS/tvOSXcode / SPM.package(url: "https://github.com/belisoful/InferKit.git", from: "0.3.1")MIT330 Oct 2026

⚠ = no push for more than 4 weeks. InferKit was pushed on 30 Oct 2026; Claude for Foundation Models on 7 Oct. The three skill rows with June–September pushes are older — read their output against the current SDK before treating every suggestion as current.

Which one to pick:

  • Default on-device FM coaching: Apple Foundation Models Agent Skill.

  • Also shipping iOS 27 / App Intents in the same agent: Apple Platforms 27 Skills.

  • Same session API with a server Claude model: Claude for Foundation Models.

  • Broader on-device AI pack (Vision/Speech/RAG) after merge: Apple Native Skills apple-ai.

  • App already needs multi-backend inference: InferKit.

A prompt that keeps the agent honest

Setting up the agent itself: Claude Code for iOS development, Codex for iOS development or Cursor rules for SwiftUI.

Add an on-device summarize feature with Foundation Models. Check SystemLanguageModel.default.availability first and implement HIG-style fallback UI when unavailable. Use LanguageModelSession with a @Generable summary type — no raw-string JSON parsing. Do not add an OpenAI client. If we need a server model later, only propose Claude for Foundation Models behind the same LanguageModel protocol and call out disclosure copy.

FAQ

What is Apple Foundation Models for AI coding agents?
Foundation Models is Apple's framework for language understanding, structured output and tool calling with on-device and Private Cloud Compute models designed for Apple Intelligence. Agent skills teach Claude Code, Cursor or Codex to check SystemLanguageModel availability, open a LanguageModelSession and use guided generation instead of inventing cloud LLM APIs.
Should the agent skip the availability check?
No. Apple's SystemLanguageModel documentation says you need to verify availability before use; it depends on whether the device and region supports Apple Intelligence. Use SystemLanguageModel.Availability (for example deviceNotEligible or modelNotReady) to change what the app shows when the model is unavailable.
What is guided generation (@Generable)?
Guided generation lets you describe the output as a Swift type instead of parsing a raw string. Apple's guided-generation article says the framework uses constrained sampling so the model fills in an instance of your Generable type, which prevents malformed output and returns results as the type you define.
When should the agent use Claude for Foundation Models instead of the on-device model?
Use Apple's on-device SystemLanguageModel first when Apple Intelligence is available. Claude for Foundation Models is a Swift package that makes Claude conform to the Foundation Models LanguageModel protocol for streaming, guided generation and tool calling — useful when you need a server-side model behind the same session API. It is beta and needs an App Attest client ID or an API key per its README.
How does HIG Generative AI fit with Foundation Models skills?
Apple's Generative AI Human Interface Guidelines say to keep people in control, communicate where the app uses AI, set clear expectations about capabilities and limits, and ensure a great experience when generative features are unavailable. Pair a Foundation Models skill with those product rules so the agent does not ship silent AI or features that fail with no fallback.