rusty_foundationmodels
[!WARNING] This repository has been archived and is no longer maintained.
Development has moved to
rs_ai, which contains the latest FoundationModels (and other localai like Phi Silica on Windows and Gemini Nano on Android) support, APIs, fixes, and ongoing work.Please update your dependencies and use
rs_aifor all new projects.
Safe Rust bindings for Apple's FoundationModels on-device AI framework (Apple Intelligence).
Run a local ≈3B-parameter language model entirely on-device — no network requests, no API keys, no data leaving the device.
Requirements
| Requirement | Value |
|---|---|
| macOS | 26 (Tahoe) or later |
| Hardware | Apple Silicon (M1 or later) |
| Setting | Apple Intelligence enabled in System Settings |
| Build tool | Xcode with the macOS 26 SDK |
The crate still compiles and links on unsupported hardware or older macOS; all APIs return Err(Error::Unavailable) at runtime so you can handle the fallback gracefully.
Usage
Add to Cargo.toml:
[]
= "0.1"
Single-shot response
use ;
async
Multi-turn conversation
use Session;
let mut session = with_instructions?;
let r1 = session.respond.await?;
let r2 = session.respond.await?;
println!;
Dynamic profile switching
Swap system instructions mid-session without losing state:
use Session;
let session = with_instructions?;
let poem = session.respond.await?;
session.update_profile?;
let review = session.respond.await?;
Multimodal prompts (image + text)
Pass an image alongside a text prompt for visual reasoning:
use ;
let session = new?;
let screenshot = read?;
let attachment = image;
let analysis = session.respond_with_attachment.await?;
Streaming structured output
Stream JSON fragments as the model fills a typed schema:
use ;
use StreamExt as _;
let session = new?;
let schema = new
.property
.property;
let mut stream = session.stream_structured?;
while let Some = stream.next.await
Streaming
use Session;
use StreamExt as _;
let session = new?;
let mut stream = session.stream?;
while let Some = stream.next.await
println!;
Structured generation
Describe the shape of the output with a Schema and the model returns a value that deserialises into your type:
use ;
use Deserialize;
let session = new?;
let schema = new
.property
.property
.property;
let capital: Capital = session.respond_as.await?;
println!;
Tool calling
Define Rust functions that the model can invoke during generation:
use ;
use Value;
let tools = vec!;
let mut session = with_tools?;
let response = session.respond.await?;
println!;
Generation options
use ;
let opts = GenerationOptions ;
let response = respond_with_options.await?;
Availability checking
use ;
match availability
Running the integration tests
The integration tests require Apple Intelligence to be active. Once you have macOS 26 on Apple Silicon with Apple Intelligence enabled:
How it works
The crate ships a Swift source file (bridge.swift) that is compiled by build.rs at build time using xcrun swiftc. The resulting static library exposes a small set of C-ABI functions that Rust calls through an unsafe extern "C" block. Swift's async/await tasks are bridged to Rust futures using futures_channel oneshot and mpsc channels.
If xcrun is not found or compilation fails (e.g. on non-macOS hosts or without the macOS 26 SDK), the build still succeeds — the Swift bridge is simply skipped and all public APIs return Err(Error::Unavailable) at runtime.
License
Licensed under the Mozilla Public License 2.0.