@rudrank: FoundationModelsKit 2.0.0 is out! I pulled the reusable bits back out of Foundation Lab after working with OS 27, and m…
Summary
FoundationModelsKit 2.0.0 is released as a standalone Swift package with runtime checks, schema helpers, token counts, conversation history, and built-in tools for building apps and CLIs with Apple's Foundation Models framework.
View Cached Full Text
Cached at: 07/03/26, 12:36 PM
FoundationModelsKit 2.0.0 is out!
I pulled the reusable bits back out of Foundation Lab after working with OS 27, and made the Kit a standalone package again
Runtime checks, schema helpers, token counts, conversation history, and the built-in tools are now easier to use from your own apps and CLIs!
rryam/FoundationModelsKit
Source: https://github.com/rryam/FoundationModelsKit
FoundationModelsKit
Utilities for shipping apps and tools with Apple’s Foundation Models framework.
FoundationModelsKit helps apps, CLIs, benchmarks, and developer tools use Foundation Models with runtime checks, Codable request and result types, schema conversion, token accounting, context recovery, and concrete tools.
It is designed to complement Apple’s Foundation Models framework and Apple’s Foundation Models Utilities. Use Apple’s utilities for OpenAI-compatible LanguageModel adapters and extensions to FoundationModels itself. Use FoundationModelsKit when you need app, CLI, or benchmark support around on-device and Private Cloud Compute execution.
Products
The package exposes two products:
FoundationModelsKit: runtime inspection, capability use cases, model configuration, schemas, token accounting, transcript utilities, error projection, and conversation state.FoundationModelsTools:Toolimplementations for Apple platform capabilities and web services. This product re-exportsFoundationModelsKit.
What Is Included
Runtime Readiness
Inspect whether Foundation Models can actually run in the current process.
- On-device availability
- Private Cloud Compute availability
- PCC entitlement status
- PCC quota state
- Supported language metadata
- Codable status models for logs, CLIs, and benchmarks
import FoundationModelsKit
let inspector = FoundationModelsRuntimeInspector()
let onDevice = inspector.status(for: .onDevice)
let pcc = inspector.status(for: .privateCloudCompute)
if pcc.isRunnableInCurrentProcess {
print("PCC is available and authorized.")
} else {
print("PCC unavailable: \(pcc.reason?.rawValue ?? "unknown")")
}
Generation Use Cases
Wrap Foundation Models calls in request and result types that are easy to test, serialize, and record.
import FoundationModelsKit
let request = FoundationModelTextGenerationRequest(
prompt: "Explain actor isolation in one paragraph.",
systemPrompt: "Answer for a Swift developer.",
generationOptions: FoundationModelGenerationOptions(
temperature: 0.3,
maximumResponseTokens: 300
),
context: FoundationModelInvocationContext(source: .cli)
)
let result = try await FoundationModelTextGenerationUseCase().execute(request)
print(result.content)
Available use cases include:
FoundationModelTextGenerationUseCaseFoundationModelStreamingTextGenerationUseCaseFoundationModelStructuredGenerationUseCaseFoundationModelDynamicSchemaGenerationUseCaseFoundationModelAvailabilityUseCaseFoundationModelRuntimeInspectionUseCaseFoundationModelQuotaUsageInspectionUseCaseFoundationModelSupportedLanguagesUseCase
Model Configuration and Adapters
FoundationModelsKit supports Apple’s on-device Foundation Models runtime and Private Cloud Compute runtime where available. It also supports Apple Foundation Models adapter files through SystemLanguageModel.Adapter.
import FoundationModelsKit
let adapterURL = URL(fileURLWithPath: "/path/to/model.fmadapter")
let request = FoundationModelTextGenerationRequest(
prompt: "Summarize this document.",
adapterURL: adapterURL,
context: FoundationModelInvocationContext(source: .app)
)
let result = try await FoundationModelTextGenerationUseCase().execute(request)
OpenAI-compatible hosted models are intentionally not duplicated here. Use Apple’s Foundation Models Utilities for that adapter, then use FoundationModelsKit for runtime status, schema conversion, token accounting, and run metadata.
Schema Utilities
Decode and validate a supported JSON Schema subset, then convert it into a Foundation Models GenerationSchema.
import FoundationModelsKit
let schema = try JSONDecoder().decode(
FoundationModelsJSONSchema.self,
from: Data("""
{
"title": "BookRecommendation",
"type": "object",
"properties": {
"title": { "type": "string" },
"reason": { "type": "string" }
},
"required": ["title", "reason"],
"additionalProperties": false
}
""".utf8)
)
try schema.validate()
let generationSchema = try schema.generationSchema(rootName: "BookRecommendation")
The schema utilities are built for CLIs, benchmarks, and user-authored schema files. They report exact JSON pointer-style paths for unsupported keywords and invalid declarations.
Token Accounting and Context Budgets
Use transcript token utilities to estimate context size, inspect model token usage, and trim transcript entries before context overflow becomes a user-visible failure.
import FoundationModels
import FoundationModelsKit
let transcript = Transcript(entries: [
.prompt(Transcript.Prompt(segments: [
.text(Transcript.TextSegment(content: "Explain Foundation Models."))
]))
])
let estimate = transcript.safeEstimatedTokenCount
let trimmed = transcript.entriesWithinTokenBudget(4_096)
FoundationModelsKit also normalizes model-reported usage through ModelTokenUsage, including cached input tokens and reasoning output tokens where the framework exposes them.
Conversation Engine
FoundationModelConversationEngine is a small runtime for app and CLI chat surfaces. It handles:
- Prompt validation
- Streaming and one-shot responses
- Cancellation
- Runtime switching
- Reasoning options for PCC
- Adapter-safe defaults
- Sliding-window context trimming
- Summary-based context-overflow recovery
- Token usage snapshots
import FoundationModelsKit
let engine = FoundationModelConversationEngine(
configuration: FoundationModelConversationConfiguration(
baseInstructions: "You are a concise Swift assistant.",
summaryInstructions: "Summarize the conversation for continuation.",
summaryPromptPreamble: "Create a compact continuation summary.",
conversationUserLabel: "User:",
conversationAssistantLabel: "Assistant:",
continuationNote: "Continue naturally from the summary.",
enableSlidingWindow: true
)
)
let answer = try await engine.sendMessage("What does Sendable protect?")
print(answer)
Error Projection
Foundation Models errors change across SDK generations. FoundationModelErrorProjection maps framework errors into stable categories for logs, CLIs, UI, and benchmark reports.
do {
_ = try await FoundationModelTextGenerationUseCase().execute(request)
} catch {
if let projection = FoundationModelErrorProjection.project(error) {
print(projection.category.rawValue)
}
}
Tools
FoundationModelsTools provides tools for real app capabilities.
import FoundationModels
import FoundationModelsTools
let session = LanguageModelSession(
tools: [
WeatherTool(),
CalendarTool(),
RemindersTool()
]
)
let response = try await session.respond(
to: "Check the weather and help me plan tomorrow morning."
)
Available tools:
WeatherTool: current weather through OpenMeteoWebTool: Exa-backed web searchWebMetadataTool: page title, description, and image metadataContactsTool: search, read, and create contactsCalendarTool: create, query, read, and update eventsRemindersTool: create, query, update, complete, and delete remindersLocationTool: current location, geocoding, reverse geocoding, place search, and distanceHealthTool: authorized HealthKit readsMusicTool: Apple Music search and playback controls
The tools preserve platform permission boundaries. They do not fabricate unavailable Health, Contacts, Calendar, Location, Music, or Reminders data.
Requirements
- macOS 26.0+
- iOS 26.0+
- Swift 6.2+
- Xcode 26.0+
Private Cloud Compute APIs and some reasoning controls require newer SDK/runtime availability and are guarded in code.
Installation
Add the package dependency:
dependencies: [
.package(
url: "https://github.com/rryam/FoundationModelsKit.git",
branch: "main"
)
]
Use the core product, the tools product, or both:
.target(
name: "YourTarget",
dependencies: [
.product(
name: "FoundationModelsKit",
package: "FoundationModelsKit"
),
.product(
name: "FoundationModelsTools",
package: "FoundationModelsKit"
)
]
)
Privacy and Keys
Some tools require platform permissions and usage descriptions:
- Calendar:
NSCalendarsUsageDescription - Contacts:
NSContactsUsageDescription - Health:
NSHealthShareUsageDescription - Location:
NSLocationWhenInUseUsageDescription - Music:
NSAppleMusicUsageDescription - Reminders:
NSRemindersUsageDescription
WebTool uses Exa and requires an API key. Do not ship API keys inside a client app bundle. Prefer a server endpoint that stores the key in an environment variable and forwards only the safe request shape from your app.
Relationship to Apple’s Utilities
FoundationModelsKit is intentionally complementary to Apple’s Foundation Models Utilities.
Use Apple’s utilities for:
- OpenAI-compatible
LanguageModeladapters - Protocol-native
DynamicProfilehelpers - Generic model-facing skills if Apple keeps them in that package
Use FoundationModelsKit for:
- Runtime and PCC readiness checks
- Codable request and result types
- Codable execution metadata
- Error projection
- JSON Schema validation and conversion
- Token accounting
- Conversation recovery
- Concrete Apple platform tools
- App, CLI, and benchmark workflows
Validation
Run the package checks locally:
swift build
swift test
License
See LICENSE.
Similar Articles
@soriano_tech: Yes, we have a Foundation Models CLI #WWDC26 - Update your Mac - Download Xcode 27 (beta) - run `fm` in Terminal That's…
Announcement of a Foundation Models CLI, available by updating Mac and downloading Xcode 27 beta, then running 'fm' in Terminal.
@jundotkim: I just shipped oMLX v0.4.0, the first official release with the new native Swift macOS app. https://github.com/jundot/o…
oMLX v0.4.0 ships a native Swift macOS app with redesigned onboarding, settings UI, Hugging Face cache discovery, and improved model management for running local AI on Macs.
Liquid AI Releases Liquid Foundation Models 2.5 230M (3 minute read)
Liquid AI releases LFM2.5-230M, a lightweight foundation model that runs on devices from cloud GPUs to CPUs and Raspberry Pi, with strong performance on tool use and data extraction tasks.
@bqbrady: This article covers six different types of foundation models. In a lot of ways, these domains use the same building blo…
A tweet referencing an article that covers six different types of foundation models, noting they use similar building blocks remixed for different task signatures and suggesting future unification.
@seclink: https://x.com/seclink/status/2064906981639430624
At WWDC26, Apple announced multiple open-source SDKs and free trial capabilities for developers, including the open-sourcing of the Foundation Models framework, Game Porting Toolkit 4, Xcode 27 intelligent agent, free computing power from Private Cloud Compute, Core AI framework, and the new generation App Intents framework.