Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsCommunityBlog
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

Back to skills

Apple Foundation Models

ASecurity

Use when integrating Apple's on-device LLM via the FoundationModels framework (iOS 26+). Covers SystemLanguageModel availability cases, LanguageModelSession, @Generable/@Guide guided generation, PartiallyGenerated snapshot streaming, tool calling, and the 4096-token context limit.

2 stars
0 votes
0 copies
0 views
Added 9/19/2026
ai-agentsgoswiftdatabase

Security Analysis

A100/100

Scanned 9/19/2026

Install to Claude Code

$npx -y skills add Mixard/fable-pack --skill apple-foundation-models --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Apple Foundation Models?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Apple Foundation Models
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mixard-apple-foundation-models/badge)](https://www.skillsdirectory.com/skills/mixard-apple-foundation-models)

More formats (shields.io, HTML) on the badges page.

Download Zip
Files
SKILL.md
---
name: apple-foundation-models
description: Use when integrating Apple's on-device LLM via the FoundationModels framework (iOS 26+). Covers SystemLanguageModel availability cases, LanguageModelSession, @Generable/@Guide guided generation, PartiallyGenerated snapshot streaming, tool calling, and the 4096-token context limit.
---

# Apple FoundationModels (on-device LLM, iOS 26+)

The FoundationModels framework runs Apple Intelligence's language model entirely on-device: no network, no data leaving the device. Key constraints: availability depends on device eligibility and user settings, and the context window is 4,096 tokens total (instructions + prompt + output combined) — chunk larger inputs across sessions.

## Availability

Check `SystemLanguageModel.default.availability` before creating a session; every unavailability case is reachable in the field:

```swift
struct GenerativeView: View {
    private var model = SystemLanguageModel.default

    var body: some View {
        switch model.availability {
        case .available:
            ContentView()
        case .unavailable(.deviceNotEligible):
            Text("Device not eligible for Apple Intelligence")
        case .unavailable(.appleIntelligenceNotEnabled):
            Text("Please enable Apple Intelligence in Settings")
        case .unavailable(.modelNotReady):
            Text("Model is downloading or not ready")
        case .unavailable(let other):
            Text("Model unavailable: \(other)")
        }
    }
}
```

## LanguageModelSession

```swift
// Single-turn: new session each time
let session = LanguageModelSession()
let response = try await session.respond(to: "What's a good month to visit Paris?")
print(response.content)

// Multi-turn: reuse the session; it keeps conversation context
let session = LanguageModelSession(instructions: """
    You are a cooking assistant.
    Provide recipe suggestions based on ingredients.
    Keep suggestions brief and practical.
    """)
let first = try await session.respond(to: "I have chicken and rice")
let followUp = try await session.respond(to: "What about a vegetarian option?")
```

- The result is on `response.content` — there is no `.output` property; that is a common wrong guess.
- `instructions` take priority over prompts; use them for role, task, style, and safety framing.
- A session handles one request at a time — check `session.isResponding` before sending another, or create multiple sessions for concurrency.
- `GenerationOptions(temperature:)` tunes creativity (higher = more creative).

## Guided generation with @Generable

Generate typed Swift values instead of parsing strings:

```swift
@Generable(description: "Basic profile information about a cat")
struct CatProfile {
    var name: String

    @Guide(description: "The age of the cat", .range(0...20))
    var age: Int

    @Guide(description: "A one sentence profile about the cat's personality")
    var profile: String
}

let response = try await session.respond(
    to: "Generate a cute rescue cat",
    generating: CatProfile.self
)
print(response.content.name)   // typed access
```

`@Guide` constraints:
- `.range(0...20)` — numeric range
- `.count(3)` — array element count
- `description:` — semantic guidance

The macro also generates a `PartiallyGenerated` companion type used for streaming.

## Snapshot streaming

Streaming yields snapshots, not deltas: each element is a complete partial state of the value, with all properties Optional (`TripIdeas.PartiallyGenerated`).

```swift
@Generable
struct TripIdeas {
    @Guide(description: "Ideas for upcoming trips")
    var ideas: [String]
}

let stream = session.streamResponse(
    to: "What are some exciting trip ideas?",
    generating: TripIdeas.self
)

for try await partial in stream {
    // partial: TripIdeas.PartiallyGenerated
}
```

SwiftUI integration:

```swift
@State private var partialResult: TripIdeas.PartiallyGenerated?
@State private var errorMessage: String?

var body: some View {
    List {
        ForEach(partialResult?.ideas ?? [], id: \.self) { idea in
            Text(idea)
        }
    }
    .task {
        do {
            let stream = session.streamResponse(to: prompt, generating: TripIdeas.self)
            for try await partial in stream {
                partialResult = partial
            }
        } catch {
            errorMessage = error.localizedDescription
        }
    }
}
```

## Tool calling

A tool is a struct conforming to `Tool` with `name`, `description`, a `@Generable` `Arguments` type, and `call(arguments:) async throws -> ToolOutput`:

```swift
struct RecipeSearchTool: Tool {
    let name = "recipe_search"
    let description = "Search for recipes matching a given term and return a list of results."

    @Generable
    struct Arguments {
        var searchTerm: String
        var numberOfResults: Int
    }

    func call(arguments: Arguments) async throws -> ToolOutput {
        let recipes = await searchRecipes(term: arguments.searchTerm,
                                          limit: arguments.numberOfResults)
        return .string(recipes.map { "- \($0.name): \($0.description)" }.joined(separator: "\n"))
    }
}

let session = LanguageModelSession(tools: [RecipeSearchTool()])
let response = try await session.respond(to: "Find me some pasta recipes")
```

Tool errors surface as `LanguageModelSession.ToolCallError`, which carries the tool and the underlying error:

```swift
do {
    let answer = try await session.respond(to: "Find a recipe for tomato soup.")
} catch let error as LanguageModelSession.ToolCallError {
    print(error.tool.name)
    if case .databaseIsEmpty = error.underlyingError as? RecipeSearchToolError {
        // handle specific tool failure
    }
}
```

## Practical notes

- Prefer `@Generable` output over parsing free text whenever the result has structure.
- Break complex multi-step tasks into several focused prompts rather than one large one — the 4,096-token budget covers instructions, prompt, and output together.
- Profile request latency with Xcode Instruments.

Attribution

MixardMixard
View sourceMore from Mixard →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Caveman

Ultra-compressed communication mode. Cuts token usage ~75% by speaking like caveman while keeping full technical accuracy. Supports intensity levels: lite, full (default), ultra, wenyan-lite, wenyan-full, wenyan-ultra. Use when user says "caveman mode", "talk like caveman", "use caveman", "less tokens", "be brief", or invokes /caveman. Also auto-triggers when token efficiency is requested.

1023331 votes

Hyperplan

Adversarial multi-agent planning skill. Self-orchestrates 5 hostile category members (unspecified-low, unspecified-high, deep, ultrabrain, artistry) via team-mode for ruthless cross-critique debate, distills only the defensible insights, then MANDATORILY hands the distilled insight bundle to the `plan` agent for executable plan formalization. Use when planning needs maximum rigor and surfacing of weak assumptions, blind spots, and over-engineering. Triggers: 'hyperplan', 'hpp', '/hyperplan', ...

686011 votes

Mcp Code Execution

Routes multi-tool workflows through MCP servers for large datasets and pipelines. Use when Bash tool overhead is limiting throughput on data-heavy tasks.

3331 votes

catchup

Recovers prior coding-agent session context by running `catchup <agent> --since-compact`, which extracts a clean summary of a previous Codex, Claude Code, Antigravity, OpenCode, or Pi Agent session. Use when the user says "catch up", "what did the last session do", "get me up to speed", "I switched agents", or asks to recover/summarize a previous session before continuing. Do NOT use for the current conversation, git history, or any non-agent log.

611 votes

math-skill

A comprehensive mathematical reasoning skill for AI assistants — handles arithmetic to research-level problems with rigorous step-by-step reasoning, systematic verification, and transparent uncertainty handling

381 votes
View all in ai-agents →