Repository navigation
Project profile history into native Foundation Models sessions - #349
Merged
mattt merged 65 commits intoNov 6, 2026
Merged
Conversation
…dynamic-profiles # Conflicts: # Sources/AnyLanguageModel/LanguageModelSession.swift # Sources/AnyLanguageModel/SessionProperties.swift # Sources/AnyLanguageModelMacros/SessionPropertyEntryMacro.swift # Tests/AnyLanguageModelTests/APICompatibilityAnyLanguageModelTests.swift # Tests/AnyLanguageModelTests/APICompatibilityFoundationModelsTests.swift # Tests/AnyLanguageModelTests/SessionPropertyTests.swift
…dynamic-profiles # Conflicts: # Sources/AnyLanguageModel/SessionProperties.swift # Tests/AnyLanguageModelTests/SessionPropertyTests.swift
…dynamic-profiles # Conflicts: # Sources/AnyLanguageModel/LanguageModelSession.swift
…ofile-tool-continuations # Conflicts: # Sources/AnyLanguageModel/DynamicProfile.swift # Sources/AnyLanguageModel/LanguageModelSession.swift
…ile-tool-continuations
…pstream-profile-native-history
…stream-profile-native-history
…stream-session-properties
…stream-dynamic-profiles
…stream-profile-tool-continuations
…stream-profile-native-history
main has the shared profile runtime from huggingface#315 and the work in huggingface#344 to huggingface#348, so main's version is kept for all files except SystemLanguageModel.swift and NativeProfileHistoryTests.swift. The tests now expect what main does when it creates a profile session: it evaluates the profile once and records an instructions entry.
Foundation Models sends a profile's transformed prompt in place of the current one. A native request sent both prompts, or the original text if the transform kept the IDs.
During a request, each native evaluation already returns the prepared context, so the reuse changed nothing there. The profile is still resolved when the session is made, for the projected history.
The original prompt was converted first, so a transform that replaced a remote image with text still threw nonFileImageURL. A profile session now converts it only if the request sends it. A rewritten prompt went through the tool output converter, which flattened structured segments to JSON text and dropped their source. A Foundation Models prompt can't set a segment's ID or source, so a native history transform now sets the rewritten segments.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR makes native Foundation Models sessions send a profile's projected history, as the framework does.
On
main, a profile session's native history comes from the canonical transcript, sohistoryTransformhas no effect on native requests. This PR seeds the native history from the resolved request context and leaves the canonical transcript unchanged. If a transform rewrites the current prompt, the rewritten prompt is sent in place of the current one, so the request holds one copy. Foundation Models 27 does the same with its own profiles: the model sees the rewritten text, and the session's transcript keeps the original. A rewritten prompt reaches the native request through a history transform, because the Foundation Models prompt API can't set a structured segment's ID or source.The profile constructor stays Compatibility SPI. This PR adds no native delegate or Tool loop, and ordinary sessions keep their evaluation timing. To carry the rewritten prompt,
fmRespondandfmStreamResponsenow take a closure that returns the session and the prompt together.Known differences from Foundation Models:
main, and this PR does not change it.