[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M730Z4MEMHDVFS655ATTBZD2":3,"skill-same:01M730Z4MEMHDVFS655ATTBZD2":47},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":30,"ownerDescription":31,"updatedAt":32,"install":33,"resources":46},"01M730Z4MEMHDVFS655ATTBZD2","foundation-models-on-device",null,"Apple FoundationModels framework for on-device LLM — text generation, guided generation with @Generable, tool calling, and snapshot streaming in iOS 26+.","SriramGandhiS\u002FSkills","SriramGandhiS","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F211849986?v=4","01M72WQCW12BYX71C6WN584TTA","Sriram S","01M72WQCWTJ2RD0ET1X31AF1RC",1,"MIT","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fskills\u002Ffoundation-models-on-device\u002FSKILL.md",[],[],"2026-11-11 15:11:14",false,"---\nname: foundation-models-on-device\ndescription: Apple FoundationModels framework for on-device LLM — text generation, guided generation with @Generable, tool calling, and snapshot streaming in iOS 26+.\n---\n\n# FoundationModels: On-Device LLM (iOS 26)\n\nPatterns 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.\n\n## When to Activate\n\n- Building AI-powered features using Apple Intelligence on-device\n- Generating or summarizing text without cloud dependency\n- Extracting structured data from natural language input\n- Implementing custom tool calling for domain-specific AI actions\n- Streaming structured responses for real-time UI updates\n- Need privacy-preserving AI (no data leaves the device)\n\n## Core Pattern — Availability Check\n\nAlways check model availability before creating a session:\n\n```swift\nstruct GenerativeView: View {\n    private var model = SystemLanguageModel.default\n\n    var body: some View {\n        switch model.availability {\n        case .available:\n            ContentView()\n        case .unavailable(.deviceNotEligible):\n            Text(\"Device not eligible for Apple Intelligence\")\n        case .unavailable(.appleIntelligenceNotEnabled):\n            Text(\"Please enable Apple Intelligence in Settings\")\n        case .unavailable(.modelNotReady):\n            Text(\"Model is downloading or not ready\")\n        case .unavailable(let other):\n            Text(\"Model unavailable: \\(other)\")\n        }\n    }\n}\n```\n\n## Core Pattern — Basic Session\n\n```swift\n\u002F\u002F Single-turn: create a new session each time\nlet session = LanguageModelSession()\nlet response = try await session.respond(to: \"What's a good month to visit Paris?\")\nprint(response.content)\n\n\u002F\u002F Multi-turn: reuse session for conversation context\nlet session = LanguageModelSession(instructions: \"\"\"\n    You are a cooking assistant.\n    Provide recipe suggestions based on ingredients.\n    Keep suggestions brief and practical.\n    \"\"\")\n\nlet first = try await session.respond(to: \"I have chicken and rice\")\nlet followUp = try await session.respond(to: \"What about a vegetarian option?\")\n```\n\nKey points for instructions:\n- Define the model's role (\"You are a mentor\")\n- Specify what to do (\"Help extract calendar events\")\n- Set style preferences (\"Respond as briefly as possible\")\n- Add safety measures (\"Respond with 'I can't help with that' for dangerous requests\")\n\n## Core Pattern — Guided Generation with @Generable\n\nGenerate structured Swift types instead of raw strings:\n\n### 1. Define a Generable Type\n\n```swift\n@Generable(description: \"Basic profile information about a cat\")\nstruct CatProfile {\n    var name: String\n\n    @Guide(description: \"The age of the cat\", .range(0...20))\n    var age: Int\n\n    @Guide(description: \"A one sentence profile about the cat's personality\")\n    var profile: String\n}\n```\n\n### 2. Request Structured Output\n\n```swift\nlet response = try await session.respond(\n    to: \"Generate a cute rescue cat\",\n    generating: CatProfile.self\n)\n\n\u002F\u002F Access structured fields directly\nprint(\"Name: \\(response.content.name)\")\nprint(\"Age: \\(response.content.age)\")\nprint(\"Profile: \\(response.content.profile)\")\n```\n\n### Supported @Guide Constraints\n\n- `.range(0...20)` — numeric range\n- `.count(3)` — array element count\n- `description:` — semantic guidance for generation\n\n## Core Pattern — Tool Calling\n\nLet the model invoke custom code for domain-specific tasks:\n\n### 1. Define a Tool\n\n```swift\nstruct RecipeSearchTool: Tool {\n    let name = \"recipe_search\"\n    let description = \"Search for recipes matching a given term and return a list of results.\"\n\n    @Generable\n    struct Arguments {\n        var searchTerm: String\n        var numberOfResults: Int\n    }\n\n    func call(arguments: Arguments) async throws -> ToolOutput {\n        let recipes = await searchRecipes(\n            term: arguments.searchTerm,\n            limit: arguments.numberOfResults\n        )\n        return .string(recipes.map { \"- \\($0.name): \\($0.description)\" }.joined(separator: \"\\n\"))\n    }\n}\n```\n\n### 2. Create Session with Tools\n\n```swift\nlet session = LanguageModelSession(tools: [RecipeSearchTool()])\nlet response = try await session.respond(to: \"Find me some pasta recipes\")\n```\n\n### 3. Handle Tool Errors\n\n```swift\ndo {\n    let answer = try await session.respond(to: \"Find a recipe for tomato soup.\")\n} catch let error as LanguageModelSession.ToolCallError {\n    print(error.tool.name)\n    if case .databaseIsEmpty = error.underlyingError as? RecipeSearchToolError {\n        \u002F\u002F Handle specific tool error\n    }\n}\n```\n\n## Core Pattern — Snapshot Streaming\n\nStream structured responses for real-time UI with `PartiallyGenerated` types:\n\n```swift\n@Generable\nstruct TripIdeas {\n    @Guide(description: \"Ideas for upcoming trips\")\n    var ideas: [String]\n}\n\nlet stream = session.streamResponse(\n    to: \"What are some exciting trip ideas?\",\n    generating: TripIdeas.self\n)\n\nfor try await partial in stream {\n    \u002F\u002F partial: TripIdeas.PartiallyGenerated (all properties Optional)\n    print(partial)\n}\n```\n\n### SwiftUI Integration\n\n```swift\n@State private var partialResult: TripIdeas.PartiallyGenerated?\n@State private var errorMessage: String?\n\nvar body: some View {\n    List {\n        ForEach(partialResult?.ideas ?? [], id: \\.self) { idea in\n            Text(idea)\n        }\n    }\n    .overlay {\n        if let errorMessage { Text(errorMessage).foregroundStyle(.red) }\n    }\n    .task {\n        do {\n            let stream = session.streamResponse(to: prompt, generating: TripIdeas.self)\n            for try await partial in stream {\n                partialResult = partial\n            }\n        } catch {\n            errorMessage = error.localizedDescription\n        }\n    }\n}\n```\n\n## Key Design Decisions\n\n| Decision | Rationale |\n|----------|-----------|\n| On-device execution | Privacy — no data leaves the device; works offline |\n| 4,096 token limit | On-device model constraint; chunk large data across sessions |\n| Snapshot streaming (not deltas) | Structured output friendly; each snapshot is a complete partial state |\n| `@Generable` macro | Compile-time safety for structured generation; auto-generates `PartiallyGenerated` type |\n| Single request per session | `isResponding` prevents concurrent requests; create multiple sessions if needed |\n| `response.content` (not `.output`) | Correct API — always access results via `.content` property |\n\n## Best Practices\n\n- **Always check `model.availability`** before creating a session — handle all unavailability cases\n- **Use `instructions`** to guide model behavior — they take priority over prompts\n- **Check `isResponding`** before sending a new request — sessions handle one request at a time\n- **Access `response.content`** for results — not `.output`\n- **Break large inputs into chunks** — 4,096 token limit applies to instructions + prompt + output combined\n- **Use `@Generable`** for structured output — stronger guarantees than parsing raw strings\n- **Use `GenerationOptions(temperature:)`** to tune creativity (higher = more creative)\n- **Monitor with Instruments** — use Xcode Instruments to profile request performance\n\n## Anti-Patterns to Avoid\n\n- Creating sessions without checking `model.availability` first\n- Sending inputs exceeding the 4,096 token context window\n- Attempting concurrent requests on a single session\n- Using `.output` instead of `.content` to access response data\n- Parsing raw string responses when `@Generable` structured output would work\n- Building complex multi-step logic in a single prompt — break into multiple focused prompts\n- Assuming the model is always available — device eligibility and settings vary\n\n## When to Use\n\n- On-device text generation for privacy-sensitive apps\n- Structured data extraction from user input (forms, natural language commands)\n- AI-assisted features that must work offline\n- Streaming UI that progressively shows generated content\n- Domain-specific AI actions via tool calling (search, compute, lookup)\n","# FoundationModels: On-Device LLM (iOS 26)\n\nPatterns 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.\n\n## When to Activate\n\n- Building AI-powered features using Apple Intelligence on-device\n- Generating or summarizing text without cloud dependency\n- Extracting structured data from natural language input\n- Implementing custom tool calling for domain-specific AI actions\n- Streaming structured responses for real-time UI updates\n- Need privacy-preserving AI (no data leaves the device)\n\n## Core Pattern — Availability Check\n\nAlways check model availability before creating a session:\n\n```swift\nstruct GenerativeView: View {\n    private var model = SystemLanguageModel.default\n\n    var body: some View {\n        switch model.availability {\n        case .available:\n            ContentView()\n        case .unavailable(.deviceNotEligible):\n            Text(\"Device not eligible for Apple Intelligence\")\n        case .unavailable(.appleIntelligenceNotEnabled):\n            Text(\"Please enable Apple Intelligence in Settings\")\n        case .unavailable(.modelNotReady):\n            Text(\"Model is downloading or not ready\")\n        case .unavailable(let other):\n            Text(\"Model unavailable: \\(other)\")\n        }\n    }\n}\n```\n\n## Core Pattern — Basic Session\n\n```swift\n\u002F\u002F Single-turn: create a new session each time\nlet session = LanguageModelSession()\nlet response = try await session.respond(to: \"What's a good month to visit Paris?\")\nprint(response.content)\n\n\u002F\u002F Multi-turn: reuse session for conversation context\nlet session = LanguageModelSession(instructions: \"\"\"\n    You are a cooking assistant.\n    Provide recipe suggestions based on ingredients.\n    Keep suggestions brief and practical.\n    \"\"\")\n\nlet first = try await session.respond(to: \"I have chicken and rice\")\nlet followUp = try await session.respond(to: \"What about a vegetarian option?\")\n```\n\nKey points for instructions:\n- Define the model's role (\"You are a mentor\")\n- Specify what to do (\"Help extract calendar events\")\n- Set style preferences (\"Respond as briefly as possible\")\n- Add safety measures (\"Respond with 'I can't help with that' for dangerous requests\")\n\n## Core Pattern — Guided Generation with @Generable\n\nGenerate structured Swift types instead of raw strings:\n\n### 1. Define a Generable Type\n\n```swift\n@Generable(description: \"Basic profile information about a cat\")\nstruct CatProfile {\n    var name: String\n\n    @Guide(description: \"The age of the cat\", .range(0...20))\n    var age: Int\n\n    @Guide(description: \"A one sentence profile about the cat's personality\")\n    var profile: String\n}\n```\n\n### 2. Request Structured Output\n\n```swift\nlet response = try await session.respond(\n    to: \"Generate a cute rescue cat\",\n    generating: CatProfile.self\n)\n\n\u002F\u002F Access structured fields directly\nprint(\"Name: \\(response.content.name)\")\nprint(\"Age: \\(response.content.age)\")\nprint(\"Profile: \\(response.content.profile)\")\n```\n\n### Supported @Guide Constraints\n\n- `.range(0...20)` — numeric range\n- `.count(3)` — array element count\n- `description:` — semantic guidance for generation\n\n## Core Pattern — Tool Calling\n\nLet the model invoke custom code for domain-specific tasks:\n\n### 1. Define a Tool\n\n```swift\nstruct RecipeSearchTool: Tool {\n    let name = \"recipe_search\"\n    let description = \"Search for recipes matching a given term and return a list of results.\"\n\n    @Generable\n    struct Arguments {\n        var searchTerm: String\n        var numberOfResults: Int\n    }\n\n    func call(arguments: Arguments) async throws -> ToolOutput {\n        let recipes = await searchRecipes(\n            term: arguments.searchTerm,\n            limit: arguments.numberOfResults\n        )\n        return .string(recipes.map { \"- \\($0.name): \\($0.description)\" }.joined(separator: \"\\n\"))\n    }\n}\n```\n\n### 2. Create Session with Tools\n\n```swift\nlet session = LanguageModelSession(tools: [RecipeSearchTool()])\nlet response = try await session.respond(to: \"Find me some pasta recipes\")\n```\n\n### 3. Handle Tool Errors\n\n```swift\ndo {\n    let answer = try await session.respond(to: \"Find a recipe for tomato soup.\")\n} catch let error as LanguageModelSession.ToolCallError {\n    print(error.tool.name)\n    if case .databaseIsEmpty = error.underlyingError as? RecipeSearchToolError {\n        \u002F\u002F Handle specific tool error\n    }\n}\n```\n\n## Core Pattern — Snapshot Streaming\n\nStream structured responses for real-time UI with `PartiallyGenerated` types:\n\n```swift\n@Generable\nstruct TripIdeas {\n    @Guide(description: \"Ideas for upcoming trips\")\n    var ideas: [String]\n}\n\nlet stream = session.streamResponse(\n    to: \"What are some exciting trip ideas?\",\n    generating: TripIdeas.self\n)\n\nfor try await partial in stream {\n    \u002F\u002F partial: TripIdeas.PartiallyGenerated (all properties Optional)\n    print(partial)\n}\n```\n\n### SwiftUI Integration\n\n```swift\n@State private var partialResult: TripIdeas.PartiallyGenerated?\n@State private var errorMessage: String?\n\nvar body: some View {\n    List {\n        ForEach(partialResult?.ideas ?? [], id: \\.self) { idea in\n            Text(idea)\n        }\n    }\n    .overlay {\n        if let errorMessage { Text(errorMessage).foregroundStyle(.red) }\n    }\n    .task {\n        do {\n            let stream = session.streamResponse(to: prompt, generating: TripIdeas.self)\n            for try await partial in stream {\n                partialResult = partial\n            }\n        } catch {\n            errorMessage = error.localizedDescription\n        }\n    }\n}\n```\n\n## Key Design Decisions\n\n| Decision | Rationale |\n|----------|-----------|\n| On-device execution | Privacy — no data leaves the device; works offline |\n| 4,096 token limit | On-device model constraint; chunk large data across sessions |\n| Snapshot streaming (not deltas) | Structured output friendly; each snapshot is a complete partial state |\n| `@Generable` macro | Compile-time safety for structured generation; auto-generates `PartiallyGenerated` type |\n| Single request per session | `isResponding` prevents concurrent requests; create multiple sessions if needed |\n| `response.content` (not `.output`) | Correct API — always access results via `.content` property |\n\n## Best Practices\n\n- **Always check `model.availability`** before creating a session — handle all unavailability cases\n- **Use `instructions`** to guide model behavior — they take priority over prompts\n- **Check `isResponding`** before sending a new request — sessions handle one request at a time\n- **Access `response.content`** for results — not `.output`\n- **Break large inputs into chunks** — 4,096 token limit applies to instructions + prompt + output combined\n- **Use `@Generable`** for structured output — stronger guarantees than parsing raw strings\n- **Use `GenerationOptions(temperature:)`** to tune creativity (higher = more creative)\n- **Monitor with Instruments** — use Xcode Instruments to profile request performance\n\n## Anti-Patterns to Avoid\n\n- Creating sessions without checking `model.availability` first\n- Sending inputs exceeding the 4,096 token context window\n- Attempting concurrent requests on a single session\n- Using `.output` instead of `.content` to access response data\n- Parsing raw string responses when `@Generable` structured output would work\n- Building complex multi-step logic in a single prompt — break into multiple focused prompts\n- Assuming the model is always available — device eligibility and settings vary\n\n## When to Use\n\n- On-device text generation for privacy-sensitive apps\n- Structured data extraction from user input (forms, natural language commands)\n- AI-assisted features that must work offline\n- Streaming UI that progressively shows generated content\n- Domain-specific AI actions via tool calling (search, compute, lookup)\n",{"name":5,"description":7},"master","d6ca01da0f24a3b0e26e4a8b7b66cbd25d429f5d","skills\u002Ffoundation-models-on-device",0,"https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills","https:\u002F\u002Fgithub.com\u002FSriramGandhiS","https:\u002F\u002Fsriram.website\u002F","Curious guy who keeps tinkering until something works","2026-05-20 16:21:34",{"source":8,"skillName":5,"commands":34,"prompt":44,"zipAvailable":45},[35,38,41],{"tool":36,"command":37},"npx","npx skills add SriramGandhiS\u002FSkills --skill foundation-models-on-device",{"tool":39,"command":40},"bunx","bunx skills add SriramGandhiS\u002FSkills --skill foundation-models-on-device",{"tool":42,"command":43},"pnpm","pnpm dlx skills add SriramGandhiS\u002FSkills --skill foundation-models-on-device","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fskills\u002Ffoundation-models-on-device\u002FSKILL.md",true,[],[48,55,60,66,73,80],{"skillNo":49,"name":50,"nameZh":6,"description":51,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":52,"categories":53,"keywords":54,"publishedAt":19},"01M732609EPJWV13PVTX3GT4TM","webgpu-threejs-tsl","Comprehensive guide for developing WebGPU-enabled Three.js applications using TSL (Three.js Shading Language). Covers WebGPU renderer setup, TSL syntax and node materials, compute shaders, post-processing effects, and WGSL integration. Use this skill when working with Three.js WebGPU, TSL shaders, node materials, or GPU compute in Three.js.","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fwebgpu-threejs-tsl\u002Fskills\u002Fwebgpu-threejs-tsl\u002FSKILL.md",[],[],{"skillNo":56,"name":50,"nameZh":6,"description":51,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":57,"categories":58,"keywords":59,"publishedAt":19},"01M7325XM47AGWB6K6C4VXKE6B","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fwebgpu-threejs-tsl\u002FSKILL.md",[],[],{"skillNo":61,"name":62,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":63,"categories":64,"keywords":65,"publishedAt":19},"01M7325WP6DES69JKC840VMFEP","verification-loop","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fweb-assets\u002Fdocs\u002Fzh-TW\u002Fskills\u002Fverification-loop\u002FSKILL.md",[],[],{"skillNo":67,"name":68,"nameZh":6,"description":69,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":70,"categories":71,"keywords":72,"publishedAt":19},"01M7325TFQF1DZTQ6J3WGQQ1VR","tdd-workflow","Use this skill when writing new features, fixing bugs, or refactoring code. Enforces test-driven development with 80%+ coverage including unit, integration, and E2E tests.","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fweb-assets\u002Fdocs\u002Fzh-TW\u002Fskills\u002Ftdd-workflow\u002FSKILL.md",[],[],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":19},"01M7325RGV9AY9PK92D2V8KKPW","strategic-compact","Suggests manual context compaction at logical intervals to preserve context through task phases rather than arbitrary auto-compaction.","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fweb-assets\u002Fdocs\u002Fzh-TW\u002Fskills\u002Fstrategic-compact\u002FSKILL.md",[],[],{"skillNo":81,"name":82,"nameZh":6,"description":83,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":19},"01M7325MZC28SE86E7NMCNEFS4","security-review","Use this skill when adding authentication, handling user input, working with secrets, creating API endpoints, or implementing payment\u002Fsensitive features. Provides comprehensive security checklist and patterns.","https:\u002F\u002Fgithub.com\u002FSriramGandhiS\u002FSkills\u002Fblob\u002Fmaster\u002Fweb-assets\u002Fdocs\u002Fzh-TW\u002Fskills\u002Fsecurity-review\u002FSKILL.md",[],[]]