Skip to content

Add Foundation Models 27 dynamic profiles - #314

Open
qoli wants to merge 6 commits into
huggingface:mainfrom
qoli:codex/upstream-dynamic-profiles
Open

qoli wants to merge 6 commits into
huggingface:mainfrom
qoli:codex/upstream-dynamic-profiles

Conversation

@qoli

@qoli qoli commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add the Foundation Models 27 LanguageModelSession.DynamicProfile composition surface and built-in modifiers
  • resolve model, instructions, tools, generation options, context options, history transforms, error policy, and lifecycle callbacks per request
  • keep canonical session history separate from request projections
  • bind session properties for profiles, dynamic instructions, lifecycle callbacks, and explicit compatibility Tool execution
  • compile the same Dynamic Profile syntax against AnyLanguageModel and FoundationModels 27

Stack

This PR depends on #311 and #313. After those merge, its functional change is commit a03fd6b. Provider-owned Tool continuation support is intentionally submitted as a separate follow-up PR.

Validation

  • swift format lint --strict --recursive .
  • CI=1 swift test — 697 tests in 74 suites
  • iOS Simulator build
  • watchOS build-for-testing

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Request-scoped profile state can leak across overlapping requests, and history handling can violate its instruction-free contract.

5 open findings
What changed in this PR

Adds Foundation Models 27-compatible dynamic profiles, session properties, request options, and per-request lifecycle handling.

Changes:

  • Adds dynamic profile composition, modifiers, callbacks, and request projections.
  • Adds observable session properties and instruction-free history access.
  • Adds Foundation Models 27 request-option bridging and compatibility tests.
File Description
Sources/​AnyLanguageModel/​ContextOptions.swift Defines request-context options.
Sources/​AnyLanguageModel/​DynamicInstructions.swift Exposes instruction resolution internally.
Sources/​AnyLanguageModel/​DynamicProfile.swift Implements profiles, modifiers, and lifecycle handling.
Sources/​AnyLanguageModel/​GenerationOptions.swift Adds sampling aliases and tool-calling policy.
Sources/​AnyLanguageModel/​LanguageModelSession.swift Integrates profile resolution and callbacks.
Sources/​AnyLanguageModel/​Models/​SystemLanguageModel.swift Bridges tool-calling mode to Foundation Models.
Sources/​AnyLanguageModel/​SessionProperties.swift Implements session-scoped property storage.
Sources/​AnyLanguageModelMacros/​Plugin.swift Registers the session-property macro.
Sources/​AnyLanguageModelMacros/​SessionPropertyEntryMacro.swift Generates session-property accessors and keys.
Tests/​AnyLanguageModelTests/​APICompatibilityAnyLanguageModelTests.swift Checks AnyLanguageModel syntax compatibility.
Tests/​AnyLanguageModelTests/​APICompatibilityFoundationModelsTests.swift Checks native Foundation Models compatibility.
Tests/​AnyLanguageModelTests/​DynamicProfileTests.swift Exercises profiles and lifecycle behavior.
Tests/​AnyLanguageModelTests/​FoundationModelsGenerationOptionsTests.swift Tests native option bridging.
Tests/​AnyLanguageModelTests/​RequestOptionsTests.swift Tests new request-option values.
Tests/​AnyLanguageModelTests/​SessionPropertyTests.swift Tests property storage and history behavior.
README.md Documents Foundation Models 27 request options.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Sources/AnyLanguageModel/LanguageModelSession.swift Outdated
Comment thread Sources/AnyLanguageModel/LanguageModelSession.swift Outdated
Comment thread Sources/AnyLanguageModel/DynamicProfile.swift
Comment thread Sources/AnyLanguageModel/LanguageModelSession.swift Outdated
Comment thread Sources/AnyLanguageModel/SessionProperties.swift

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +431 to +432
if requestContext.callbackState.wasDispatched(entry.id) {
continue
Comment on lines +204 to +207
public func historyTransform(
_ transform: @escaping ([Transcript.Entry]) -> [Transcript.Entry]
) -> some LanguageModelSession.DynamicProfile {
BuiltinModifiedDynamicProfile(content: self, modifier: .historyTransform(transform))
}

/// The canonical session history after dynamic instructions.
public var history: Transcript.HistoryView {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants