Use native contexts for execution observation
This commit is contained in:
@@ -104,7 +104,7 @@ func RunProducer[T any](
|
||||
}
|
||||
}
|
||||
|
||||
request := producerRequest(initial, operation.Execution, true)
|
||||
request := producerRequest(initial, operation.Execution)
|
||||
request.CaptureExchange = request.CaptureExchange || (correct != nil && operation.Controls.MaxAdditionalTurns > 0)
|
||||
request, capture := CaptureNativeRequest(request, scopeEvidence(operation.Execution.Capture, "initial"))
|
||||
if captureErr := capture.Err(); captureErr != nil {
|
||||
@@ -196,7 +196,7 @@ func RunProducer[T any](
|
||||
var pendingCapture *NativeCapture
|
||||
var recordingErr error
|
||||
coordination, coordinateErr := engine.Coordinate(ctx, promptkit.CoordinateRequest{
|
||||
Start: result.Exchange, AdditionalTurns: operation.Controls.MaxAdditionalTurns, Observer: operation.Execution.Observer,
|
||||
Start: result.Exchange, AdditionalTurns: operation.Controls.MaxAdditionalTurns,
|
||||
Next: func(_ context.Context, turn promptkit.ConversationTurn) (*promptkit.RunRequest, error) {
|
||||
// The first callback has no new result. Its findings already exist.
|
||||
if turn.Result != nil {
|
||||
@@ -237,7 +237,7 @@ func RunProducer[T any](
|
||||
if initial.SessionID != "" {
|
||||
next.SessionID = initial.SessionID
|
||||
}
|
||||
next = producerRequest(next, operation.Execution, false)
|
||||
next = producerRequest(next, operation.Execution)
|
||||
if operation.Execution.Capture != nil {
|
||||
next, pendingCapture = CaptureNativeRequest(next, scopeEvidence(operation.Execution.Capture, correctionPath))
|
||||
if recordingErr = pendingCapture.Err(); recordingErr != nil {
|
||||
@@ -284,19 +284,14 @@ func RunProducer[T any](
|
||||
return FinishProducerFailure(ctx, operation.Controls.Mode, failure, construct)
|
||||
}
|
||||
|
||||
// producerRequest applies native options to a value copy. The invocation
|
||||
// observer is enrolled here for the initial run and on CoordinateRequest for
|
||||
// continuations, never twice on the same continuation.
|
||||
func producerRequest(request promptkit.RunRequest, options contracts.ExecutionOptions, initial bool) promptkit.RunRequest {
|
||||
// producerRequest applies native request overrides and preparation hooks to a value copy.
|
||||
func producerRequest(request promptkit.RunRequest, options contracts.ExecutionOptions) promptkit.RunRequest {
|
||||
if options.Execution != nil {
|
||||
request.Execution = options.Execution
|
||||
}
|
||||
if options.TransientRetries != nil {
|
||||
request.TransientRetries = options.TransientRetries
|
||||
}
|
||||
if initial {
|
||||
request.Observer = promptkit.ComposeObservers(request.Observer, options.Observer)
|
||||
}
|
||||
if options.OnPrepared != nil {
|
||||
existing := request.OnPrepared
|
||||
request.OnPrepared = func(ctx context.Context, details promptkit.PreparedRun) {
|
||||
|
||||
Reference in New Issue
Block a user