onPrompt(perform:)
Runs an action before the model is invoked for this dynamic profile.
Declaration
@export(implementation) func onPrompt(perform action: nonisolated(nonsending) sending @escaping () async throws -> Void) -> some LanguageModelSession.DynamicProfile
Mentioned in
Discussion
When the onPrompt closure throws an error, the caller’s respond or response propagates that error.
Use this to observe or log prompts before generation begins:
struct MyDynamicProfile: LanguageModelSession.DynamicProfile {
var body: some LanguageModelSession.DynamicProfile {
Profile {
Instructions("You are a helpful assistant.")
}
.onPrompt {
promptCount += 1
}
}
}