In this note
1amageek.Portfolio ↗ENGINEERING NOTES
English
APPLE FOUNDATIONMODELS AI AGENT1AMAGEEK / 2026-10-13

Apple FoundationModels — Turn generation into the next action.

Move beyond a paragraph that an app must interpret. SwiftAgent’s Generate connects a FoundationModels-style session to the typed processing the application needs.

01

Ask for the value the application needs.

An extracted field belongs on a screen; a classification belongs in the next step. Define that output boundary rather than parsing arbitrary prose afterward. In Generate<In, Out>, Out conforms to Generable and becomes the step’s structured result.

Structured generation passes the desired type into the call itself. Generate.run supplies generating: Out.self and includeSchemaInPrompt: true to respond. Unlike parsing arbitrary prose afterward, the required structure is explicit at invocation. Whether the values inside it are factually valid is still a different check.

02

Separate generation from judgment.

SwiftAgent treats types as behavioral boundaries, not only convenience. Structured output makes fields accessible, but cannot eliminate incorrect values or unsuitable decisions. The model generates; the consuming app decides whether to accept the result and act.

Free text suits explanations and exploration whose shape is not yet fixed. Typed output makes a boundary explicit when fields feed a screen or another step. The cost is designing that type upfront and checking the selected model integration’s support. A common API does not make every provider’s capabilities or error conditions equivalent.

03

Use a session and keep failure explicit.

Non-streaming Generate.run passes Out.self to LanguageModelSession.respond and returns response.content. Streaming delivers snapshots before constructing the final value. The implementation checks cancellation, bounds retries and throws when generation cannot complete. A partial snapshot is not a completed result.

From responsibility to result.
  1. ApplicationInput
  2. SwiftAgentGenerate<In, Out>
  3. Model integrationLanguageModelSession
  4. Model integrationOut: Generable
  5. ApplicationValidation / action
Implementation excerpt · Generate.run ↗
let response = try await session.respond(
    generating: Out.self,
    includeSchemaInPrompt: true,
    options: options
) {
    prompt
}
return response.content

A visible partial result is not an adopted result.

The streaming path sends Snapshot to the handler, then attempts to construct Out from rawContent. A partial snapshot may not yet be constructible; if no value exists when the stream ends, Generate throws ModelError. An app can use snapshots for preview and the returned run value for committed processing. The library does not automatically defer side effects written inside the handler.

Snapshot
streamHandler(snapshot)
lastContent == nil
ModelError.generationFailed
Read the evidence · Generate.run ↗
04

A shared interface has different operating conditions.

The README baseline is Swift 6.4+, iOS 26+ and macOS 26+. Apple model availability depends on the device and settings and must be checked by the app. An OpenFoundationModels trait enables other providers, whose networking, authentication and data handling can differ. The inspected session tests cover context lifetime, not real-model quality.

The app still needs semantic checks after receiving typed output: valid classifications, acceptable extracted values and authority to act. Keep acceptance in a subsequent Step or the application rather than in the model’s prose. Tests of session-context lifetime and tests of actual model quality also establish different things.

Read the evidence

Source reading date:

An explanation based on reading public design, implementation and test bodies. It is not a report of executing upstream tests or measuring device performance.

SwiftAgent / FoundationModelsExplore the project ↗