LanguageModelSession.DynamicProfile
A dynamic profile that contains one or more profiles.
Declaration
protocol DynamicProfileMentioned in
Overview
A dynamic profile is the top-level coordination layer that manages profiles. It determines which LanguageModelSession.DynamicProfile.Profile is in an active state and allows a LanguageModelSession to switch between entirely different configurations as app state changes. A body must resolve to a single profile.
DynamicInstructions declares what content and tools the model sees, and LanguageModelSession.DynamicProfile.Profile binds that content to how a single configuration runs. That configuration includes details like the model to use, temperature, reasoning level, and so on.
struct PresentationProfile: LanguageModelSession.DynamicProfile {
// The data source for the profile.
var isEditingImage = true
var isEditingAnimation = false
// Determine which profile to load based on the current state.
var body: some LanguageModelSession.DynamicProfile {
if isEditingImage {
// Use the editing image profile.
} else if isEditingAnimation {
// Use the editing animation profile.
} else {
// Use the default profile.
}
}
}Use historyTransform(_:) to perform stateless transcript transforms. This allows you to modify the transcript that’s sent to the model, but doesn’t impact the global transcript state. For example, the request might only need the last twenty entries instead of the full transcript:
Profile {
// The instructions and tools necessary for the task.
}
.historyTransform { history in
Array(history.suffix(20))
}Topics
Implementing a dynamic profile
bodyBodyLanguageModelSession.DynamicProfile.DynamicProfileLanguageModelSession.DynamicProfile.ProfileLanguageModelSession.DynamicProfile.SessionProperty
Transforming the history
Observing life cycle modifiers
onActivate(perform:)onDeactivate(perform:)onPrompt(perform:)onResponse(perform:)onToolCall(perform:)onToolOutput(perform:)