Contents

onReasoning(perform:)

Runs an action whenever this dynamic profile produces reasoning.

Declaration

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

Discussion

Reasoning is only produced by models that declare the .reasoning capability.

When the onReasoning closure throws an error, the caller’s respond or response propagates that error.

Use this to observe or log the model’s reasoning as it works toward a response:

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

See Also

Observing life cycle modifiers