Contents

DynamicInstructions

A type that represents dynamic instructions.

Declaration

protocol DynamicInstructions

Mentioned in

Overview

Dynamic instructions provide a declarative approach to assembling instructions and tools that a LanguageModelSession uses. The framework evaluates them before every request to the model, so the body can contain conditional logic that’s based on current app state.

struct PresentationInstructions: DynamicInstructions {
    // The data source for conditional instructions.
    var isEditingImage = true

    var body: some DynamicInstructions {
        // The instructions and tools that remain the same across any use of this type.
        Instructions {
            "Help people improve their presentation."
        }
        ListPhotosTool()
        AddPhotoTool()

        // Depending on the state of the app, include additional instructions
        // that provide the model with more task-specific instructions and tools.
        if isEditingImage {
            ImageEditingInstructions()
        }
    }
}

Topics

Implementing dynamic instructions

Building dynamic instructions

See Also

Dynamic profiles