Agent skill

Foundation Models On Device

by affaan-m in affaan-m/ECC

苹果FoundationModels框架用于设备上的LLM——文本生成、使用@Generable进行引导生成、工具调用,以及在iOS 26+中的快照流。

MITAuto-check passedMobile

Install Foundation Models On Device

skills CLI
$ npx skills add affaan-m/ECC --skill foundation-models-on-device -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install affaan-m/ECC foundation-models-on-device --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/affaan-m/ECC.git skills-src && mkdir -p .claude/skills && cp -r skills-src/docs/zh-CN/skills/foundation-models-on-device .claude/skills/foundation-models-on-device && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
foundation-models-on-device
GitHub stars
277k
Used in
3 other repos
Token cost
~1.5k tokens
SKILL.md length
151 words
Files
1
Skills in repo
683
Repo updated
First seen
Licence
MIT

At a glance

苹果FoundationModels框架用于设备上的LLM——文本生成、使用@Generable进行引导生成、工具调用,以及在iOS 26+中的快照流。

  • Works in 5 steps: 定义可生成类型 → 请求结构化输出 → 定义工具 → …
  • Mobile work in your project
  • SKILL.md covers 何时启用, 核心模式 — 可用性检查, 核心模式 — 基础会话 and 核心模式 — 使用 @Generable 进行引导式生成, plus 6 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Foundation Models On Device is an agent skill from affaan-m/ECC. 苹果FoundationModels框架用于设备上的LLM——文本生成、使用@Generable进行引导生成、工具调用,以及在iOS 26+中的快照流。

Its SKILL.md is about 1.5k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Mobile. It works with iOS. The repository describes itself as: The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond. The licence is MIT.

When your agent uses it

  • Mobile work in your project

Example prompts

  • “/foundation-models-on-device”

Workflow steps

5 steps, taken from the step headings in SKILL.md.

  1. 定义可生成类型
  2. 请求结构化输出
  3. 定义工具
  4. 创建带工具的会话
  5. 处理工具错误

What it can do on your machine

Read from SKILL.md and the folder at commit 2d515e4. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are swift).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Foundation Models On Device loads about 1.5k tokens when it runs. Until then it costs about 26 tokens; SKILL.md has 151 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~26
When it runs · the whole SKILL.md, loaded when a task matches
~1.5k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from affaan-m/ECC at commit 2d515e4, republished under its MIT licence (© affaan-m). 151 words, ~1,489 tokens.

Download SKILL.mdSave it as .claude/skills/foundation-models-on-device/SKILL.md (or your agent's skills folder).
name
foundation-models-on-device
description
苹果FoundationModels框架用于设备上的LLM——文本生成、使用@Generable进行引导生成、工具调用,以及在iOS 26+中的快照流。

FoundationModels:设备端 LLM(iOS 26)

使用 FoundationModels 框架将苹果的设备端语言模型集成到应用中的模式。涵盖文本生成、使用 @Generable 的结构化输出、自定义工具调用以及快照流式传输——全部在设备端运行,以保护隐私并支持离线使用。

何时启用

  • 使用 Apple Intelligence 在设备端构建 AI 功能
  • 无需依赖云端即可生成或总结文本
  • 从自然语言输入中提取结构化数据
  • 为特定领域的 AI 操作实现自定义工具调用
  • 流式传输结构化响应以实现实时 UI 更新
  • 需要保护隐私的 AI(数据不离开设备)

核心模式 — 可用性检查

在创建会话之前,始终检查模型可用性:

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

核心模式 — 基础会话

swift
// 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?")

指令的关键点:

  • 定义模型的角色("你是一位导师")
  • 指定要做什么("帮助提取日历事件")
  • 设置风格偏好("尽可能简短地回答")
  • 添加安全措施("对于危险请求,回复'我无法提供帮助'")

核心模式 — 使用 @Generable 进行引导式生成

生成结构化的 Swift 类型,而不是原始字符串:

1. 定义可生成类型
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
}
2. 请求结构化输出
swift
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)")
支持的 @Guide 约束
  • .range(0...20) — 数值范围
  • .count(3) — 数组元素数量
  • description: — 生成的语义引导

核心模式 — 工具调用

让模型调用自定义代码以执行特定领域的任务:

1. 定义工具
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"))
    }
}
2. 创建带工具的会话
swift
let session = LanguageModelSession(tools: [RecipeSearchTool()])
let response = try await session.respond(to: "Find me some pasta recipes")
3. 处理工具错误
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 error
    }
}

核心模式 — 快照流式传输

使用 PartiallyGenerated 类型为实时 UI 流式传输结构化响应:

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 (all properties Optional)
    print(partial)
}
SwiftUI 集成
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)
        }
    }
    .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
        }
    }
}

关键设计决策

决策理由
设备端执行隐私性——数据不离开设备;支持离线工作
4,096 个令牌限制设备端模型约束;跨会话分块处理大数据
快照流式传输(非增量)对结构化输出友好;每个快照都是一个完整的部分状态
@Generable 宏为结构化生成提供编译时安全性;自动生成 PartiallyGenerated 类型
每个会话单次请求isResponding 防止并发请求;如有需要,创建多个会话
response.content(而非 .output)正确的 API——始终通过 .content 属性访问结果

最佳实践

  • 在创建会话之前始终检查 model.availability——处理所有不可用的情况
  • 使用 instructions 来引导模型行为——它们的优先级高于提示词
  • 在发送新请求之前检查 isResponding——会话一次处理一个请求
  • 通过 response.content 访问结果——而不是 .output
  • 将大型输入分块处理——4,096 个令牌的限制适用于指令、提示词和输出的总和
  • 对于结构化输出使用 @Generable——比解析原始字符串提供更强的保证
  • 使用 GenerationOptions(temperature:) 来调整创造力(值越高越有创意)
  • 使用 Instruments 进行监控——使用 Xcode Instruments 来分析请求性能

应避免的反模式

  • 未先检查 model.availability 就创建会话
  • 发送超过 4,096 个令牌上下文窗口的输入
  • 尝试在单个会话上进行并发请求
  • 使用 .output 而不是 .content 来访问响应数据
  • 当 @Generable 结构化输出可行时,却去解析原始字符串响应
  • 在单个提示词中构建复杂的多步逻辑——将其拆分为多个聚焦的提示词
  • 假设模型始终可用——设备的资格和设置各不相同

何时使用

  • 为注重隐私的应用进行设备端文本生成
  • 从用户输入(表单、自然语言命令)中提取结构化数据
  • 必须离线工作的 AI 辅助功能
  • 逐步显示生成内容的流式 UI
  • 通过工具调用(搜索、计算、查找)执行特定领域的 AI 操作

© affaan-m, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in docs/zh-CN/skills/foundation-models-on-device of affaan-m/ECC.

Open the folder on GitHubat commit 2d515e4

Used in 3 other repositories

We found 3 copies of this SKILL.md (exact, near-identical or edited) in other folders, from 3 other GitHub owners. This page covers the copy in affaan-m/ECC, which our catalogue first saw on October 7, 2026.

Compare with similar skills

Foundation Models On Device next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Foundation Models On Device compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Foundation Models On Device this skillaffaan-m/ECC277k3 repos~1.5kAutomated safety check: PassMIT
Hig Project Contextraintree-technology/hig-doctor1445 repos~1.2kAutomated safety check: PassMIT
Hig Components Contentraintree-technology/hig-doctor1445 repos~1.3kAutomated safety check: PassMIT
Discover iOS KeysPoomSmart/MGKeys238—~1.4kAutomated safety check: PassMIT
Argent Metro Debuggerbbplayer-app/BBPlayer1.2k—~3.4kAutomated safety check: PassMIT
iOS Simulator Skilln0an/VivaDicta1301 repos~2.5kAutomated safety check: PassMIT

Similar skills

  • Hig Project Context

    raintree-technology/hig-doctor

    Create or update a shared Apple design context document that other HIG skills use to tailor guidance.

    144 GitHub starsUsed in 5 repos~1.2k tokens
    MobileAuto-check passed
  • Hig Components Content

    raintree-technology/hig-doctor

    Apple Human Interface Guidelines for content display components.

    144 GitHub starsUsed in 5 repos~1.3k tokens
    MobileAuto-check passed
  • Discover iOS Keys

    PoomSmart/MGKeys

    Discover and map new MobileGestalt keys for a new iOS version in MGKeys.

    238 GitHub stars~1.4k tokensUpdated 22 days ago
    MobileAuto-check passed
  • Argent Metro Debugger

    bbplayer-app/BBPlayer

    Debug a JS runtime via CDP using argent debugger tools. An agent skill from bbplayer-app/BBPlayer.

    1.2k GitHub stars~3.4k tokensUpdated 3 days ago
    MobileAuto-check passed
  • iOS Simulator Skill

    n0an/VivaDicta

    21 production-ready scripts for iOS app testing, building, and automation.

    130 GitHub starsUsed in 1 repo~2.5k tokens
    MobileAuto-check passed
  • Theming

    Code-with-Beto/skills

    Scaffold a unified, cross-platform color theme system into an Expo Router app.

    140 GitHub stars~2.5k tokensUpdated 3 mo ago
    MobileAuto-check passed

More from affaan-m/ECC

All 682 skills in this repo
  • Skill Stocktake

    affaan-m/ECC

    Audits your installed Claude skills and commands for quality, with a quick mode for recently changed skills and a full mode that evaluates all of them through subagents.

    277k GitHub starsUsed in 5 repos~3.1k tokens
    Auto-check passed
  • Ingests, indexes, searches, edits and monitors video, audio and live streams through the VideoDB Python SDK, returning stream links, clips and timestamps.

    277k GitHub starsUsed in 3 repos~3.5k tokens
    Auto-check: notes
  • Docs Governance

    affaan-m/ECC

    Route broad documentation-governance requests to existing ECC skills and run an opt-in, read-only audit of mapped documentation roles, links, ADR indexes, and evidence references.

    277k GitHub stars~1.1k tokensUpdated today
    Auto-check passed
  • Rules Distillation

    affaan-m/ECC

    Scans installed skills for principles that recur across them and proposes rule-file changes: append, revise, add a section, create a file or leave as covered.

    277k GitHub starsUsed in 2 repos~2.3k tokens
    Auto-check passed
  • Builds DRAFT counterparty agreements from one markdown template and a small JSON spec per party, with clauses picked by the party's role.

    277k GitHub stars~2.9k tokensUpdated today
    Auto-check passed
  • Set an ECC-specific frontend design direction for production UI work.

    277k GitHub starsUsed in 1 repo~2.2k tokens
    Auto-check passed

Works with

Categories

Questions about Foundation Models On Device

What does Foundation Models On Device do?

苹果FoundationModels框架用于设备上的LLM——文本生成、使用@Generable进行引导生成、工具调用,以及在iOS 26+中的快照流。. Foundation Models On Device is an agent skill from affaan-m/ECC.

When should I use Foundation Models On Device?

Foundation Models On Device fits situations like: mobile work in your project.

How do I install Foundation Models On Device in Claude Code?

Run `npx skills add affaan-m/ECC --skill foundation-models-on-device -a claude-code`. Or copy the skill folder (docs/zh-CN/skills/foundation-models-on-device in affaan-m/ECC) into .claude/skills/foundation-models-on-device in your project. Claude Code loads it when a task matches its description.

How do I install Foundation Models On Device in Codex?

Run `npx skills add affaan-m/ECC --skill foundation-models-on-device -a codex`. Or copy the skill folder (docs/zh-CN/skills/foundation-models-on-device in affaan-m/ECC) into .agents/skills/foundation-models-on-device in your project. Codex loads it when a task matches its description.

Can I use Foundation Models On Device in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add affaan-m/ECC --skill foundation-models-on-device -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/foundation-models-on-device, .gemini/skills/foundation-models-on-device, .github/skills/foundation-models-on-device and .opencode/skills/foundation-models-on-device in your project.

What does Foundation Models On Device need to run?

SKILL.md names no scripts, command-line tools or credentials: Foundation Models On Device is instructions for the agent only.

Does Foundation Models On Device access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Foundation Models On Device safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Foundation Models On Device use?

Foundation Models On Device is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Foundation Models On Device use?

About 1.5k tokens (SKILL.md is roughly 6k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Foundation Models On Device?

Skills that share tags, products or a category with Foundation Models On Device: Hig Project Context (raintree-technology/hig-doctor, 144 stars), Hig Components Content (raintree-technology/hig-doctor, 144 stars), Discover iOS Keys (PoomSmart/MGKeys, 238 stars) and Argent Metro Debugger (bbplayer-app/BBPlayer, 1.2k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Foundation Models On Device?

affaan-m (a GitHub user) maintains it in affaan-m/ECC, which has 276,673 GitHub stars. The repository holds 683 skills in this directory. The repository was last updated on October 11, 2026.

Source: affaan-m/ECC on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.