Retain processing evidence only for selected outputs
This commit is contained in:
@@ -64,6 +64,7 @@ func (c *RoleClient) prepareCall(parent context.Context, req structuredoutput.Re
|
||||
var terminal pk.ExecutionEvent
|
||||
var terminalAvailable bool
|
||||
var prepared *structuredoutput.PreparedSnapshot
|
||||
var prompt structuredoutput.PromptMetadata
|
||||
var record structuredoutput.CallRecord
|
||||
if c.hooks.OnCall != nil || c.hooks.OnEventWithCall != nil {
|
||||
record.CallID = c.runtime.nextCallID.Add(1)
|
||||
@@ -90,19 +91,19 @@ func (c *RoleClient) prepareCall(parent context.Context, req structuredoutput.Re
|
||||
response.Execution.HTTPStatus = &status
|
||||
}
|
||||
}
|
||||
if prepared != nil {
|
||||
response.Prepared = prepared
|
||||
response.Prompt = prepared.Prompt
|
||||
response.Model = prepared.Prompt.Model
|
||||
}
|
||||
response.Prepared = prepared
|
||||
response.Prompt = prompt
|
||||
response.Model = prompt.Model
|
||||
mu.Unlock()
|
||||
if result != nil {
|
||||
response.FinalContent = result.RawOutput
|
||||
if req.CaptureDiagnostics {
|
||||
response.FinalContent = result.RawOutput
|
||||
}
|
||||
response.Model = result.ModelName
|
||||
}
|
||||
err := c.finishResponse(parent, &response, result, runErr, out)
|
||||
if onCall := c.hooks.OnCall; onCall != nil {
|
||||
if response.Prepared != nil {
|
||||
if response.Prompt.PromptID != "" {
|
||||
record.Prompt = response.Prompt
|
||||
}
|
||||
record.Finished = time.Now().UTC()
|
||||
@@ -146,12 +147,18 @@ func (c *RoleClient) prepareCall(parent context.Context, req structuredoutput.Re
|
||||
c.hooks.OnEventWithCall(record.CallID, record.Context, event)
|
||||
}
|
||||
}),
|
||||
OnPrepared: func(_ context.Context, details pk.PreparedRun) {
|
||||
snapshot := preparedSnapshot(details)
|
||||
}
|
||||
if req.CaptureDiagnostics || c.hooks.OnCall != nil {
|
||||
call.request.OnPrepared = func(_ context.Context, details pk.PreparedRun) {
|
||||
metadata := promptMetadata(details)
|
||||
var snapshot *structuredoutput.PreparedSnapshot
|
||||
if req.CaptureDiagnostics {
|
||||
snapshot = &structuredoutput.PreparedSnapshot{Messages: convertMessages(details.Messages), Prompt: metadata}
|
||||
}
|
||||
mu.Lock()
|
||||
prepared = snapshot
|
||||
prepared, prompt = snapshot, metadata
|
||||
mu.Unlock()
|
||||
},
|
||||
}
|
||||
}
|
||||
return call, nil
|
||||
}
|
||||
@@ -290,11 +297,6 @@ func promptMetadata(details pk.PreparedRun) structuredoutput.PromptMetadata {
|
||||
}
|
||||
}
|
||||
|
||||
func preparedSnapshot(details pk.PreparedRun) *structuredoutput.PreparedSnapshot {
|
||||
messages := convertMessages(details.Messages)
|
||||
return &structuredoutput.PreparedSnapshot{Messages: messages, Prompt: promptMetadata(details)}
|
||||
}
|
||||
|
||||
func convertMessages(messages []pk.RenderedMessage) []structuredoutput.Message {
|
||||
result := make([]structuredoutput.Message, len(messages))
|
||||
for i, message := range messages {
|
||||
|
||||
Reference in New Issue
Block a user