---
title: "onActivate(perform:)"
framework: foundationmodels
role: symbol
role_heading: Instance Method
path: "foundationmodels/languagemodelsession/dynamicprofile/onactivate(perform:)"
---

# onActivate(perform:)

Runs an action when this dynamic profile becomes active.

## Declaration

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

```

## Mentioned in

Composing dynamic sessions with instructions and profiles

## Discussion

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"     }   } }

## See Also

### Observing life cycle modifiers

- [onDeactivate(perform:)](foundationmodels/languagemodelsession/dynamicprofile/ondeactivate(perform:).md)
- [onPrompt(perform:)](foundationmodels/languagemodelsession/dynamicprofile/onprompt(perform:).md)
- [onResponse(perform:)](foundationmodels/languagemodelsession/dynamicprofile/onresponse(perform:).md)
- [onToolCall(perform:)](foundationmodels/languagemodelsession/dynamicprofile/ontoolcall(perform:).md)
- [onToolOutput(perform:)](foundationmodels/languagemodelsession/dynamicprofile/ontooloutput(perform:).md)
