onActivate(perform:)
Runs an action when this dynamic profile becomes active.
Declaration
func onActivate(perform action: sending @escaping @isolated(any) () async -> Void) -> some LanguageModelSession.DynamicProfile
Mentioned in
Discussion
A profile becomes active when it is first included in the session’s resolved configuration, or when it is re-included after being absent. Use this to set up state tied to the profile’s lifecycle:
struct MyDynamicProfile: LanguageModelSession.DynamicProfile {
var body: some LanguageModelSession.DynamicProfile {
Profile {
Instructions("You are a helpful assistant.")
}
.onActivate {
activeProfile = "assistant"
}
}
}