Contents

onDeactivate(perform:)

Runs an action when this dynamic profile becomes inactive.

Declaration

func onDeactivate(perform action: sending @escaping @isolated(any) () async -> Void) -> some LanguageModelSession.DynamicProfile

Mentioned in

Discussion

A profile becomes inactive when it is no longer included in the session’s resolved configuration after previously being active. Use this to tear down state tied to the profile’s lifecycle:

struct MyDynamicProfile: LanguageModelSession.DynamicProfile {
  var body: some LanguageModelSession.DynamicProfile {
    Profile {
      Instructions("You are a helpful assistant.")
    }
    .onDeactivate {
      activeProfile = nil
    }
  }
}

See Also

Observing life cycle modifiers