Introduction
As Apple pushes further into on-device and private cloud AI with Apple Intelligence, developers are gaining powerful new native tools. The core of this is the Foundation Models framework, a Swift API for working with large language models. Recognizing the need for more advanced, real-world patterns, Apple has released an open-source companion library: the Foundation Models Utilities. This Swift package isn’t another monolithic framework; it’s a focused collection of building blocks for solving the practical challenges of building sophisticated AI apps, like managing growing conversation histories and connecting to the vast ecosystem of open-source models.
What Is Foundation Models Utilities?
The Foundation Models Utilities is an open-source Swift package from Apple, licensed under Apache-2.0, that extends the native Foundation Models framework. It provides a collection of experimental but powerful components for developers building apps with LLMs, focusing on three key areas: connecting to any OpenAI-compatible server, managing the model’s limited context window, and loading task-specific instructions on a just-in-time basis. In essence, it’s a toolkit for solving the practical problems that arise when building long-running, multi-turn conversational AI experiences on Apple platforms and Linux.
The package was released by Apple following WWDC 2026 as part of a commitment to open-source its new AI frameworks. Its primary purpose is to provide patterns and helpers that are not part of the core framework but are essential for building robust applications, such as history compaction and dynamic instruction loading.
Why This Project Matters
For a year after its initial release, Apple’s Foundation Models framework was a closed box: it gave developers unprecedented access to on-device models but limited them to *only* Apple’s model. This was a significant limitation for developers who needed larger models, fine-tuned variants, or simply wanted to use a different architecture. The Foundation Models Utilities package, specifically its `ChatCompletionsLanguageModel` component, shatters that limitation. It officially opens the socket, allowing any `LanguageModelSession` in a Swift app to communicate with virtually any model in the open-source ecosystem, from local servers to cloud APIs.
This matters because it transforms the Foundation Models framework from a niche, Apple-only tool into a universal Swift interface for any LLM. Furthermore, it directly addresses the critical engineering problem of context window management. All LLMs have a finite context window, and as a conversation grows, performance degrades and errors occur. By providing built-in strategies for managing transcript growth, the utilities package saves developers from writing complex and brittle boilerplate code, enabling them to build more robust and long-running AI agents.
Key Features
The utilities package is focused on a few powerful, composable features that solve specific, common problems in LLM application development.
- ChatCompletionsLanguageModel: This is arguably the most significant feature. It’s an adapter that allows the native `LanguageModelSession` to communicate with any server that uses the standard OpenAI chat completions REST API. This means a developer can write a single piece of Swift code and have it work seamlessly with Apple’s on-device model, a local Llama model served via Ollama, or a powerful cloud model like Claude, simply by changing the initialization parameters.
- Skills for Just-in-Time Instructions: LLM performance is highly dependent on the quality of instructions, but keeping a large set of instructions permanently in the context window is inefficient. The `Skills` feature allows developers to define task-specific instructions that are only injected into the model’s context when the model itself decides they are needed by calling a tool. This keeps the context clean and optimizes time-to-first-token.
- History Management Modifiers: A long-running conversation will eventually exceed the model’s context window. The utilities package provides several profile modifiers to handle this gracefully. These strategies can automatically remove or compress older content from the session transcript, preventing errors while preserving the flow of the conversation.
- Observable State Management: The `SkillActivations` type is an observable object that tracks which skills are currently active. Because it conforms to `Observable`, developers can easily use it to drive UI updates in a SwiftUI application, for example, to show the user what capabilities the model is currently using.
How It Compares
The Foundation Models Utilities package is not a direct competitor to large, end-to-end frameworks but rather a set of specialized tools for the Apple ecosystem. Its main point of comparison is the ecosystem of tools around Hugging Face and Python.
| Aspect | Apple Foundation Models + Utilities | Hugging Face Transformers (Python) | LangChain / LlamaIndex (Python) |
|---|---|---|---|
| Primary Language & Ecosystem | Swift (Native Apple platforms) | Python (Cross-platform) | Python (Cross-platform) |
| Core Abstraction | `LanguageModelSession` | `pipeline`, `AutoModel` | `Chain`, `Agent` |
| On-Device Integration | First-class, highly optimized | Possible, but requires manual conversion/optimization | Relies on other libraries for on-device |
| Philosophy | Native, performant building blocks | Massive, comprehensive model hub and toolkit | High-level agentic frameworks |
| Target User | iOS, macOS, visionOS Developers | ML Researchers and Engineers | Application Developers |
vs. Hugging Face Transformers: Hugging Face is the undisputed leader in the AI/ML space, providing a massive hub of models and the Python libraries to use them. The `transformers` library is incredibly comprehensive. Apple’s approach is different; it is focused on providing a native, highly optimized experience specifically for its own platforms. The Foundation Models Utilities package, with its `ChatCompletionsLanguageModel`, acts as a bridge, allowing the native Swift framework to tap into the vast model ecosystem that Hugging Face and others support, but the core development experience remains Swift-native.
vs. LangChain / LlamaIndex: These are high-level Python frameworks for building agentic applications by ‘chaining’ together LLMs with other tools and data sources. Apple’s Foundation Models framework provides similar concepts like `Tool` and `Session`, but at a lower, more fundamental level. The Utilities package adds patterns like `Skills` which are a step toward agent-like behavior, but the overall philosophy is to provide focused building blocks rather than a complete, opinionated agent framework.
Getting Started: Installation
The Foundation Models Utilities package is designed to be integrated into a Swift project using either Xcode or the Swift Package Manager.
Prerequisites
- Xcode for development on Apple platforms.
- A project targeting modern Apple OS versions (e.g., iOS 18, macOS 15).
Installation with Xcode
Integrating the package into an existing Xcode project is straightforward:
- From the Xcode menu, navigate to File > Add Package Dependencies…
- Enter the package URL:
https://github.com/apple/foundation-models-utilities - Follow the prompts to add the package to your project.
Installation with Swift Package Manager
To add the package as a dependency to your own Swift package, modify your Package.swift file:
let package = Package(
name: "YourApp",
dependencies: [
.package(url: "https://github.com/apple/foundation-models-utilities", from: "1.0.0")
],
targets: [
.target(
name: "YourApp",
dependencies: [
.product(name: "FoundationModelsUtilities", package: "foundation-models-utilities")
]
)
]
)How to Use Foundation Models Utilities
The primary use case is to connect to an external model. The `ChatCompletionsLanguageModel` makes this incredibly simple.
First, you import the necessary frameworks. Then, you create an instance of `ChatCompletionsLanguageModel`, providing it with the URL of your model server (e.g., a local Ollama instance). You can also specify the model’s capabilities, such as whether it supports guided generation. Once the model object is created, you can use it in a standard `LanguageModelSession` just as you would with Apple’s native on-device model. This provides a unified interface for interacting with any LLM.
Code Examples
The following examples demonstrate how to use the key components of the utilities package.
Connecting to a Local LLM Server
This snippet shows how to use `ChatCompletionsLanguageModel` to connect to an LLM running on `localhost`. This could be a model served by Ollama, vLLM, or any other OpenAI-compatible server.
import FoundationModels
import FoundationModelsUtilities
// Point to a local server running an open-source model
let model = ChatCompletionsLanguageModel(
name: "llama3-8b",
url: URL(string: "http://localhost:8080/v1")!,
supportsGuidedGeneration: false
)
let session = LanguageModelSession(model: model)
let response = try await session.respond(to: "What are the key features of Swift?")
print(response.content)
Defining and Using a Skill
This example illustrates the `Skills` API. We define a skill for summarizing text that will only be injected into the context when the model needs it. This keeps the initial prompt clean and efficient.
import FoundationModels
import FoundationModelsUtilities
@Skill("summarize")
struct SummarizationSkill {
var instructions: String = "Summarize the provided text into three key bullet points."
}
// In your session management code:
@State private var skillActivations = SkillActivations()
var skills = Skills(activations: $skillActivations) {
SummarizationSkill()
}
// The session can now be initialized with this dynamic skill
let session = LanguageModelSession(instructions: skills, ...)
Real-World Use Cases
- Multi-Platform AI Apps: A developer can build an app that uses Apple’s on-device model for fast, private summarization on the go, but can switch to a larger, more powerful server-side model (via `ChatCompletionsLanguageModel`) for complex reasoning tasks, all using the same `LanguageModelSession` code.
- Long-Running Agentic Apps: A developer creating a personal assistant app can use the history management modifiers to ensure the conversation can run for hours or days without crashing due to an exhausted context window.
- Modular, Tool-Using Agents: An application could have dozens of potential capabilities (e.g., calendar access, web search, image generation). Using the `Skills` API, the instructions for each of these tools only consume tokens when they are actively being considered by the model, making the agent more efficient.
- Prototyping with Open-Source Models: An iOS developer can now rapidly prototype new AI features using the vast library of models on Hugging Face, running them locally via MLX or Ollama and connecting to them with this utility package, long before needing to commit to Apple’s on-device model constraints.
Contributing and Community
As an official Apple open-source project, contributions and feedback are handled through standard channels. The repository is still marked as experimental, indicating that the API may change. For bug reports and issues, Apple directs developers to use the official Apple Developer Forums rather than GitHub Issues. While this is different from typical open-source projects, it centralizes feedback within Apple’s developer ecosystem.
Conclusion
Apple’s Foundation Models Utilities package is a small but strategically significant open-source release. It represents a major step in opening up Apple’s native AI framework to the broader ecosystem of language models, transforming it from a closed-box solution into a universal Swift interface. For developers in the Apple ecosystem, this is a critical toolkit that solves real-world problems around context management and model interoperability.
While still experimental, the patterns it introduces for just-in-time instructions and history compaction are essential for building the next generation of intelligent, long-running applications. It provides a set of focused, powerful building blocks for any Swift developer looking to move beyond simple, stateless LLM calls and create truly dynamic and robust AI experiences.
Resources
- Official foundation-models-utilities GitHub Repository: The source code and official README for the package.
- Official Apple Foundation Models Documentation: The primary documentation for the core framework that these utilities extend.
- Apple Developer Forums: The official channel for reporting issues and providing feedback on the utilities package.
What is the Apple Foundation Models Utilities package?
It is an open-source Swift package from Apple that adds extra features to the core Foundation Models framework. It primarily provides tools for connecting to any OpenAI-compatible LLM server, managing the conversation history to prevent context overflow, and loading instructions dynamically.
Is this a replacement for the main Foundation Models framework?
No, it is a companion library. The utilities package is designed to be used on top of the existing Foundation Models framework, extending its capabilities with experimental and emerging patterns for building with LLMs.
Can I use this to connect to models from Hugging Face or run Llama 3 on my Mac?
Yes. The `ChatCompletionsLanguageModel` utility allows you to connect to any server that exposes an OpenAI-compatible API. You can run a model like Llama 3 locally using a tool like Ollama or MLX, and then use this utility to have your native Swift application communicate with it.
Is this package written in Python or Swift?
The Foundation Models Utilities package is written entirely in Swift. It is designed for developers building applications for Apple’s ecosystem (iOS, macOS, visionOS) and for server-side Swift development on Linux.
What problem do 'Skills' solve?
Skills solve the problem of context pollution and inefficiency. Instead of loading all possible instructions for every task into the model’s limited context window, a Skill allows instructions to be loaded dynamically on a just-in-time basis, only when the model needs them to perform a specific task.
How does the package help with long conversations?
LLMs have a fixed context window, and long conversations can exceed this limit, causing errors. This package provides history modifiers that can automatically compress or remove the oldest parts of the conversation transcript, allowing the session to continue indefinitely without overflowing the context.
What is the license for this project?
The Foundation Models Utilities package is open-source and licensed under the permissive Apache 2.0 license, making it suitable for use in both personal and commercial projects.
