foundation-models-ref

Documents Apple Foundation Models APIs including LanguageModelSession, @Generable, Tool protocol, and WWDC 2025 code samples for iOS 26+ and visionOS 26+ development.

1.1k|81|Updated Nov 30, 2025
One-click install
npx skills add https://github.com/CharlesWiltgen/Axiom --skill foundation-models-ref
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: foundation-models-ref
Source: https://github.com/CharlesWiltgen/Axiom/tree/main/plugins/axiom/skills/foundation-models-ref
Command: npx skills add https://github.com/CharlesWiltgen/Axiom --skill foundation-models-ref

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides a complete reference to Apple's Foundation Models framework, clarifying its unique APIs, capabilities, and best practices. It helps developers implement on-device AI features, understand structured output, integrate tools, and manage streaming effectively.

Core Features & Use Cases

  • Complete API Reference: Detailed guide covering LanguageModelSession, @Generable, @Guide, Tool protocol, streaming, and dynamic schemas with all WWDC 2025 code examples.
  • Performance & Error Handling: Strategies for prewarming sessions, managing context window limits, and handling generation errors like exceededContextWindowSize and guardrailViolation.
  • Tool Protocol Integration: Explains how to enable the model to autonomously execute custom code for external data (e.g., WeatherKit, MapKit, Contacts).
  • Use Case: When you need to implement structured output from the on-device model, use this skill to understand how the @Generable macro works with constrained decoding to guarantee type-safe Swift objects.

Quick Start

To create a basic LanguageModelSession, import FoundationModels and initialize with let session = LanguageModelSession().

Frequently Asked Questions about foundation-models-ref

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement on-device AI features using Apple's Foundation Models framework?

On-device Foundation Models let you run AI directly on iOS, macOS, iPadOS, and visionOS without server calls. Start by importing FoundationModels and creating a LanguageModelSession to access the 3B-parameter model with 4096-token context, full offline capability, and privacy guarantees built in.

What is the @Generable macro and how does it enable structured output?

The @Generable macro uses constrained decoding to guarantee type-safe Swift objects from the model. It enforces schema validation during generation, eliminating JSON parsing errors and ensuring the model output matches your expected data structure exactly.

Can I use Foundation Models to call external APIs or custom code during generation?

Yes, the Tool protocol lets the model autonomously execute custom code during generation. You define tools that access WeatherKit, MapKit, Contacts, or your own APIs; the model decides when to invoke them to answer user queries without leaving the device.

What are the limitations and optimization notes for on-device Foundation Models?

Foundation Models excel at text summarization, classification, and entity detection but aren't optimized for world knowledge queries, complex multi-step reasoning, mathematical computation, or translation. Handle context limits with prewarming and error handling for exceededContextWindowSize and guardrailViolation.

How do I stream model output and manage long-running generations?

Stream responses token-by-token using LanguageModelSession's streaming APIs to provide real-time feedback and manage context windows effectively. Prewarm sessions before critical operations and implement error handling for generation failures specific to on-device constraints.

Does Foundation Models support prompts and instructions separately, and what's the difference?

Yes, Foundation Models distinguishes between prompts (user input) and instructions (system guidance). Use instructions to shape model behavior and context; prompts carry the actual user query. This separation enables consistent, controllable generations across use cases like tagging, extraction, and content generation.