Retain native prompt execution evidence
This commit is contained in:
@@ -9,47 +9,11 @@ import (
|
||||
pk "go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
// TokenCount retains the distinction between zero and unavailable usage.
|
||||
type TokenCount struct {
|
||||
Value int `json:"value"`
|
||||
Known bool `json:"known"`
|
||||
Complete bool `json:"complete"`
|
||||
}
|
||||
|
||||
type Usage struct {
|
||||
Prompt TokenCount `json:"prompt"`
|
||||
Completion TokenCount `json:"completion"`
|
||||
Total TokenCount `json:"total"`
|
||||
Cached TokenCount `json:"cached"`
|
||||
CacheWrite TokenCount `json:"cache_write"`
|
||||
}
|
||||
|
||||
// ExecutionObservation contains execution metadata only. It never contains
|
||||
// endpoint URLs, credentials, messages, provider errors, or generated text.
|
||||
// ExecutionObservation combines an Audita logical call with native execution evidence.
|
||||
type ExecutionObservation struct {
|
||||
CallID uint64 `json:"call_id"`
|
||||
Context structuredoutput.DiagnosticContext `json:"context"`
|
||||
Kind string `json:"kind"`
|
||||
RunID string `json:"run_id,omitempty"`
|
||||
Time time.Time `json:"time"`
|
||||
BackendID string `json:"backend_id,omitempty"`
|
||||
ProfileID string `json:"profile_id,omitempty"`
|
||||
Model string `json:"model,omitempty"`
|
||||
Generation uint64 `json:"generation,omitempty"`
|
||||
Attempt uint64 `json:"attempt,omitempty"`
|
||||
Dispatched bool `json:"dispatched"`
|
||||
CapacityWait time.Duration `json:"capacity_wait_ns"`
|
||||
GenerationDuration time.Duration `json:"generation_duration_ns"`
|
||||
RetryDelay time.Duration `json:"retry_delay_ns"`
|
||||
Duration time.Duration `json:"duration_ns"`
|
||||
Outcome string `json:"outcome,omitempty"`
|
||||
Failure string `json:"failure,omitempty"`
|
||||
StatusCode int `json:"status_code,omitempty"`
|
||||
RetriesExhausted bool `json:"retries_exhausted,omitempty"`
|
||||
Attempts uint64 `json:"attempts"`
|
||||
TransientRetries uint64 `json:"transient_retries"`
|
||||
StructuralRepairs uint64 `json:"structural_repairs"`
|
||||
Usage Usage `json:"usage"`
|
||||
CallID uint64 `json:"call_id"`
|
||||
Context structuredoutput.DiagnosticContext `json:"context"`
|
||||
PromptKit pk.ExecutionEvent `json:"promptkit"`
|
||||
}
|
||||
|
||||
type LogicalCall struct {
|
||||
@@ -70,12 +34,8 @@ type ObservationSnapshot struct {
|
||||
}
|
||||
|
||||
type ExecutionSummary struct {
|
||||
TerminalCoverageComplete bool `json:"terminal_coverage_complete"`
|
||||
LogicalCalls uint64 `json:"logical_calls"`
|
||||
ProviderAttempts uint64 `json:"provider_attempts"`
|
||||
TransientRetries uint64 `json:"transient_retries"`
|
||||
StructuralRepairs uint64 `json:"structural_repairs"`
|
||||
Usage Usage `json:"usage"`
|
||||
LogicalCalls uint64 `json:"logical_calls"`
|
||||
PromptKit pk.ExecutionGroupSummary `json:"promptkit"`
|
||||
}
|
||||
|
||||
// ObservationCollector accepts short synchronous callbacks from parallel calls.
|
||||
@@ -140,22 +100,10 @@ func (c *ObservationCollector) recordEvent(callID uint64, context structuredoutp
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
c.group.Observe(event)
|
||||
count := func(value pk.ObservedTokenCount) TokenCount {
|
||||
return TokenCount{Value: value.Value, Known: value.Known, Complete: value.Complete}
|
||||
}
|
||||
observation := ExecutionObservation{
|
||||
CallID: callID, Context: copyContext(context), Kind: string(event.Kind), RunID: event.RunID,
|
||||
Time: event.Time, BackendID: event.BackendID, ProfileID: event.ProfileID, Model: event.Model,
|
||||
Generation: event.Generation, Attempt: event.Attempt, Dispatched: event.Dispatched,
|
||||
CapacityWait: event.CapacityWait, GenerationDuration: event.GenerationDuration, RetryDelay: event.RetryDelay, Duration: event.Duration,
|
||||
Outcome: string(event.Outcome), Failure: string(event.Failure), StatusCode: event.StatusCode, RetriesExhausted: event.RetriesExhausted,
|
||||
Attempts: event.Attempts, TransientRetries: event.TransientRetries, StructuralRepairs: event.RepairCalls,
|
||||
Usage: Usage{Prompt: count(event.Usage.PromptTokens), Completion: count(event.Usage.CompletionTokens), Total: count(event.Usage.TotalTokens), Cached: count(event.Usage.CachedTokens), CacheWrite: count(event.Usage.CacheWriteTokens)},
|
||||
}
|
||||
c.mu.Lock()
|
||||
c.events = append(c.events, observation)
|
||||
c.mu.Unlock()
|
||||
defer c.mu.Unlock()
|
||||
c.group.Observe(event)
|
||||
c.events = append(c.events, ExecutionObservation{CallID: callID, Context: copyContext(context), PromptKit: event})
|
||||
}
|
||||
|
||||
func (c *ObservationCollector) Snapshot() ObservationSnapshot {
|
||||
@@ -178,7 +126,7 @@ func (c *ObservationCollector) Snapshot() ObservationSnapshot {
|
||||
if snapshot.Events[i].CallID != snapshot.Events[j].CallID {
|
||||
return snapshot.Events[i].CallID < snapshot.Events[j].CallID
|
||||
}
|
||||
return snapshot.Events[i].Time.Before(snapshot.Events[j].Time)
|
||||
return snapshot.Events[i].PromptKit.Time.Before(snapshot.Events[j].PromptKit.Time)
|
||||
})
|
||||
group := c.group.Snapshot()
|
||||
snapshot.Group = &group
|
||||
@@ -188,20 +136,14 @@ func (c *ObservationCollector) Snapshot() ObservationSnapshot {
|
||||
// Summarize delegates deduplication and terminal accounting to PromptKit. A
|
||||
// filtered diagnostic view selects its own group; overlapping views are not additive.
|
||||
func Summarize(snapshot ObservationSnapshot) ExecutionSummary {
|
||||
summary := snapshot.Group
|
||||
if summary == nil {
|
||||
var group pk.ExecutionGroup
|
||||
count := func(c TokenCount) pk.ObservedTokenCount {
|
||||
return pk.ObservedTokenCount{Value: c.Value, Known: c.Known, Complete: c.Complete}
|
||||
}
|
||||
for _, event := range snapshot.Events {
|
||||
group.Observe(pk.ExecutionEvent{Kind: pk.ExecutionEventKind(event.Kind), RunID: event.RunID, Attempts: event.Attempts, TransientRetries: event.TransientRetries, RepairCalls: event.StructuralRepairs, Usage: pk.ObservedTokenUsage{PromptTokens: count(event.Usage.Prompt), CompletionTokens: count(event.Usage.Completion), TotalTokens: count(event.Usage.Total), CachedTokens: count(event.Usage.Cached), CacheWriteTokens: count(event.Usage.CacheWrite)}})
|
||||
}
|
||||
value := group.Snapshot()
|
||||
summary = &value
|
||||
if snapshot.Group != nil {
|
||||
group := *snapshot.Group
|
||||
group.Members = append([]pk.ExecutionGroupMember(nil), group.Members...)
|
||||
return ExecutionSummary{LogicalCalls: uint64(len(snapshot.Calls)), PromptKit: group}
|
||||
}
|
||||
count := func(c pk.ObservedTokenCount) TokenCount {
|
||||
return TokenCount{Value: c.Value, Known: c.Known, Complete: c.Complete}
|
||||
var group pk.ExecutionGroup
|
||||
for _, event := range snapshot.Events {
|
||||
group.Observe(event.PromptKit)
|
||||
}
|
||||
return ExecutionSummary{LogicalCalls: uint64(len(snapshot.Calls)), TerminalCoverageComplete: summary.TerminalCoverageComplete, ProviderAttempts: summary.Attempts, TransientRetries: summary.TransientRetries, StructuralRepairs: summary.RepairCalls, Usage: Usage{Prompt: count(summary.Usage.PromptTokens), Completion: count(summary.Usage.CompletionTokens), Total: count(summary.Usage.TotalTokens), Cached: count(summary.Usage.CachedTokens), CacheWrite: count(summary.Usage.CacheWriteTokens)}}
|
||||
return ExecutionSummary{LogicalCalls: uint64(len(snapshot.Calls)), PromptKit: group.Snapshot()}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user