diff --git a/internal/builders/agent_run_log_builder.go b/internal/builders/agent_run_log_builder.go index 8eeed79..f6b0720 100644 --- a/internal/builders/agent_run_log_builder.go +++ b/internal/builders/agent_run_log_builder.go @@ -3,6 +3,7 @@ package builders import ( "cs-agent/internal/models" "cs-agent/internal/pkg/dto/response" + "encoding/json" "strings" ) @@ -11,38 +12,65 @@ func BuildAgentRunLog(item *models.AgentRunLog) response.AgentRunLogResponse { return response.AgentRunLogResponse{} } hitlStatus, hitlStatusName, hitlSummary := resolveAgentRunLogHITL(item) + recommendedAction, riskLevel, ticketDraftReady := resolveGraphOutcome(item.GraphToolTrace) return response.AgentRunLogResponse{ - ID: item.ID, - ConversationID: item.ConversationID, - MessageID: item.MessageID, - AIAgentID: item.AIAgentID, - AIConfigID: item.AIConfigID, - UserMessage: item.UserMessage, - PlannedAction: item.PlannedAction, - PlannedSkillCode: item.PlannedSkillCode, - PlannedSkillName: item.PlannedSkillName, - SkillRouteTrace: item.SkillRouteTrace, - ToolSearchTrace: item.ToolSearchTrace, - GraphToolTrace: item.GraphToolTrace, - GraphToolCode: item.GraphToolCode, - HandoffReason: item.HandoffReason, - PlannedToolCode: item.PlannedToolCode, - PlanReason: item.PlanReason, - InterruptType: item.InterruptType, - ResumeSource: item.ResumeSource, - HitlStatus: hitlStatus, - HitlStatusName: hitlStatusName, - HitlSummary: hitlSummary, - FinalAction: item.FinalAction, - FinalStatus: item.FinalStatus, - ReplyText: item.ReplyText, - ErrorMessage: item.ErrorMessage, - LatencyMs: item.LatencyMs, - TraceData: item.TraceData, - CreatedAt: item.CreatedAt.Format("2006-01-02 15:04:05"), + ID: item.ID, + ConversationID: item.ConversationID, + MessageID: item.MessageID, + AIAgentID: item.AIAgentID, + AIConfigID: item.AIConfigID, + UserMessage: item.UserMessage, + PlannedAction: item.PlannedAction, + PlannedSkillCode: item.PlannedSkillCode, + PlannedSkillName: item.PlannedSkillName, + SkillRouteTrace: item.SkillRouteTrace, + ToolSearchTrace: item.ToolSearchTrace, + GraphToolTrace: item.GraphToolTrace, + GraphToolCode: item.GraphToolCode, + RecommendedAction: recommendedAction, + RiskLevel: riskLevel, + TicketDraftReady: ticketDraftReady, + HandoffReason: item.HandoffReason, + PlannedToolCode: item.PlannedToolCode, + PlanReason: item.PlanReason, + InterruptType: item.InterruptType, + ResumeSource: item.ResumeSource, + HitlStatus: hitlStatus, + HitlStatusName: hitlStatusName, + HitlSummary: hitlSummary, + FinalAction: item.FinalAction, + FinalStatus: item.FinalStatus, + ReplyText: item.ReplyText, + ErrorMessage: item.ErrorMessage, + LatencyMs: item.LatencyMs, + TraceData: item.TraceData, + CreatedAt: item.CreatedAt.Format("2006-01-02 15:04:05"), } } +func resolveGraphOutcome(raw string) (recommendedAction, riskLevel string, ticketDraftReady bool) { + raw = strings.TrimSpace(raw) + if raw == "" { + return "", "", false + } + var payload struct { + Items []struct { + RecommendedAction string `json:"recommendedAction"` + RiskLevel string `json:"riskLevel"` + TicketDraftReady bool `json:"ticketDraftReady"` + } `json:"items"` + } + if err := json.Unmarshal([]byte(raw), &payload); err != nil { + return "", "", false + } + for _, item := range payload.Items { + if strings.TrimSpace(item.RecommendedAction) != "" || strings.TrimSpace(item.RiskLevel) != "" || item.TicketDraftReady { + return strings.TrimSpace(item.RecommendedAction), strings.TrimSpace(item.RiskLevel), item.TicketDraftReady + } + } + return "", "", false +} + func resolveAgentRunLogHITL(item *models.AgentRunLog) (status, statusName, summary string) { if item == nil { return "", "", "" diff --git a/internal/pkg/dto/response/skill_response.go b/internal/pkg/dto/response/skill_response.go index 16f4a96..f7f5b9f 100644 --- a/internal/pkg/dto/response/skill_response.go +++ b/internal/pkg/dto/response/skill_response.go @@ -42,34 +42,37 @@ type SkillDebugRunResponse struct { } type AgentRunLogResponse struct { - ID int64 `json:"id"` - ConversationID int64 `json:"conversationId"` - MessageID int64 `json:"messageId"` - AIAgentID int64 `json:"aiAgentId"` - AIConfigID int64 `json:"aiConfigId"` - UserMessage string `json:"userMessage"` - PlannedAction string `json:"plannedAction"` - PlannedSkillCode string `json:"plannedSkillCode"` - PlannedSkillName string `json:"plannedSkillName"` - SkillRouteTrace string `json:"skillRouteTrace"` - ToolSearchTrace string `json:"toolSearchTrace"` - GraphToolTrace string `json:"graphToolTrace"` - GraphToolCode string `json:"graphToolCode"` - HandoffReason string `json:"handoffReason"` - PlannedToolCode string `json:"plannedToolCode"` - PlanReason string `json:"planReason"` - InterruptType string `json:"interruptType"` - ResumeSource string `json:"resumeSource"` - HitlStatus string `json:"hitlStatus"` - HitlStatusName string `json:"hitlStatusName"` - HitlSummary string `json:"hitlSummary"` - FinalAction string `json:"finalAction"` - FinalStatus string `json:"finalStatus"` - ReplyText string `json:"replyText"` - ErrorMessage string `json:"errorMessage"` - LatencyMs int64 `json:"latencyMs"` - TraceData string `json:"traceData"` - CreatedAt string `json:"createdAt"` + ID int64 `json:"id"` + ConversationID int64 `json:"conversationId"` + MessageID int64 `json:"messageId"` + AIAgentID int64 `json:"aiAgentId"` + AIConfigID int64 `json:"aiConfigId"` + UserMessage string `json:"userMessage"` + PlannedAction string `json:"plannedAction"` + PlannedSkillCode string `json:"plannedSkillCode"` + PlannedSkillName string `json:"plannedSkillName"` + SkillRouteTrace string `json:"skillRouteTrace"` + ToolSearchTrace string `json:"toolSearchTrace"` + GraphToolTrace string `json:"graphToolTrace"` + GraphToolCode string `json:"graphToolCode"` + RecommendedAction string `json:"recommendedAction"` + RiskLevel string `json:"riskLevel"` + TicketDraftReady bool `json:"ticketDraftReady"` + HandoffReason string `json:"handoffReason"` + PlannedToolCode string `json:"plannedToolCode"` + PlanReason string `json:"planReason"` + InterruptType string `json:"interruptType"` + ResumeSource string `json:"resumeSource"` + HitlStatus string `json:"hitlStatus"` + HitlStatusName string `json:"hitlStatusName"` + HitlSummary string `json:"hitlSummary"` + FinalAction string `json:"finalAction"` + FinalStatus string `json:"finalStatus"` + ReplyText string `json:"replyText"` + ErrorMessage string `json:"errorMessage"` + LatencyMs int64 `json:"latencyMs"` + TraceData string `json:"traceData"` + CreatedAt string `json:"createdAt"` } type AgentRunGraphSummaryResponse struct { diff --git a/web/app/(console)/agent-run-logs/page.tsx b/web/app/(console)/agent-run-logs/page.tsx index edfc834..3941d44 100644 --- a/web/app/(console)/agent-run-logs/page.tsx +++ b/web/app/(console)/agent-run-logs/page.tsx @@ -440,6 +440,13 @@ export default function DashboardAgentRunLogsPage() { 转人工原因:{item.handoffReason} ) : null} + {item.recommendedAction ? ( +