@mmerterden/multi-agent-pipeline 20.7.0 → 20.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/LICENSE +0 -10
- package/docs/facts.json +1 -1
- package/manifest.json +266 -267
- package/package.json +2 -2
- package/pipeline/scripts/_notices.mjs +1 -1
- package/pipeline/skills/.skill-manifest.json +68 -68
- package/pipeline/skills/shared/README.md +70 -70
- package/pipeline/skills/shared/external/alarmkit/SKILL.md +373 -381
- package/pipeline/skills/shared/external/alarmkit/evals/evals.json +23 -18
- package/pipeline/skills/shared/external/alarmkit/references/alarmkit-patterns.md +328 -378
- package/pipeline/skills/shared/external/app-clips/SKILL.md +260 -160
- package/pipeline/skills/shared/external/app-clips/evals/evals.json +27 -27
- package/pipeline/skills/shared/external/app-clips/references/data-handoff-notifications-location.md +150 -83
- package/pipeline/skills/shared/external/app-clips/references/routing-and-experiences.md +135 -83
- package/pipeline/skills/shared/external/app-clips/references/size-capabilities-and-promotion.md +143 -85
- package/pipeline/skills/shared/external/app-intents/SKILL.md +302 -304
- package/pipeline/skills/shared/external/app-intents/evals/evals.json +21 -21
- package/pipeline/skills/shared/external/app-intents/references/appintents-advanced.md +594 -894
- package/pipeline/skills/shared/external/app-store-optimization/SKILL.md +339 -277
- package/pipeline/skills/shared/external/app-store-optimization/evals/evals.json +27 -23
- package/pipeline/skills/shared/external/app-store-optimization/references/keyword-research-methodology.md +105 -122
- package/pipeline/skills/shared/external/app-store-optimization/references/product-page-variants.md +143 -166
- package/pipeline/skills/shared/external/app-store-review/SKILL.md +307 -326
- package/pipeline/skills/shared/external/app-store-review/evals/evals.json +21 -21
- package/pipeline/skills/shared/external/app-store-review/references/privacy-manifest.md +105 -67
- package/pipeline/skills/shared/external/app-store-review/references/review-checklists.md +114 -101
- package/pipeline/skills/shared/external/apple-on-device-ai/SKILL.md +333 -360
- package/pipeline/skills/shared/external/apple-on-device-ai/evals/evals.json +24 -27
- package/pipeline/skills/shared/external/apple-on-device-ai/references/coreml-conversion.md +215 -322
- package/pipeline/skills/shared/external/apple-on-device-ai/references/coreml-optimization.md +161 -256
- package/pipeline/skills/shared/external/apple-on-device-ai/references/foundation-models.md +277 -387
- package/pipeline/skills/shared/external/apple-on-device-ai/references/mlx-swift.md +196 -210
- package/pipeline/skills/shared/external/authentication/SKILL.md +265 -381
- package/pipeline/skills/shared/external/authentication/evals/evals.json +25 -25
- package/pipeline/skills/shared/external/authentication/references/keychain-biometric.md +133 -178
- package/pipeline/skills/shared/external/authentication/references/passkeys.md +111 -147
- package/pipeline/skills/shared/external/avkit/SKILL.md +267 -364
- package/pipeline/skills/shared/external/avkit/evals/evals.json +26 -26
- package/pipeline/skills/shared/external/avkit/references/avkit-patterns.md +375 -493
- package/pipeline/skills/shared/external/background-processing/SKILL.md +270 -382
- package/pipeline/skills/shared/external/background-processing/evals/evals.json +22 -22
- package/pipeline/skills/shared/external/background-processing/references/background-task-patterns.md +169 -317
- package/pipeline/skills/shared/external/callkit-voip/SKILL.md +290 -371
- package/pipeline/skills/shared/external/callkit-voip/evals/evals.json +24 -24
- package/pipeline/skills/shared/external/callkit-voip/references/callkit-patterns.md +175 -343
- package/pipeline/skills/shared/external/cloudkit-sync/SKILL.md +292 -381
- package/pipeline/skills/shared/external/cloudkit-sync/evals/evals.json +33 -30
- package/pipeline/skills/shared/external/cloudkit-sync/references/cloudkit-patterns.md +227 -355
- package/pipeline/skills/shared/external/contacts-framework/SKILL.md +197 -346
- package/pipeline/skills/shared/external/contacts-framework/evals/evals.json +19 -21
- package/pipeline/skills/shared/external/contacts-framework/references/contacts-patterns.md +169 -308
- package/pipeline/skills/shared/external/core-bluetooth/SKILL.md +226 -376
- package/pipeline/skills/shared/external/core-bluetooth/evals/evals.json +25 -22
- package/pipeline/skills/shared/external/core-bluetooth/references/ble-patterns.md +257 -337
- package/pipeline/skills/shared/external/core-data/SKILL.md +292 -368
- package/pipeline/skills/shared/external/core-data/evals/evals.json +30 -27
- package/pipeline/skills/shared/external/core-motion/SKILL.md +235 -324
- package/pipeline/skills/shared/external/core-motion/evals/evals.json +31 -27
- package/pipeline/skills/shared/external/core-motion/references/motion-patterns.md +210 -310
- package/pipeline/skills/shared/external/core-nfc/SKILL.md +292 -366
- package/pipeline/skills/shared/external/core-nfc/evals/evals.json +22 -24
- package/pipeline/skills/shared/external/core-nfc/references/nfc-patterns.md +233 -329
- package/pipeline/skills/shared/external/coreml/SKILL.md +323 -367
- package/pipeline/skills/shared/external/coreml/evals/evals.json +24 -21
- package/pipeline/skills/shared/external/coreml/references/coreml-swift-integration.md +562 -565
- package/pipeline/skills/shared/external/cryptokit/SKILL.md +253 -394
- package/pipeline/skills/shared/external/cryptokit/evals/evals.json +20 -18
- package/pipeline/skills/shared/external/cryptokit/references/cryptokit-patterns.md +299 -488
- package/pipeline/skills/shared/external/debugging-instruments/SKILL.md +270 -323
- package/pipeline/skills/shared/external/debugging-instruments/evals/evals.json +27 -30
- package/pipeline/skills/shared/external/debugging-instruments/references/instruments-guide.md +167 -315
- package/pipeline/skills/shared/external/debugging-instruments/references/lldb-patterns.md +140 -193
- package/pipeline/skills/shared/external/device-integrity/SKILL.md +230 -353
- package/pipeline/skills/shared/external/device-integrity/evals/evals.json +25 -21
- package/pipeline/skills/shared/external/device-integrity/references/device-integrity-patterns.md +159 -197
- package/pipeline/skills/shared/external/energykit/SKILL.md +225 -392
- package/pipeline/skills/shared/external/energykit/evals/evals.json +29 -28
- package/pipeline/skills/shared/external/energykit/references/energykit-patterns.md +174 -470
- package/pipeline/skills/shared/external/eventkit-calendar/SKILL.md +261 -383
- package/pipeline/skills/shared/external/eventkit-calendar/evals/evals.json +25 -22
- package/pipeline/skills/shared/external/eventkit-calendar/references/eventkit-patterns.md +165 -268
- package/pipeline/skills/shared/external/healthkit/SKILL.md +252 -303
- package/pipeline/skills/shared/external/healthkit/evals/evals.json +24 -23
- package/pipeline/skills/shared/external/healthkit/references/healthkit-patterns.md +369 -523
- package/pipeline/skills/shared/external/homekit-matter/SKILL.md +233 -348
- package/pipeline/skills/shared/external/homekit-matter/evals/evals.json +27 -22
- package/pipeline/skills/shared/external/homekit-matter/references/matter-commissioning.md +199 -305
- package/pipeline/skills/shared/external/ios-accessibility/SKILL.md +368 -340
- package/pipeline/skills/shared/external/ios-accessibility/evals/evals.json +28 -27
- package/pipeline/skills/shared/external/ios-accessibility/references/a11y-patterns.md +314 -260
- package/pipeline/skills/shared/external/ios-accessibility/references/media-accessibility.md +97 -67
- package/pipeline/skills/shared/external/ios-accessibility/references/nutrition-labels.md +165 -101
- package/pipeline/skills/shared/external/ios-localization/SKILL.md +258 -371
- package/pipeline/skills/shared/external/ios-localization/evals/evals.json +23 -23
- package/pipeline/skills/shared/external/ios-localization/references/formatstyle-locale.md +283 -491
- package/pipeline/skills/shared/external/ios-localization/references/string-catalogs.md +313 -440
- package/pipeline/skills/shared/external/ios-networking/SKILL.md +265 -341
- package/pipeline/skills/shared/external/ios-networking/evals/evals.json +24 -24
- package/pipeline/skills/shared/external/ios-networking/references/background-websocket.md +425 -652
- package/pipeline/skills/shared/external/ios-networking/references/file-storage-patterns.md +143 -285
- package/pipeline/skills/shared/external/ios-networking/references/lightweight-clients.md +93 -53
- package/pipeline/skills/shared/external/ios-networking/references/network-framework.md +231 -456
- package/pipeline/skills/shared/external/ios-networking/references/urlsession-patterns.md +517 -784
- package/pipeline/skills/shared/external/ios-simulator/SKILL.md +265 -393
- package/pipeline/skills/shared/external/ios-simulator/evals/evals.json +21 -21
- package/pipeline/skills/shared/external/ios-simulator/references/simctl-commands.md +177 -270
- package/pipeline/skills/shared/external/live-activities/SKILL.md +318 -360
- package/pipeline/skills/shared/external/live-activities/evals/evals.json +21 -21
- package/pipeline/skills/shared/external/live-activities/references/activitykit-patterns.md +478 -710
- package/pipeline/skills/shared/external/mapkit-location/SKILL.md +295 -267
- package/pipeline/skills/shared/external/mapkit-location/evals/evals.json +28 -24
- package/pipeline/skills/shared/external/mapkit-location/references/mapkit-corelocation-patterns.md +378 -532
- package/pipeline/skills/shared/external/mapkit-location/references/mapkit-patterns.md +397 -499
- package/pipeline/skills/shared/external/metrickit-diagnostics/SKILL.md +165 -348
- package/pipeline/skills/shared/external/metrickit-diagnostics/evals/evals.json +26 -23
- package/pipeline/skills/shared/external/metrickit-diagnostics/references/metrickit-patterns.md +123 -130
- package/pipeline/skills/shared/external/musickit-audio/SKILL.md +189 -315
- package/pipeline/skills/shared/external/musickit-audio/evals/evals.json +22 -21
- package/pipeline/skills/shared/external/musickit-audio/references/musickit-patterns.md +181 -270
- package/pipeline/skills/shared/external/natural-language/SKILL.md +188 -340
- package/pipeline/skills/shared/external/natural-language/evals/evals.json +21 -21
- package/pipeline/skills/shared/external/natural-language/references/translation-patterns.md +171 -225
- package/pipeline/skills/shared/external/passkit-wallet/SKILL.md +258 -392
- package/pipeline/skills/shared/external/passkit-wallet/evals/evals.json +30 -29
- package/pipeline/skills/shared/external/passkit-wallet/references/wallet-passes.md +164 -231
- package/pipeline/skills/shared/external/pdfkit/SKILL.md +312 -344
- package/pipeline/skills/shared/external/pdfkit/evals/evals.json +19 -19
- package/pipeline/skills/shared/external/pdfkit/references/pdfkit-patterns.md +413 -624
- package/pipeline/skills/shared/external/pencilkit-drawing/SKILL.md +242 -358
- package/pipeline/skills/shared/external/pencilkit-drawing/evals/evals.json +25 -21
- package/pipeline/skills/shared/external/pencilkit-drawing/references/pencilkit-patterns.md +161 -226
- package/pipeline/skills/shared/external/permissionkit/SKILL.md +282 -400
- package/pipeline/skills/shared/external/permissionkit/evals/evals.json +27 -30
- package/pipeline/skills/shared/external/permissionkit/references/permissionkit-patterns.md +237 -350
- package/pipeline/skills/shared/external/photos-camera-media/SKILL.md +276 -325
- package/pipeline/skills/shared/external/photos-camera-media/references/av-playback.md +299 -545
- package/pipeline/skills/shared/external/photos-camera-media/references/camera-capture.md +344 -588
- package/pipeline/skills/shared/external/photos-camera-media/references/image-loading-caching.md +316 -660
- package/pipeline/skills/shared/external/photos-camera-media/references/photokit-patterns.md +270 -416
- package/pipeline/skills/shared/external/push-notifications/SKILL.md +312 -340
- package/pipeline/skills/shared/external/push-notifications/evals/evals.json +27 -26
- package/pipeline/skills/shared/external/push-notifications/references/notification-patterns.md +328 -485
- package/pipeline/skills/shared/external/push-notifications/references/rich-notifications.md +327 -560
- package/pipeline/skills/shared/external/realitykit-ar/SKILL.md +218 -410
- package/pipeline/skills/shared/external/realitykit-ar/evals/evals.json +24 -27
- package/pipeline/skills/shared/external/realitykit-ar/references/realitykit-patterns.md +221 -348
- package/pipeline/skills/shared/external/shareplay-activities/SKILL.md +222 -393
- package/pipeline/skills/shared/external/shareplay-activities/evals/evals.json +23 -24
- package/pipeline/skills/shared/external/shareplay-activities/references/shareplay-patterns.md +280 -420
- package/pipeline/skills/shared/external/speech-recognition/SKILL.md +217 -421
- package/pipeline/skills/shared/external/speech-recognition/evals/evals.json +23 -26
- package/pipeline/skills/shared/external/speech-recognition/references/speechanalyzer-patterns.md +133 -125
- package/pipeline/skills/shared/external/storekit/SKILL.md +228 -204
- package/pipeline/skills/shared/external/storekit/evals/evals.json +27 -24
- package/pipeline/skills/shared/external/storekit/references/app-review-guidelines.md +98 -109
- package/pipeline/skills/shared/external/storekit/references/core-patterns.md +298 -242
- package/pipeline/skills/shared/external/storekit/references/storekit-advanced.md +356 -649
- package/pipeline/skills/shared/external/swift-api-design-guidelines/SKILL.md +274 -399
- package/pipeline/skills/shared/external/swift-api-design-guidelines/evals/evals.json +22 -24
- package/pipeline/skills/shared/external/swift-api-design-guidelines/references/argument-labels-and-parameters.md +107 -108
- package/pipeline/skills/shared/external/swift-api-design-guidelines/references/conventions-and-special-rules.md +93 -165
- package/pipeline/skills/shared/external/swift-api-design-guidelines/references/naming-and-clarity.md +99 -137
- package/pipeline/skills/shared/external/swift-api-design-guidelines/references/side-effects-and-mutating-pairs.md +77 -120
- package/pipeline/skills/shared/external/swift-architecture/SKILL.md +334 -350
- package/pipeline/skills/shared/external/swift-architecture/evals/evals.json +22 -22
- package/pipeline/skills/shared/external/swift-charts/SKILL.md +208 -394
- package/pipeline/skills/shared/external/swift-charts/evals/evals.json +27 -30
- package/pipeline/skills/shared/external/swift-charts/references/charts-patterns.md +351 -762
- package/pipeline/skills/shared/external/swift-codable/SKILL.md +339 -343
- package/pipeline/skills/shared/external/swift-codable/evals/evals.json +20 -20
- package/pipeline/skills/shared/external/swift-concurrency/SKILL.md +303 -351
- package/pipeline/skills/shared/external/swift-concurrency/evals/evals.json +27 -24
- package/pipeline/skills/shared/external/swift-concurrency/references/approachable-concurrency.md +65 -80
- package/pipeline/skills/shared/external/swift-concurrency/references/async-algorithms.md +48 -84
- package/pipeline/skills/shared/external/swift-concurrency/references/bridging-interop.md +134 -79
- package/pipeline/skills/shared/external/swift-concurrency/references/concurrency-patterns.md +145 -167
- package/pipeline/skills/shared/external/swift-concurrency/references/diagnostics.md +62 -50
- package/pipeline/skills/shared/external/swift-concurrency/references/swiftui-concurrency.md +92 -121
- package/pipeline/skills/shared/external/swift-concurrency/references/synchronization-primitives.md +177 -241
- package/pipeline/skills/shared/external/swift-formatstyle/SKILL.md +258 -234
- package/pipeline/skills/shared/external/swift-language/SKILL.md +342 -382
- package/pipeline/skills/shared/external/swift-language/evals/evals.json +24 -27
- package/pipeline/skills/shared/external/swift-language/references/swift-attributes-interop.md +79 -56
- package/pipeline/skills/shared/external/swift-language/references/swift-patterns-extended.md +297 -340
- package/pipeline/skills/shared/external/swift-security/SKILL.md +180 -161
- package/pipeline/skills/shared/external/swift-security/evals/evals.json +25 -25
- package/pipeline/skills/shared/external/swift-security/references/biometric-authentication.md +314 -469
- package/pipeline/skills/shared/external/swift-security/references/certificate-trust.md +408 -476
- package/pipeline/skills/shared/external/swift-security/references/common-anti-patterns.md +260 -530
- package/pipeline/skills/shared/external/swift-security/references/compliance-owasp-mapping.md +270 -477
- package/pipeline/skills/shared/external/swift-security/references/credential-storage-patterns.md +573 -571
- package/pipeline/skills/shared/external/swift-security/references/cryptokit-public-key.md +370 -441
- package/pipeline/skills/shared/external/swift-security/references/cryptokit-symmetric.md +332 -433
- package/pipeline/skills/shared/external/swift-security/references/keychain-access-control.md +346 -468
- package/pipeline/skills/shared/external/swift-security/references/keychain-fundamentals.md +352 -472
- package/pipeline/skills/shared/external/swift-security/references/keychain-item-classes.md +431 -432
- package/pipeline/skills/shared/external/swift-security/references/keychain-sharing.md +328 -425
- package/pipeline/skills/shared/external/swift-security/references/migration-legacy-stores.md +341 -579
- package/pipeline/skills/shared/external/swift-security/references/secure-enclave.md +396 -457
- package/pipeline/skills/shared/external/swift-security/references/testing-security-code.md +354 -614
- package/pipeline/skills/shared/external/swift-testing/SKILL.md +188 -175
- package/pipeline/skills/shared/external/swift-testing/evals/evals.json +26 -24
- package/pipeline/skills/shared/external/swift-testing/references/testing-advanced.md +80 -84
- package/pipeline/skills/shared/external/swift-testing/references/testing-patterns.md +317 -433
- package/pipeline/skills/shared/external/swiftdata/SKILL.md +392 -256
- package/pipeline/skills/shared/external/swiftdata/evals/evals.json +24 -24
- package/pipeline/skills/shared/external/swiftdata/references/core-data-coexistence.md +206 -402
- package/pipeline/skills/shared/external/swiftdata/references/indexing.md +59 -52
- package/pipeline/skills/shared/external/swiftdata/references/predicate-pitfalls.md +57 -33
- package/pipeline/skills/shared/external/swiftdata/references/swiftdata-advanced.md +354 -747
- package/pipeline/skills/shared/external/swiftdata/references/swiftdata-queries.md +300 -508
- package/pipeline/skills/shared/external/swiftlint/SKILL.md +175 -226
- package/pipeline/skills/shared/external/swiftlint/references/adoption-and-configuration.md +141 -208
- package/pipeline/skills/shared/external/swiftlint/references/custom-rules-and-analyze.md +100 -109
- package/pipeline/skills/shared/external/swiftlint/references/plugins-run-scripts-and-integrations.md +159 -179
- package/pipeline/skills/shared/external/swiftlint/references/rule-reference.md +383 -18
- package/pipeline/skills/shared/external/swiftlint/references/rules-suppressions-and-baselines.md +143 -229
- package/pipeline/skills/shared/external/swiftui-animation/SKILL.md +283 -366
- package/pipeline/skills/shared/external/swiftui-animation/references/animation-advanced.md +396 -608
- package/pipeline/skills/shared/external/swiftui-animation/references/core-animation-bridge.md +336 -385
- package/pipeline/skills/shared/external/swiftui-gestures/SKILL.md +239 -349
- package/pipeline/skills/shared/external/swiftui-gestures/references/gesture-patterns.md +228 -310
- package/pipeline/skills/shared/external/swiftui-layout-components/SKILL.md +260 -249
- package/pipeline/skills/shared/external/swiftui-layout-components/references/form.md +92 -74
- package/pipeline/skills/shared/external/swiftui-layout-components/references/grids.md +112 -177
- package/pipeline/skills/shared/external/swiftui-layout-components/references/list.md +61 -64
- package/pipeline/skills/shared/external/swiftui-layout-components/references/scrollview.md +94 -134
- package/pipeline/skills/shared/external/swiftui-liquid-glass/SKILL.md +193 -225
- package/pipeline/skills/shared/external/swiftui-liquid-glass/references/liquid-glass.md +173 -327
- package/pipeline/skills/shared/external/swiftui-navigation/SKILL.md +193 -168
- package/pipeline/skills/shared/external/swiftui-navigation/references/deeplinks.md +127 -150
- package/pipeline/skills/shared/external/swiftui-navigation/references/navigationstack.md +132 -133
- package/pipeline/skills/shared/external/swiftui-navigation/references/sheets.md +152 -117
- package/pipeline/skills/shared/external/swiftui-navigation/references/tabview.md +106 -140
- package/pipeline/skills/shared/external/swiftui-patterns/SKILL.md +316 -252
- package/pipeline/skills/shared/external/swiftui-patterns/references/architecture-patterns.md +341 -332
- package/pipeline/skills/shared/external/swiftui-patterns/references/deprecated-migration.md +547 -854
- package/pipeline/skills/shared/external/swiftui-patterns/references/design-polish.md +485 -537
- package/pipeline/skills/shared/external/swiftui-patterns/references/platform-and-sharing.md +417 -499
- package/pipeline/skills/shared/external/swiftui-performance/SKILL.md +213 -376
- package/pipeline/skills/shared/external/swiftui-performance/references/demystify-swiftui-performance-wwdc23.md +86 -175
- package/pipeline/skills/shared/external/swiftui-performance/references/optimizing-swiftui-performance-instruments.md +89 -195
- package/pipeline/skills/shared/external/swiftui-performance/references/understanding-hangs-in-your-app.md +95 -182
- package/pipeline/skills/shared/external/swiftui-performance/references/understanding-improving-swiftui-performance.md +71 -149
- package/pipeline/skills/shared/external/swiftui-performance/references/wwdc-session-sources.md +21 -27
- package/pipeline/skills/shared/external/swiftui-uikit-interop/SKILL.md +303 -295
- package/pipeline/skills/shared/external/swiftui-uikit-interop/references/hosting-migration.md +204 -387
- package/pipeline/skills/shared/external/swiftui-uikit-interop/references/representable-recipes.md +469 -683
- package/pipeline/skills/shared/external/swiftui-webkit/SKILL.md +140 -186
- package/pipeline/skills/shared/external/swiftui-webkit/references/loading-and-observation.md +75 -86
- package/pipeline/skills/shared/external/swiftui-webkit/references/local-content-and-custom-schemes.md +63 -60
- package/pipeline/skills/shared/external/swiftui-webkit/references/migration-and-fallbacks.md +69 -137
- package/pipeline/skills/shared/external/swiftui-webkit/references/navigation-and-javascript.md +95 -67
- package/pipeline/skills/shared/external/tipkit/SKILL.md +220 -335
- package/pipeline/skills/shared/external/tipkit/references/tipkit-patterns.md +356 -494
- package/pipeline/skills/shared/external/vision-framework/SKILL.md +260 -375
- package/pipeline/skills/shared/external/vision-framework/references/vision-requests.md +393 -515
- package/pipeline/skills/shared/external/vision-framework/references/visionkit-scanner.md +363 -539
- package/pipeline/skills/shared/external/weatherkit/SKILL.md +152 -310
- package/pipeline/skills/shared/external/weatherkit/references/weatherkit-patterns.md +288 -407
- package/pipeline/skills/shared/external/widgetkit/SKILL.md +216 -288
- package/pipeline/skills/shared/external/widgetkit/references/widgetkit-advanced.md +414 -719
- package/pipeline/skills/shared/external/NOTICE-swift-ios-skills.md +0 -39
|
@@ -1,528 +1,418 @@
|
|
|
1
|
-
# Foundation Models
|
|
2
|
-
|
|
3
|
-
Complete reference for Apple's Foundation Models framework (iOS 26+ / macOS 26+).
|
|
4
|
-
On-device language model optimized for Apple Silicon. No app-managed API key,
|
|
5
|
-
model hosting, or network round trip for generation; still handle Apple
|
|
6
|
-
Intelligence and system model asset availability.
|
|
1
|
+
# Foundation Models reference
|
|
7
2
|
|
|
8
3
|
## Contents
|
|
9
4
|
|
|
10
|
-
- [
|
|
11
|
-
- [
|
|
12
|
-
- [
|
|
13
|
-
- [
|
|
14
|
-
- [
|
|
15
|
-
- [
|
|
16
|
-
- [
|
|
17
|
-
- [
|
|
18
|
-
- [
|
|
19
|
-
- [
|
|
20
|
-
- [
|
|
21
|
-
- [
|
|
22
|
-
- [
|
|
23
|
-
- [
|
|
24
|
-
- [
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
5
|
+
- [What the framework is for](#what-the-framework-is-for)
|
|
6
|
+
- [SystemLanguageModel](#systemlanguagemodel)
|
|
7
|
+
- [Availability and locale](#availability-and-locale)
|
|
8
|
+
- [Use cases and guardrails](#use-cases-and-guardrails)
|
|
9
|
+
- [Sessions](#sessions)
|
|
10
|
+
- [Prewarming](#prewarming)
|
|
11
|
+
- [Text responses](#text-responses)
|
|
12
|
+
- [Generable types](#generable-types)
|
|
13
|
+
- [Tools](#tools)
|
|
14
|
+
- [Runtime schemas](#runtime-schemas)
|
|
15
|
+
- [Handling errors](#handling-errors)
|
|
16
|
+
- [Sampling and length](#sampling-and-length)
|
|
17
|
+
- [Safety](#safety)
|
|
18
|
+
- [Adapters](#adapters)
|
|
19
|
+
- [Long conversations](#long-conversations)
|
|
20
|
+
- [One coordinator for all calls](#one-coordinator-for-all-calls)
|
|
21
|
+
- [Writing prompts](#writing-prompts)
|
|
22
|
+
- [Sending feedback](#sending-feedback)
|
|
23
|
+
|
|
24
|
+
## What the framework is for
|
|
25
|
+
|
|
26
|
+
The framework gives apps the system language model on iOS 26+ and macOS 26+.
|
|
27
|
+
Generation needs no key, hosting or network access from the app, but the app
|
|
28
|
+
must handle Apple Intelligence being off and model assets not being present.
|
|
29
|
+
|
|
30
|
+
Input and output share one context window; its size is
|
|
31
|
+
`SystemLanguageModel.default.contextSize`.
|
|
32
|
+
|
|
33
|
+
Good at: summaries, entity extraction, understanding and rewriting text, short
|
|
34
|
+
dialog, creative writing, content tagging. Weak at: complex math, generating
|
|
35
|
+
code, and anything that must be factually accurate.
|
|
36
|
+
|
|
37
|
+
## SystemLanguageModel
|
|
38
|
+
|
|
39
|
+
| Member | Meaning |
|
|
40
|
+
|---|---|
|
|
41
|
+
| `contextSize` | Maximum tokens in the context window |
|
|
42
|
+
| `supportedLanguages` | `Set<Locale.Language>` the model supports |
|
|
43
|
+
| `supportsLocale(_ locale: Locale) -> Bool` | Whether a locale works, including fallbacks; prefer this |
|
|
44
|
+
| `isAvailable` | Quick `Bool` availability check |
|
|
45
|
+
| `availability` | Detailed status with an unavailability reason |
|
|
46
|
+
|
|
47
|
+
Use `supportsLocale(_:)` to decide whether to generate. Use
|
|
48
|
+
`supportedLanguages` only to show which languages are broadly supported.
|
|
49
|
+
|
|
50
|
+
## Availability and locale
|
|
46
51
|
|
|
47
52
|
```swift
|
|
53
|
+
import Foundation
|
|
48
54
|
import FoundationModels
|
|
49
55
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
enum AssistantRoute {
|
|
57
|
+
case generate(Locale)
|
|
58
|
+
case askToEnable
|
|
59
|
+
case waitForAssets
|
|
60
|
+
case fallback
|
|
53
61
|
}
|
|
54
62
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
func assistantRoute() -> AssistantRoute {
|
|
64
|
+
let model = SystemLanguageModel.default
|
|
65
|
+
switch model.availability {
|
|
66
|
+
case .available:
|
|
67
|
+
let candidates = [Locale.current]
|
|
68
|
+
+ Locale.preferredLanguages.map(Locale.init(identifier:))
|
|
69
|
+
if let locale = candidates.first(where: model.supportsLocale) {
|
|
70
|
+
return .generate(locale)
|
|
71
|
+
}
|
|
72
|
+
return .fallback
|
|
73
|
+
case .unavailable(.appleIntelligenceNotEnabled):
|
|
74
|
+
return .askToEnable // Settings > Apple Intelligence
|
|
75
|
+
case .unavailable(.modelNotReady):
|
|
76
|
+
return .waitForAssets // downloading, or another temporary system reason
|
|
77
|
+
case .unavailable(.deviceNotEligible):
|
|
78
|
+
return .fallback
|
|
79
|
+
default:
|
|
80
|
+
return .fallback // reasons added in future releases
|
|
62
81
|
}
|
|
63
|
-
// Proceed with model usage
|
|
64
|
-
case .unavailable(.appleIntelligenceNotEnabled):
|
|
65
|
-
// Guide user to Settings > Apple Intelligence
|
|
66
|
-
case .unavailable(.modelNotReady):
|
|
67
|
-
// System model assets are downloading or unavailable for other system reasons
|
|
68
|
-
case .unavailable(.deviceNotEligible):
|
|
69
|
-
// Device cannot run Apple Intelligence
|
|
70
|
-
default:
|
|
71
|
-
// Graceful fallback for unknown or future unavailable reasons
|
|
72
82
|
}
|
|
73
83
|
```
|
|
74
84
|
|
|
75
|
-
## Use
|
|
76
|
-
|
|
77
|
-
Foundation Models supports specialized use cases:
|
|
85
|
+
## Use cases and guardrails
|
|
78
86
|
|
|
79
87
|
```swift
|
|
80
|
-
|
|
81
|
-
let
|
|
82
|
-
|
|
83
|
-
// Content tagging (optimized for categorization)
|
|
84
|
-
let model = SystemLanguageModel(useCase: .contentTagging, guardrails: .default)
|
|
88
|
+
let general = SystemLanguageModel(useCase: .general, guardrails: .default)
|
|
89
|
+
let tagger = SystemLanguageModel(useCase: .contentTagging, guardrails: .default)
|
|
85
90
|
```
|
|
86
91
|
|
|
87
|
-
|
|
92
|
+
`.general` covers generation, summaries and dialog. `.contentTagging` is tuned
|
|
93
|
+
for labelling and categorising text.
|
|
88
94
|
|
|
89
|
-
|
|
95
|
+
## Sessions
|
|
90
96
|
|
|
91
97
|
```swift
|
|
92
|
-
//
|
|
98
|
+
// Uses SystemLanguageModel.default
|
|
93
99
|
let session = LanguageModelSession()
|
|
94
100
|
|
|
95
|
-
//
|
|
96
|
-
let
|
|
97
|
-
"You are a
|
|
98
|
-
"
|
|
101
|
+
// Several instruction lines
|
|
102
|
+
let coach = LanguageModelSession {
|
|
103
|
+
"You are a running coach."
|
|
104
|
+
"Answer in at most three sentences."
|
|
99
105
|
}
|
|
100
106
|
|
|
101
|
-
//
|
|
102
|
-
let
|
|
103
|
-
|
|
104
|
-
) {
|
|
105
|
-
"You are a helpful assistant with access to tools."
|
|
107
|
+
// A specific model plus tools
|
|
108
|
+
let tagging = LanguageModelSession(model: tagger, tools: []) {
|
|
109
|
+
"Assign one topic label to each note."
|
|
106
110
|
}
|
|
107
111
|
|
|
108
|
-
//
|
|
109
|
-
let
|
|
110
|
-
let session = LanguageModelSession(model: model, tools: []) {
|
|
111
|
-
"You are a helpful assistant."
|
|
112
|
-
}
|
|
112
|
+
// Continue a stored conversation
|
|
113
|
+
let restored = LanguageModelSession(model: general, tools: [], transcript: storedTranscript)
|
|
113
114
|
```
|
|
114
115
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
requests.
|
|
120
|
-
3. Prewarm with `session.prewarm()` before user interaction for faster first
|
|
121
|
-
response.
|
|
122
|
-
4. Save and restore transcripts for session continuity:
|
|
123
|
-
`LanguageModelSession(model: model, tools: [], transcript: savedTranscript)`.
|
|
116
|
+
- Sessions are stateful; each turn sees the earlier ones.
|
|
117
|
+
- One request at a time; `isResponding` tells you if one is running.
|
|
118
|
+
- Prewarm before use.
|
|
119
|
+
- Save `session.transcript` to continue the conversation later.
|
|
124
120
|
|
|
125
|
-
|
|
121
|
+
## Prewarming
|
|
126
122
|
|
|
127
123
|
```swift
|
|
128
|
-
// Prewarm before user interaction
|
|
129
124
|
session.prewarm()
|
|
130
|
-
|
|
131
|
-
// Prewarm with a prompt prefix for faster specific responses
|
|
132
|
-
session.prewarm(promptPrefix: Prompt("Summarize the following text:"))
|
|
125
|
+
coach.prewarm(promptPrefix: Prompt("Plan a training week for"))
|
|
133
126
|
```
|
|
134
127
|
|
|
135
|
-
|
|
128
|
+
A prefix lets the system prepare for prompts that begin the same way.
|
|
136
129
|
|
|
137
|
-
|
|
130
|
+
## Text responses
|
|
138
131
|
|
|
139
132
|
```swift
|
|
140
|
-
|
|
141
|
-
let
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
let options = GenerationOptions(
|
|
146
|
-
sampling: .random(top: 40),
|
|
147
|
-
temperature: 0.7,
|
|
148
|
-
maximumResponseTokens: 512
|
|
149
|
-
)
|
|
150
|
-
let response = try await session.respond(to: prompt, options: options)
|
|
133
|
+
let reply = try await coach.respond(to: "How should I taper before a 10K?")
|
|
134
|
+
let text: String = reply.content
|
|
135
|
+
|
|
136
|
+
let brief = try await coach.respond(to: "One tip for hills",
|
|
137
|
+
options: GenerationOptions(maximumResponseTokens: 80))
|
|
151
138
|
```
|
|
152
139
|
|
|
153
|
-
|
|
140
|
+
Streaming text:
|
|
154
141
|
|
|
155
142
|
```swift
|
|
156
|
-
let stream =
|
|
157
|
-
for try await
|
|
158
|
-
|
|
143
|
+
let stream = coach.streamResponse(to: "Describe a tempo run")
|
|
144
|
+
for try await partial in stream {
|
|
145
|
+
liveText = partial.content
|
|
159
146
|
}
|
|
160
|
-
|
|
161
|
-
// Or collect the full response
|
|
162
|
-
let response = try await stream.collect()
|
|
147
|
+
let complete = try await stream.collect()
|
|
163
148
|
```
|
|
164
149
|
|
|
165
|
-
##
|
|
150
|
+
## Generable types
|
|
166
151
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
152
|
+
`@Generable` turns a type into a JSON schema at compile time. Property types it
|
|
153
|
+
accepts: `String`, `Int`, `Double`, `Float`, `Bool`, arrays of Generable or
|
|
154
|
+
scalar values, optionals of those, nested `@Generable` structs and
|
|
155
|
+
`@Generable` enums.
|
|
170
156
|
|
|
171
157
|
```swift
|
|
172
158
|
@Generable
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
var name: String
|
|
176
|
-
|
|
177
|
-
@Guide(description: "A brief description of the dish")
|
|
178
|
-
var summary: String
|
|
179
|
-
|
|
180
|
-
@Guide(description: "Cooking steps", .count(3))
|
|
181
|
-
var steps: [String]
|
|
182
|
-
|
|
183
|
-
@Guide(description: "Prep time in minutes", .range(1...120))
|
|
184
|
-
var prepTime: Int
|
|
159
|
+
enum Effort: String {
|
|
160
|
+
case easy, moderate, hard
|
|
185
161
|
}
|
|
186
162
|
|
|
187
|
-
let response = try await session.respond(
|
|
188
|
-
to: "Suggest a quick pasta recipe",
|
|
189
|
-
generating: Recipe.self
|
|
190
|
-
)
|
|
191
|
-
let recipe = response.content
|
|
192
|
-
print(recipe.name)
|
|
193
|
-
print(recipe.steps)
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
### Supported Types for `@Generable` Properties
|
|
197
|
-
|
|
198
|
-
- `String`
|
|
199
|
-
- `Int`, `Double`, `Float`
|
|
200
|
-
- `Bool`
|
|
201
|
-
- `[Element]` where Element is Generable or a supported scalar
|
|
202
|
-
- `Optional<T>` where T is Generable or a supported scalar
|
|
203
|
-
- Other `@Generable` structs (nested)
|
|
204
|
-
- Enums conforming to `@Generable`
|
|
205
|
-
|
|
206
|
-
### `@Guide` Constraints
|
|
207
|
-
|
|
208
|
-
```swift
|
|
209
163
|
@Generable
|
|
210
|
-
struct
|
|
211
|
-
@Guide(
|
|
212
|
-
var
|
|
164
|
+
struct WorkoutFeedback {
|
|
165
|
+
@Guide(.range(1...10))
|
|
166
|
+
var perceivedExertion: Int
|
|
213
167
|
|
|
214
|
-
@Guide(
|
|
215
|
-
var
|
|
168
|
+
@Guide(.anyOf(["improving", "steady", "declining"]))
|
|
169
|
+
var trend: String
|
|
216
170
|
|
|
217
|
-
@Guide(description: "
|
|
218
|
-
var
|
|
171
|
+
@Guide(description: "Actionable suggestions", .count(3))
|
|
172
|
+
var suggestions: [String]
|
|
219
173
|
|
|
220
|
-
@Guide(
|
|
221
|
-
var
|
|
174
|
+
@Guide(.pattern(/^[A-Z][^.]*\.$/))
|
|
175
|
+
var headline: String
|
|
222
176
|
|
|
223
|
-
@Guide(
|
|
224
|
-
var
|
|
177
|
+
@Guide(.constant("v1"))
|
|
178
|
+
var format: String
|
|
225
179
|
|
|
226
|
-
|
|
227
|
-
var language: String
|
|
180
|
+
var effort: Effort
|
|
228
181
|
}
|
|
229
182
|
```
|
|
230
183
|
|
|
231
|
-
|
|
184
|
+
Which guides apply to which types:
|
|
232
185
|
|
|
233
|
-
|
|
|
234
|
-
|
|
235
|
-
| `description:` |
|
|
236
|
-
| `.anyOf
|
|
237
|
-
| `.count
|
|
238
|
-
| `.
|
|
239
|
-
| `.maximumCount(n)` | Array | Maximum array length |
|
|
240
|
-
| `.range(min...max)` | Numeric | Closed numeric range |
|
|
241
|
-
| `.minimum(n)` | Numeric | Lower bound |
|
|
242
|
-
| `.maximum(n)` | Numeric | Upper bound |
|
|
243
|
-
| `.constant(value)` | String | Always returns this value |
|
|
244
|
-
| `.pattern(regex)` | String | Regex format enforcement |
|
|
245
|
-
| `.element(guide)` | Array | Guide applied to each element |
|
|
186
|
+
| Guide | Applies to |
|
|
187
|
+
|---|---|
|
|
188
|
+
| `description:` | Any property |
|
|
189
|
+
| `.anyOf`, `.constant`, `.pattern` | `String` |
|
|
190
|
+
| `.count`, `.minimumCount`, `.maximumCount`, `.element` | Arrays |
|
|
191
|
+
| `.range`, `.minimum`, `.maximum` | Numbers |
|
|
246
192
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
Properties are generated in declaration order. Place foundational data before
|
|
250
|
-
dependent data:
|
|
193
|
+
Generation follows declaration order, and later fields are written with the
|
|
194
|
+
earlier ones already in context. Order fields the way a person would reason:
|
|
251
195
|
|
|
252
196
|
```swift
|
|
253
197
|
@Generable
|
|
254
|
-
struct
|
|
255
|
-
var
|
|
256
|
-
var
|
|
257
|
-
var
|
|
198
|
+
struct RaceReport {
|
|
199
|
+
var headline: String // first: sets the topic
|
|
200
|
+
var highlights: [String] // then: details under that headline
|
|
201
|
+
var takeaway: String // last: draws on both
|
|
258
202
|
}
|
|
259
203
|
```
|
|
260
204
|
|
|
261
|
-
|
|
205
|
+
Streaming a Generable type yields `PartiallyGenerated` values whose fields are
|
|
206
|
+
all optional:
|
|
262
207
|
|
|
263
208
|
```swift
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
)
|
|
268
|
-
for try await snapshot in stream {
|
|
269
|
-
// snapshot.content is Recipe.PartiallyGenerated (all properties optional)
|
|
270
|
-
if let name = snapshot.content.name { updateNameLabel(name) }
|
|
271
|
-
if let steps = snapshot.content.steps { updateStepsList(steps) }
|
|
209
|
+
for try await snapshot in coach.streamResponse(to: prompt, generating: WorkoutFeedback.self) {
|
|
210
|
+
if let trend = snapshot.content.trend { trendLabel = trend }
|
|
211
|
+
if let tips = snapshot.content.suggestions { suggestionList = tips }
|
|
272
212
|
}
|
|
273
213
|
```
|
|
274
214
|
|
|
275
|
-
|
|
215
|
+
## Tools
|
|
276
216
|
|
|
277
217
|
```swift
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
@Generable
|
|
284
|
-
struct Task {
|
|
285
|
-
var title: String
|
|
286
|
-
var priority: Priority
|
|
287
|
-
}
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
## Tool Calling
|
|
291
|
-
|
|
292
|
-
### Defining Tools
|
|
293
|
-
|
|
294
|
-
```swift
|
|
295
|
-
struct WeatherTool: Tool {
|
|
296
|
-
let name = "weather"
|
|
297
|
-
let description = "Get current weather for a city."
|
|
218
|
+
struct PaceHistoryTool: Tool {
|
|
219
|
+
let name = "recentPaces"
|
|
220
|
+
let description = "Returns the runner's average pace for recent runs."
|
|
298
221
|
|
|
299
222
|
@Generable
|
|
300
223
|
struct Arguments {
|
|
301
|
-
@Guide(description: "
|
|
302
|
-
var
|
|
224
|
+
@Guide(description: "How many recent runs to include", .range(1...20))
|
|
225
|
+
var count: Int
|
|
303
226
|
}
|
|
304
227
|
|
|
305
|
-
func call(arguments: Arguments) async throws -> String {
|
|
306
|
-
|
|
307
|
-
return weather.description
|
|
228
|
+
func call(arguments: Arguments) async throws -> [String] {
|
|
229
|
+
try await RunLog.shared.paces(last: arguments.count)
|
|
308
230
|
}
|
|
309
231
|
}
|
|
310
|
-
```
|
|
311
232
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
```swift
|
|
315
|
-
let session = LanguageModelSession(
|
|
316
|
-
tools: [WeatherTool()]
|
|
317
|
-
) {
|
|
318
|
-
"You are a helpful assistant."
|
|
233
|
+
let session = LanguageModelSession(tools: [PaceHistoryTool()]) {
|
|
234
|
+
"Use recent paces when giving pacing advice."
|
|
319
235
|
}
|
|
320
|
-
|
|
321
|
-
// The model decides autonomously when to invoke tools
|
|
322
|
-
let response = try await session.respond(to: "What's the weather in Tokyo?")
|
|
236
|
+
let advice = try await session.respond(to: "What pace for my next easy run?")
|
|
323
237
|
```
|
|
324
238
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
-
|
|
328
|
-
|
|
329
|
-
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
-
|
|
334
|
-
the
|
|
335
|
-
-
|
|
336
|
-
|
|
337
|
-
-
|
|
338
|
-
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
- `ToolCallError`: Struct on `LanguageModelSession` representing a tool invocation failure. Properties: `tool` (the tool name), `underlyingError` (the original error).
|
|
349
|
-
- `DynamicGenerationSchema`: Build generation schemas at runtime for dynamic use cases where compile-time `@Generable` is insufficient. Construct schemas programmatically and pass to `respond(to:schema:)`.
|
|
350
|
-
|
|
351
|
-
## Error Handling
|
|
239
|
+
The model decides during `respond(to:)` whether to call a tool.
|
|
240
|
+
|
|
241
|
+
- Keep the active set small, usually three to five tools, and only those the
|
|
242
|
+
current task can use.
|
|
243
|
+
- By default each tool's name, description and argument schema are written into
|
|
244
|
+
the instructions, which costs context tokens. Setting
|
|
245
|
+
`includesSchemaInInstructions` to `false` (default `true`) leaves the schema
|
|
246
|
+
out.
|
|
247
|
+
- Fetch data the answer always needs before calling the model and include it in
|
|
248
|
+
the prompt. Autonomous tool calls suit lookups that depend on the question.
|
|
249
|
+
- A tool call cannot be forced.
|
|
250
|
+
- `Tool` conforms to `Sendable`, so any state a tool captures must be
|
|
251
|
+
concurrency-safe.
|
|
252
|
+
- `Arguments` conforms to `ConvertibleFromGeneratedContent` (a `@Generable`
|
|
253
|
+
struct does). `Output` conforms to `PromptRepresentable`: `String`,
|
|
254
|
+
`[String]` and your own conforming types work.
|
|
255
|
+
- A failing tool surfaces as `LanguageModelSession.ToolCallError`, which holds
|
|
256
|
+
the `tool` and its `underlyingError`.
|
|
257
|
+
|
|
258
|
+
## Runtime schemas
|
|
259
|
+
|
|
260
|
+
When the shape is only known at runtime, build a `DynamicGenerationSchema` and
|
|
261
|
+
pass the resulting schema to `respond(to:schema:)`:
|
|
352
262
|
|
|
353
263
|
```swift
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
} catch let error as LanguageModelSession.GenerationError {
|
|
357
|
-
switch error {
|
|
358
|
-
case .guardrailViolation:
|
|
359
|
-
// Content triggered safety filters; rephrase and retry
|
|
360
|
-
case .exceededContextWindowSize:
|
|
361
|
-
// Too many tokens; summarize earlier turns and create new session
|
|
362
|
-
case .concurrentRequests:
|
|
363
|
-
// Another request is already in progress on this session
|
|
364
|
-
case .rateLimited:
|
|
365
|
-
// Too many requests; back off and retry
|
|
366
|
-
case .unsupportedLanguageOrLocale:
|
|
367
|
-
// Current locale not supported by the model
|
|
368
|
-
case .unsupportedGuide:
|
|
369
|
-
// A @Guide constraint is not supported
|
|
370
|
-
case .assetsUnavailable:
|
|
371
|
-
// Model assets not available on device
|
|
372
|
-
case .decodingFailure:
|
|
373
|
-
// Failed to decode structured output
|
|
374
|
-
case .refusal(let refusal, _):
|
|
375
|
-
// Model refused the request
|
|
376
|
-
let explanation = try await refusal.explanation.content
|
|
377
|
-
print("Refused: \(explanation)")
|
|
378
|
-
default: break
|
|
379
|
-
}
|
|
264
|
+
let fields = userChosenFields.map {
|
|
265
|
+
DynamicGenerationSchema.Property(name: $0, schema: DynamicGenerationSchema(type: String.self))
|
|
380
266
|
}
|
|
267
|
+
let form = DynamicGenerationSchema(name: "Form", properties: fields)
|
|
268
|
+
let schema = try GenerationSchema(root: form, dependencies: [])
|
|
269
|
+
let filled = try await session.respond(to: sourceText, schema: schema)
|
|
381
270
|
```
|
|
382
271
|
|
|
383
|
-
##
|
|
272
|
+
## Handling errors
|
|
384
273
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
sampling: .greedy, // Deterministic output
|
|
388
|
-
temperature: nil, // Use default
|
|
389
|
-
maximumResponseTokens: 256 // Limit response length
|
|
390
|
-
)
|
|
391
|
-
|
|
392
|
-
// Random sampling with top-k
|
|
393
|
-
let options = GenerationOptions(
|
|
394
|
-
sampling: .random(top: 40),
|
|
395
|
-
temperature: 0.7
|
|
396
|
-
)
|
|
397
|
-
|
|
398
|
-
// Random sampling with probability threshold
|
|
399
|
-
let options = GenerationOptions(
|
|
400
|
-
sampling: .random(probabilityThreshold: 0.9)
|
|
401
|
-
)
|
|
402
|
-
```
|
|
274
|
+
The `GenerationError` cases and the usual response are listed in SKILL.md. The
|
|
275
|
+
recovery for each:
|
|
403
276
|
|
|
404
|
-
|
|
405
|
-
|
|
277
|
+
- `guardrailViolation`: ask the user to rephrase, then retry.
|
|
278
|
+
- `exceededContextWindowSize`: summarise the earlier turns into a new session
|
|
279
|
+
and continue there.
|
|
280
|
+
- `rateLimited`: back off before retrying.
|
|
281
|
+
- `refusal(let refusal, _)`: read the reason with
|
|
282
|
+
`try await refusal.explanation.content` and show it.
|
|
406
283
|
|
|
407
|
-
##
|
|
408
|
-
|
|
409
|
-
### Guardrail Types
|
|
284
|
+
## Sampling and length
|
|
410
285
|
|
|
411
286
|
```swift
|
|
412
|
-
|
|
413
|
-
let
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
let
|
|
417
|
-
useCase: .general,
|
|
418
|
-
guardrails: .permissiveContentTransformations
|
|
419
|
-
)
|
|
287
|
+
let deterministic = GenerationOptions(sampling: .greedy)
|
|
288
|
+
let defaultTemp = GenerationOptions(temperature: nil, maximumResponseTokens: 256)
|
|
289
|
+
let topK = GenerationOptions(sampling: .random(top: 40))
|
|
290
|
+
let nucleus = GenerationOptions(sampling: .random(probabilityThreshold: 0.9))
|
|
291
|
+
let repeatable = GenerationOptions(sampling: .random(top: 40, seed: 7))
|
|
420
292
|
```
|
|
421
293
|
|
|
422
|
-
|
|
294
|
+
- `.greedy` always picks the most likely token, so output is deterministic.
|
|
295
|
+
- `temperature: nil` keeps the system default.
|
|
296
|
+
- `maximumResponseTokens` caps the reply length.
|
|
297
|
+
- `.random(top:)` samples from the top k tokens; `.random(probabilityThreshold:)`
|
|
298
|
+
samples from the smallest set whose probability reaches the threshold.
|
|
299
|
+
- Both random modes take `seed:` for reproducible output.
|
|
423
300
|
|
|
424
|
-
|
|
425
|
-
- Instructions take precedence over user prompts
|
|
426
|
-
- Never include untrusted user content in instructions
|
|
427
|
-
- Provide curated selections over free-form input when possible
|
|
428
|
-
- Guardrails can produce false positives; handle gracefully
|
|
429
|
-
- Frame tool results as authorized user data
|
|
301
|
+
## Safety
|
|
430
302
|
|
|
431
|
-
|
|
303
|
+
Guardrail settings:
|
|
432
304
|
|
|
433
|
-
|
|
305
|
+
- `.default`: the recommended setting.
|
|
306
|
+
- `.permissiveContentTransformations`: for rewriting or transforming text the
|
|
307
|
+
user supplied, where the default can be too strict.
|
|
434
308
|
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
let adapter = try SystemLanguageModel.Adapter(name: "my-adapter")
|
|
438
|
-
try await adapter.compile()
|
|
309
|
+
Where you can, offer curated choices instead of free-form input. Keep user text
|
|
310
|
+
out of instructions.
|
|
439
311
|
|
|
440
|
-
|
|
441
|
-
let session = LanguageModelSession(model: model)
|
|
442
|
-
let response = try await session.respond(to: "Generate styled text")
|
|
443
|
-
```
|
|
312
|
+
## Adapters
|
|
444
313
|
|
|
445
|
-
|
|
314
|
+
Adapters are fine-tuned LoRA weights for the system model. They need the
|
|
315
|
+
`com.apple.developer.foundation-model-adapter` entitlement.
|
|
446
316
|
|
|
447
317
|
```swift
|
|
448
|
-
|
|
449
|
-
|
|
318
|
+
let adapter = try SystemLanguageModel.Adapter(name: "trail-guide")
|
|
319
|
+
try await adapter.compile()
|
|
320
|
+
let tuned = SystemLanguageModel(adapter: adapter, guardrails: .default)
|
|
321
|
+
let session = LanguageModelSession(model: tuned)
|
|
450
322
|
|
|
451
|
-
|
|
323
|
+
let usable = SystemLanguageModel.Adapter.compatibleAdapterIdentifiers(name: "trail-guide")
|
|
452
324
|
try SystemLanguageModel.Adapter.removeObsoleteAdapters()
|
|
453
325
|
```
|
|
454
326
|
|
|
455
|
-
|
|
327
|
+
`compatibleAdapterIdentifiers(name:)` lists adapter versions that match the
|
|
328
|
+
installed system model; `removeObsoleteAdapters()` deletes the ones that no
|
|
329
|
+
longer do.
|
|
456
330
|
|
|
457
|
-
|
|
331
|
+
## Long conversations
|
|
458
332
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
333
|
+
A conversation grows until it no longer fits. Measure it against
|
|
334
|
+
`contextSize`, estimate the cost of text with
|
|
335
|
+
`SystemLanguageModel.default.tokenCount(for:)` (iOS 26.4+; `contextSize` is
|
|
336
|
+
back-deployed to 26.0), and before it overflows, fold
|
|
337
|
+
the history into a summary and start a fresh session with that summary in its
|
|
338
|
+
instructions.
|
|
463
339
|
|
|
464
340
|
```swift
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
341
|
+
@available(iOS 26.4, macOS 26.4, visionOS 26.4, *)
|
|
342
|
+
func continueOrCondense(_ session: LanguageModelSession,
|
|
343
|
+
history: String) async throws -> LanguageModelSession {
|
|
344
|
+
let model = SystemLanguageModel.default
|
|
345
|
+
let used = try await model.tokenCount(for: history)
|
|
346
|
+
guard used > model.contextSize * 3 / 4 else { return session }
|
|
347
|
+
|
|
348
|
+
let summary = try await LanguageModelSession().respond(
|
|
349
|
+
to: "Summarise this conversation in five bullet points:\n\(history)"
|
|
350
|
+
).content
|
|
351
|
+
return LanguageModelSession {
|
|
352
|
+
"You are a running coach."
|
|
353
|
+
"Earlier conversation, summarised: \(summary)"
|
|
470
354
|
}
|
|
471
355
|
}
|
|
472
356
|
```
|
|
473
357
|
|
|
474
|
-
|
|
358
|
+
The 75 percent threshold leaves room for the next reply; tune it to your
|
|
359
|
+
typical answer length.
|
|
475
360
|
|
|
476
|
-
|
|
361
|
+
## One coordinator for all calls
|
|
362
|
+
|
|
363
|
+
Route every request through one actor that owns the session, so two features
|
|
364
|
+
never run the model at the same time and compete for the Neural Engine. Chain
|
|
365
|
+
requests as shown in SKILL.md, because an actor alone does not serialise across
|
|
366
|
+
`await`.
|
|
477
367
|
|
|
478
368
|
```swift
|
|
479
|
-
actor
|
|
369
|
+
actor CoachService {
|
|
480
370
|
private var session: LanguageModelSession?
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
371
|
+
private var last: Task<Void, Never>?
|
|
372
|
+
|
|
373
|
+
func ask(_ prompt: String) async throws -> String {
|
|
374
|
+
let previous = last
|
|
375
|
+
let job = Task { () async throws -> String in
|
|
376
|
+
await previous?.value
|
|
377
|
+
let active = self.currentSession()
|
|
378
|
+
return try await active.respond(to: prompt).content
|
|
485
379
|
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
380
|
+
last = Task { _ = try? await job.value }
|
|
381
|
+
return try await job.value
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
private func currentSession() -> LanguageModelSession {
|
|
385
|
+
if let session { return session }
|
|
386
|
+
let created = LanguageModelSession { "You are a running coach." }
|
|
387
|
+
session = created
|
|
388
|
+
return created
|
|
491
389
|
}
|
|
492
390
|
}
|
|
493
391
|
```
|
|
494
392
|
|
|
495
|
-
|
|
496
|
-
Neural Engine contention.
|
|
497
|
-
|
|
498
|
-
## Prompt Design Best Practices
|
|
393
|
+
## Writing prompts
|
|
499
394
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
3. **Use "DO NOT" in all caps** for behavioral prohibitions.
|
|
504
|
-
4. **Provide up to 5 few-shot examples** for consistent output.
|
|
505
|
-
5. **Use length qualifiers:** "in a few words", "in three sentences".
|
|
506
|
-
6. **Estimate token usage** with `SystemLanguageModel.default.tokenCount(for:)`
|
|
507
|
-
to avoid exceeding the context window.
|
|
395
|
+
The rules in SKILL.md apply; in addition, estimate prompt size with
|
|
396
|
+
`SystemLanguageModel.default.tokenCount(for:)` (iOS 26.4+) before sending long
|
|
397
|
+
inputs.
|
|
508
398
|
|
|
509
|
-
##
|
|
399
|
+
## Sending feedback
|
|
510
400
|
|
|
511
|
-
|
|
401
|
+
Attach structured feedback to a report when output is wrong:
|
|
512
402
|
|
|
513
403
|
```swift
|
|
514
|
-
let
|
|
404
|
+
let attachment = session.logFeedbackAttachment(
|
|
515
405
|
sentiment: .negative,
|
|
516
406
|
issues: [
|
|
517
|
-
LanguageModelFeedback.Issue(
|
|
518
|
-
|
|
519
|
-
explanation: "Ignored the word count constraint"
|
|
520
|
-
)
|
|
407
|
+
LanguageModelFeedback.Issue(category: .incorrect,
|
|
408
|
+
explanation: "Recommended pace was faster than race pace.")
|
|
521
409
|
],
|
|
522
410
|
desiredOutput: nil
|
|
523
411
|
)
|
|
524
412
|
```
|
|
525
413
|
|
|
414
|
+
The call returns data to include in a Feedback Assistant report.
|
|
415
|
+
|
|
526
416
|
Issue categories: `.didNotFollowInstructions`, `.incorrect`,
|
|
527
417
|
`.stereotypeOrBias`, `.suggestiveOrSexual`, `.tooVerbose`,
|
|
528
418
|
`.triggeredGuardrailUnexpectedly`, `.unhelpful`, `.vulgarOrOffensive`.
|