Skip to content
Open
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,28 @@ but never become part of the session's transcript.
> Otherwise, it throws `SystemLanguageModel.Error.dynamicInstructionsUnavailable`
> for a session with dynamic instructions.

### Foundation Models 27 request options

`ContextOptions` mirrors Foundation Models 27's schema-in-prompt and reasoning-level
settings for compatibility-layer request construction. `GenerationOptions` also
provides the OS 27 `samplingMode` spelling and `ToolCallingMode` values:

```swift
let context = ContextOptions(
includeSchemaInPrompt: true,
reasoningLevel: .moderate
)
let options = GenerationOptions(
samplingMode: .greedy,
toolCallingMode: .required
)
```

The older `sampling` property and initializer remain source-compatible.
Tool-calling mode is preserved in Codable transcripts and forwarded by the
Foundation Models bridge on OS 27. Other model providers can read the same
option from their request's `GenerationOptions`.

### Reasoning in the transcript

Reasoning is transcript content, separate from the answer in `response.content`.
Expand Down Expand Up @@ -654,6 +676,11 @@ say which API they follow.
- `DynamicInstructions`, its builder, and `LanguageModelSession.init(model:dynamicInstructions:history:)`:
[dynamic instructions](#dynamic-instructions),
which follow the Foundation Models 27 API.
- `ContextOptions`, `GenerationOptions.samplingMode`, and
`GenerationOptions.ToolCallingMode`:
[request options](#foundation-models-27-request-options), which follow the
Foundation Models 27 API while remaining available on the package's existing
deployment targets.
- `Transcript.Entry.reasoning` and `Transcript.Reasoning`:
[reasoning in the transcript](#reasoning-in-the-transcript),
which follows the Foundation Models 27 API.
Expand Down
27 changes: 27 additions & 0 deletions Sources/AnyLanguageModel/ContextOptions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/// Options that configure a model's request context.
///
/// This mirrors the Foundation Models 27 request-context surface while keeping
/// the package available on its existing deployment targets.
public struct ContextOptions: Sendable, Equatable {
/// The amount of reasoning the model should perform for a request.
public enum ReasoningLevel: Sendable, Equatable {
case light
case moderate
case deep
case custom(String)
}

/// Whether a structured-generation schema should also appear in the prompt.
public var includeSchemaInPrompt: Bool?

/// The amount of reasoning the model should perform.
public var reasoningLevel: ReasoningLevel?

public init(
includeSchemaInPrompt: Bool? = nil,
reasoningLevel: ReasoningLevel? = nil
) {
self.includeSchemaInPrompt = includeSchemaInPrompt
self.reasoningLevel = reasoningLevel
}
}
2 changes: 1 addition & 1 deletion Sources/AnyLanguageModel/DynamicInstructions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ extension Instructions: PrimitiveDynamicInstructions {
}
}

private func resolveDynamicInstructions(
func resolveDynamicInstructions(
_ dynamicInstructions: any DynamicInstructions
) -> ResolvedDynamicInstructions {
func resolve<Content>(_ content: Content) -> ResolvedDynamicInstructions
Expand Down
Loading