Contents

onResponse(perform:)

Runs an action after this dynamic profile produces a response.

Declaration

func onResponse(perform action: nonisolated(nonsending) sending @escaping () async throws -> Void) -> some LanguageModelSession.DynamicProfile

Mentioned in

Discussion

When the onResponse closure throws an error, the caller’s respond or response will propagate that error.

Use this to perform cleanup or state updates when a dynamic profile completes:

struct MyDynamicProfile: LanguageModelSession.DynamicProfile {
  var body: some LanguageModelSession.DynamicProfile {
    Profile {
      Instructions("You are a helpful assistant.")
    }
    .onResponse {
      completedTasks += 1
    }
  }
}

See Also

Observing life cycle modifiers