Contents

SessionPropertyValues

A container for property values.

Declaration

final class SessionPropertyValues

Mentioned in

Overview

Use session property values across your session. To help manage the context window, access history to modify the transcript for the session:

struct CompactingProfile: LanguageModelSession.DynamicProfile {
    @SessionProperty(\.history)
    var history

    var body: some LanguageModelSession.DynamicProfile {
        Profile {
            // Custom instructions and tools that you define.
        }
        .onResponse { _ in
            // Compact the history when the entries exceed a certain limit.
            if history.count > 100 {
                history = Array(history.suffix(50))
            }
        }
    }
}

Because updating the transcript history can cause cache invalidations for some models, carefully consider how you modify an existing transcript. For more information, see Optimizing key-value caching in language model sessions.

Use SessionPropertyEntry() to create custom session properties.

Topics

Accessing the session history and instructions

Accessing the subscript

See Also

Custom session properties