跪拜 Guibai
← All articles
AI Programming · Artificial Intelligence · Apple

Apple Foundation Models: A Unified AI Framework for On-Device, Cloud, and Custom Models

By Bowen_Jin ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Apple finally gives third-party developers a first-class, unified AI interface that respects the platform's privacy and execution model, eliminating the need to bolt on separate SDKs for on-device vs. cloud inference. For iOS and macOS developers, this means AI features can be built once and run anywhere Apple's models run, with the app still owning all security decisions.

Summary

Apple Foundation Models is Apple's generative AI development framework, officially available for building AI features into apps. It unifies access to three model sources: SystemLanguageModel running locally on iOS and macOS, PrivateCloudComputeLanguageModel running on Apple's own data centers, and custom models plugged in through a protocol. One LanguageModelSession API handles prompts, history, tools, and structured output, so switching between on-device and cloud models requires no rewrite of the calling code.

The framework's five core objects separate concerns cleanly: LanguageModel decides where inference runs, LanguageModelSession manages the conversation and tool invocation, @Generable converts model output into typed Swift structures, Tool lets the model request app actions while the app retains execution control, and DynamicProfile switches session configuration (instructions, model, temperature) based on app state. A historyTransform hook lets developers compress the transcript fed to the model without touching the original history.

Beyond Swift, Apple ships a command-line tool `fm` and a Python SDK (`pip install apple_fm_sdk`) that mirror the Swift API, with @fm.generable for structured output. A built-in SpotlightSearchTool lets models query content the app has indexed in Spotlight. Custom models require implementing LanguageModel and LanguageModelExecutor, mapping four things: history messages, generation parameters, streaming output, and errors.

Takeaways
— Apple Foundation Models exposes five core objects: LanguageModel, LanguageModelSession, @Generable, Tool, and DynamicProfile.
— SystemLanguageModel runs locally on iOS/macOS; PrivateCloudComputeLanguageModel runs on Apple's data centers with verifiable privacy; custom models integrate via a unified protocol.
— The model never directly accesses app databases or executes arbitrary code; it only generates parameters, and the app executes Tool.call(arguments:).
— @Generable and @Guide produce type-safe Swift output instead of raw JSON strings.
— DynamicProfile switches instructions, tools, and models based on app state, like switching between brainstorming, planning, and reviewing modes.
— historyTransform lets you compress the session transcript fed to the model without deleting the original history.
— The same session API works with any model; swapping SystemLanguageModel for PrivateCloudComputeLanguageModel doesn't change the call signature.
— Custom models require implementing LanguageModel and LanguageModelExecutor, mapping history messages, generation parameters, streaming output, and errors.
— A command-line tool 'fm' and a Python SDK (pip install apple_fm_sdk) provide the same capabilities outside of Swift.
— SpotlightSearchTool lets a model search content the app has indexed in Spotlight.
Conclusions

The framework's central design keeps execution authority in the app, not the model, which aligns with Apple's privacy stance but also means tool calling is inherently more constrained than in agentic frameworks that let the model run code directly.

The availability of a Python SDK and CLI signals that Apple targets not just app developers but also automation and server-side workflows that need the same model backend.

DynamicProfile plus historyTransform gives developers a structured way to manage context windows and model routing, addressing the practical cost and latency issues of always using the largest cloud model.

The requirement to implement four mappings for custom models (history, generation parameters, streaming, errors) is a concrete, non-trivial integration surface that will likely be the main friction point for teams adopting non-Apple backends.

Concepts & terms
Private Cloud Compute (PCC)
Apple's cloud infrastructure running on Apple-designed chips and data centers, offering more capable model inference with verifiable privacy guarantees: the user's data is not retained or exposed to Apple.
@Generable
A Swift macro that lets a language model return a typed, structured object (like a struct with fields) instead of raw text, replacing manual JSON parsing with type-safe access.
DynamicProfile
A mechanism in LanguageModelSession that reads app state and generates the appropriate session configuration (instructions, model, generation parameters) on the fly, enabling mode switching within a single session.
LanguageModelExecutor
A protocol for implementing a custom language model backend; it converts the unified session request into the backend's API calls and streams text and metadata back through a Channel.
historyTransform
A closure in DynamicProfile that adjusts the session history sent to the model on a per-request basis, allowing developers to compress or filter old context without destroying the original transcript.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗