| 178 | } |
| 179 | |
| 180 | func deriveRunAgenticAnalysis(processedRun ProcessedRun, metrics LogMetrics) (*AwContext, []ToolUsageInfo, []CreatedItemReport, *TaskDomainInfo, *BehaviorFingerprint, []AgenticAssessment) { |
| 181 | auditAgenticLog.Printf("Deriving agentic analysis for run: id=%d workflow=%s", processedRun.Run.DatabaseID, processedRun.Run.WorkflowName) |
| 182 | var awContext *AwContext |
| 183 | if processedRun.AwContext != nil { |
| 184 | awContext = processedRun.AwContext |
| 185 | } else if processedRun.Run.LogsPath != "" { |
| 186 | awInfoPath := filepath.Join(processedRun.Run.LogsPath, "aw_info.json") |
| 187 | if info, err := parseAwInfo(awInfoPath, false); err == nil && info != nil { |
| 188 | awContext = info.Context |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | toolUsage := buildToolUsageInfo(metrics) |
| 193 | createdItems := extractCreatedItemsFromManifest(processedRun.Run.LogsPath) |
| 194 | metricsData := MetricsData{ |
| 195 | TokenUsage: processedRun.Run.TokenUsage, |
| 196 | ActionMinutes: processedRun.Run.ActionMinutes, |
| 197 | Turns: processedRun.Run.Turns, |
| 198 | ErrorCount: processedRun.Run.ErrorCount, |
| 199 | WarningCount: processedRun.Run.WarningCount, |
| 200 | } |
| 201 | |
| 202 | taskDomain := detectTaskDomain(processedRun, createdItems, toolUsage, awContext) |
| 203 | behaviorFingerprint := buildBehaviorFingerprint(processedRun, metricsData, toolUsage, createdItems, awContext) |
| 204 | agenticAssessments := buildAgenticAssessments(processedRun, metricsData, toolUsage, createdItems, taskDomain, behaviorFingerprint, awContext) |
| 205 | |
| 206 | auditAgenticLog.Printf("Agentic analysis complete: tool_types=%d created_items=%d assessments=%d", len(toolUsage), len(createdItems), len(agenticAssessments)) |
| 207 | return awContext, toolUsage, createdItems, taskDomain, behaviorFingerprint, agenticAssessments |
| 208 | } |
| 209 | |
| 210 | func detectTaskDomain(processedRun ProcessedRun, createdItems []CreatedItemReport, toolUsage []ToolUsageInfo, awContext *AwContext) *TaskDomainInfo { |
| 211 | auditAgenticLog.Printf("Detecting task domain for run: workflow=%s event=%s", processedRun.Run.WorkflowName, processedRun.Run.Event) |