affaan-m avatar

Foundation Models On Device Skill

Installs
12.4k
Repo stars
316k
Repo updated
Dec 1, 2026

TL;DR

foundation-models-on-device is an agent skill that implements on-device text generation, structured output, tool calling, and streaming in iOS apps using Apple's FoundationModels framework for developers who need private

Install if

iOS developers building Apple Intelligence features that require on-device inference, structured extraction, and offline-capable LLM workflows on iOS 26.

Skip if

Android or cross-platform apps, or iOS projects that rely solely on cloud OpenAI or Anthropic APIs without on-device models.

npx skills add https://github.com/affaan-m/ECC --skill foundation-models-on-device
On this page
  1. What foundation-models-on-device covers
  2. foundation-models-on-device by the numbers
  3. What does the Foundation Models On Device skill produce?
  4. What files ship with foundation-models-on-device?
  5. Which skills are related to foundation-models-on-device?
  6. What are the Foundation Models On Device skill forks?
  7. How does foundation-models-on-device compare?
  8. Foundation Models On Device skill FAQ
  9. More in this repo

What foundation-models-on-device covers

  • Runs large language models entirely on-device with no cloud dependency
  • Supports text generation, guided generation with @Generable, custom tool calling, and snapshot streaming
  • Built-in availability checks for SystemLanguageModel (device eligibility, Apple Intelligence enabled, model ready)
  • Delivers privacy-first AI where no user data leaves the device
  • Real-time structured response streaming for responsive iOS UI updates

foundation-models-on-device by the numbers

All-time installs12,434 (12.4k)skills.sh registry
Repo stars★ 316kGitHub
Repo last updatedDecember 1, 2026GitHub
Repositoryaffaan-m/ECC ↗

Data as of Dec 4, 2026 (Skillselion catalog sync)

What does the Foundation Models On Device skill produce?

Swift FoundationModels integration with text generation, @Generable typed outputs, custom tool handlers, and streaming UI snapshots.

  • FoundationModels Swift integration
  • @Generable schema types
  • Streaming UI snapshot handlers

What files ship with foundation-models-on-device?

SKILL.mdMarkdownGitHub ↗

FoundationModels: On-Device LLM (iOS 26)

Patterns for integrating Apple's on-device language model into apps using the FoundationModels framework. Covers text generation, structured output with @Generable, custom tool calling, and snapshot streaming — all running on-device for privacy and offline support.

When to Activate

  • Building AI-powered features using Apple Intelligence on-device
  • Generating or summarizing text without cloud dependency
  • Extracting structured data from natural language input
  • Implementing custom tool calling for domain-specific AI actions
  • Streaming structured responses for real-time UI updates
  • Need privacy-preserving AI (no data leaves the device)

Core Pattern — Availability Check

Always check model availability before creating a session:

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)")
        }
    }
}

Core Pattern — Basic Session

// Single-turn: create a 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 session for 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?")

Key points for instructions:

  • Define the model's role ("You are a mentor")
  • Specify what to do ("Help extract calendar events")
  • Set style preferences ("Respond as briefly as possible")
  • Add safety measures ("Respond with 'I can't help with that' for dangerous requests")

Core Pattern — Guided Generation with @Generable

Generate structured Swift types instead of raw strings:

1. Define a Generable Type
@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
}
2. Request Structured Output
let response = try await session.respond(
    to: "Generate a cute rescue cat",
    generating: CatProfile.self
)

// Access structured fields directly
print("Name: \(response.content.name)")
print("Age: \(response.content.age)")
print("Profile: \(response.content.profile)")
Supported @Guide Constraints
  • .range(0...20) — numeric range
  • .count(3) — array element count
  • description: — semantic guidance for generation

Core Pattern — Tool Calling

Let the model invoke custom code for domain-specific tasks:

1. Define a Tool
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"))
    }
}
2. Create Session with Tools
let session = LanguageModelSession(tools: [RecipeSearchTool()])
let response = try await session.respond(to: "Find me some pasta recipes")
3. Handle Tool Errors
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 error
    }
}

Core Pattern — Snapshot Streaming

Stream structured responses for real-time UI with PartiallyGenerated types:

@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 (all properties Optional)
    print(partial)
}
SwiftUI Integration
@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)
        }
    }
    .overlay {
        if let errorMessage { Text(errorMessage).foregroundStyle(.red) }
    }
    .task {
        do {
            let stream = session.streamResponse(to: prompt, generating: TripIdeas.self)
            for try await partial in stream {
                partialResult = partial
            }
        } catch {
            errorMessage = error.localizedDescription
        }
    }
}

Key Design Decisions

DecisionRationale
On-device executionPrivacy — no data leaves the device; works offline
4,096 token limitOn-device model constraint; chunk large data across sessions
Snapshot streaming (not deltas)Structured output friendly; each snapshot is a complete partial state
@Generable macroCompile-time safety for structured generation; auto-generates PartiallyGenerated type
Single request per sessionisResponding prevents concurrent requests; create multiple sessions if needed
response.content (not .output)Correct API — always access results via .content property

Best Practices

  • Always check model.availability before creating a session — handle all unavailability cases
  • Use instructions to guide model behavior — they take priority over prompts
  • Check isResponding before sending a new request — sessions handle one request at a time
  • Access response.content for results — not .output
  • Break large inputs into chunks — 4,096 token limit applies to instructions + prompt + output combined
  • Use @Generable for structured output — stronger guarantees than parsing raw strings
  • Use GenerationOptions(temperature:) to tune creativity (higher = more creative)
  • Monitor with Instruments — use Xcode Instruments to profile request performance

Anti-Patterns to Avoid

  • Creating sessions without checking model.availability first
  • Sending inputs exceeding the 4,096 token context window
  • Attempting concurrent requests on a single session
  • Using .output instead of .content to access response data
  • Parsing raw string responses when @Generable structured output would work
  • Building complex multi-step logic in a single prompt — break into multiple focused prompts
  • Assuming the model is always available — device eligibility and settings vary

When to Use

  • On-device text generation for privacy-sensitive apps
  • Structured data extraction from user input (forms, natural language commands)
  • AI-assisted features that must work offline
  • Streaming UI that progressively shows generated content
  • Domain-specific AI actions via tool calling (search, compute, lookup)

Which skills are related to foundation-models-on-device?

What are the Foundation Models On Device skill forks?

Foundation Models On Device has 1 known copy in the catalog totaling 5.6k installs. They canonicalize to this original listing.

How does foundation-models-on-device compare?

Pick foundation-models-on-device for Apple on-device LLM on iOS; pick cloud LLM SDK skills when inference must run on remote APIs.

Foundation Models On Device skill FAQ

Who is the Foundation Models On Device skill for?

iOS developers building Apple Intelligence features that require on-device inference, structured extraction, and offline-capable LLM workflows on iOS 26. Skip if: Android or cross-platform apps, or iOS projects that rely solely on cloud OpenAI or Anthropic APIs without on-device models.

When should I use foundation-models-on-device?

User asks to integrate FoundationModels, add @Generable structured output, stream on-device LLM responses, or build offline Apple Intelligence features on iOS.

What iOS version does foundation-models-on-device target?

foundation-models-on-device targets iOS 26 patterns using Apple's FoundationModels framework for on-device text generation, @Generable structured output, tool calling, and snapshot streaming without cloud dependency.

Does foundation-models-on-device support structured output?

foundation-models-on-device documents the @Generable macro for typed structured extraction from natural language plus custom tool calling and streaming snapshots, all executed on-device for privacy.

Add a foundation-models-on-device badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Get the embed code
AI & Agent Buildingagentsllmautomation

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.