DEV Community

D
D

Posted on

Apple's Foundation Models Framework: A Closer Look

Apple just introduced some powerful new capabilities for developers that let you bring advanced AI features directly into your apps. You might have heard terms like "AI agents" floating around, but let's break down what Apple's new Foundation Models framework means for you, simply and practically.

At its heart, this framework gives your apps access to a large language model (LLM) that runs directly on your users' devices. This is a big deal for a few reasons:

  1. Privacy First: All the data stays on the device. Your users' information remains private, which is a huge win for trust and security.
  2. Works Offline: No internet? No problem! Since the model is on-device, your smart features can work anywhere.
  3. No Extra App Size: It's built into the operating system, so your app won't get bigger.

Let's look at some of the cool things this framework enables:

Getting Structured Answers (Guided Generation)

Normally, when you ask an LLM something, you get back plain text. If you want specific information (like a list of events or details about a place), it's tough to get it consistently formatted. You often end up trying to "trick" the model into giving you JSON or writing messy code to pick out what you need.

Apple's Guided Generation solves this. You can define a Swift data structure (like a struct for a Trip or an Event), and the model will guarantee it generates an instance of that structure. This means you get reliable, ready to use data every single time, making it much easier to integrate AI output into your app's design.

Smoother Streaming (Snapshots)

When an AI generates a long response, it often comes out piece by piece. Developers usually get tiny chunks of text (called "deltas") and have to stitch them together. If that text is supposed to form a complex structure, it gets even harder to show users partial results as they come in.

Instead of raw text chunks, Apple's framework streams snapshots. Imagine you're building a Trip struct. As the model thinks, it sends you partial Trip objects – maybe first the title, then the destination, then the activities start to fill in. This makes showing live, structured AI responses in your UI much smoother and simpler.

Giving Your App "Skills" (Tool Calling)

This is where things get really interesting. Tool Calling allows the AI model to use functions you've written in your app.

Think of it like this: If a user asks your travel app, "What's the weather like in Tokyo?", the LLM itself doesn't "know" the weather. But with tool calling, you can define a "weather tool" (a simple function) that can fetch this information. The LLM understands when it needs this information, "calls" your weather tool, gets the answer, and then uses that answer to give the user a complete, accurate response.

This means your app's AI can:

  • Access real-time data: Like weather, map data, or any other info your app has.
  • Perform actions: Potentially book a trip, send a message, or update a calendar entry (if you define tools for those actions).
  • Reduce "hallucinations": By pulling real data, the AI is less likely to make things up.

Remembering the Conversation (Stateful Sessions)

For an AI to have a natural back and forth, it needs to remember what was said before. Apple's framework uses Stateful Sessions to do this. Every interaction within a session is remembered, so the model understands context. If you ask it to "write another one" after it just wrote a haiku, it knows you mean another haiku.

This session also lets you give the AI "instructions" (like "act as a friendly travel agent") that guide its overall behavior, separate from the user's direct questions. This helps keep the AI on track and makes it safer.

Getting Started

Apple has made it easy to experiment with these features right in Xcode Playgrounds. You can quickly test prompts and see how the AI responds without having to build and run your entire app. For a comprehensive overview and to see these features in action, check out Apple's official WWDC25 session, "Meet Foundation Models" at https://developer.apple.com/videos/play/wwdc2025/286/.

This new framework opens up a world of possibilities for building more intelligent, responsive, and private apps. It's about empowering your app with smart features, all running seamlessly on your users' devices. Dive in and see what you can build!

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.