๐ฏ Objective
Transition from using third-party wrappers to mastering Apple's native Foundation Models framework.
By the end of this week, you will be able to manage model sessions, enforce structured JSON outputs,
and implement tool-calling logic entirely on-device.
๐ Prerequisites
- Xcode 17+ (2026 Release)
- Swift 6.0+ (Strict Concurrency enabled)
- Device with A17 Pro / M1 chip or newer
Daily Breakdown
Day 1
Session Management & Lifecycle
Topic: The LanguageModelSession.
Tasks:
- Configure a session with specific
Configuration (Temperature, Top-P).
- Implement streaming vs. non-streaming responses using
AsyncSequence.
- Handle
on-device-only errors (e.g., model not downloaded or thermal throttling).
Key API: LanguageModelSession.shared, LanguageModelSession.Configuration.
Day 2
Advanced Prompting & System Instructions
Topic: Defining the "On-Device Persona."
Tasks:
- Master
SystemPrompt architecture to minimize token usage (latency reduction).
- Experiment with "Few-Shot" prompting within a local session.
- Evaluate the difference between
user and assistant role-playing in the local buffer.
Day 3
Structured Output with @Generable
Topic: Moving beyond raw strings.
Tasks:
- Use the
@Generable macro to annotate Swift Structs.
- Force the model to return a populated object rather than text.
- Implement validation logic for when the model returns malformed JSON.
Lab: Build a "Travel Itinerary" parser that takes a paragraph and returns a [DayPlan] array.
Day 4
Tool Calling & Function Injection
Topic: Teaching the model to "Do."
Tasks:
- Define a set of
AppIntents as tools for the model.
- Implement the
ToolCalling protocol.
- Handle the hand-off: Model โ Intent Execution โ Result โ Model.
Example: A "Calendar Assistant" where the model calls CreateEventIntent after a chat.
Day 5
Context Windows & Memory Management
Topic: Managing the 32k+ context window efficiently.
Tasks:
- Implement a "Sliding Window" strategy to prevent memory spikes.
- Learn to use
TokenCounter to predict session costs before execution.
- Monitor Unified Memory usage in Instruments during heavy inference.
๐งช
Friday Lab: "The Intentional Agent"
Project: Build a single-view app called "LocalAction".
- Input: A text field for user requests (e.g., "Remind me to call John and set my volume to 50%").
- Logic: The Foundation Model identifies the tasks, uses Tool Calling to find the correct system intents, and executes them.
- Requirement: Must work entirely in Airplane Mode.
๐ Resource Checklist
- Apple Documentation: Interacting with Foundation Models
- WWDC Session: Explore the Foundation Models Framework
- Swift Evolution: Macros and the @Generable pattern
- Apple ML Research: Optimizing Large Language Models for Apple Silicon
Success Metric: You have successfully triggered a local Swift function using a natural language command
processed via LanguageModelSession without hitting a network endpoint.