feat: add AgentRunGraphSummary and related functionality for graph summary retrieval
This commit is contained in:
@@ -58,3 +58,22 @@ func (c *AgentRunLogController) GetBy(id int64) *web.JsonResult {
|
||||
}
|
||||
return web.JsonData(builders.BuildAgentRunLog(item))
|
||||
}
|
||||
|
||||
func (c *AgentRunLogController) AnyGraphSummary() *web.JsonResult {
|
||||
if _, err := services.AuthService.RequirePermission(c.Ctx, constants.PermissionConversationView); err != nil {
|
||||
return web.JsonError(err)
|
||||
}
|
||||
aiAgentID, _ := params.GetInt64(c.Ctx, "aiAgentId")
|
||||
summary := services.AgentRunLogService.BuildGraphSummary(aiAgentID)
|
||||
return web.JsonData(&response.AgentRunGraphSummaryResponse{
|
||||
TriageCount: summary.TriageCount,
|
||||
TriagePrepareTicket: summary.TriagePrepareTicket,
|
||||
TriagePrepareTicketReady: summary.TriagePrepareTicketReady,
|
||||
TriageHandoff: summary.TriageHandoff,
|
||||
TriageContinueAnswering: summary.TriageContinueAnswering,
|
||||
AnalyzeCount: summary.AnalyzeCount,
|
||||
PrepareDraftCount: summary.PrepareDraftCount,
|
||||
CreateTicketCount: summary.CreateTicketCount,
|
||||
HandoffCount: summary.HandoffCount,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -71,3 +71,15 @@ type AgentRunLogResponse struct {
|
||||
TraceData string `json:"traceData"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
}
|
||||
|
||||
type AgentRunGraphSummaryResponse struct {
|
||||
TriageCount int64 `json:"triageCount"`
|
||||
TriagePrepareTicket int64 `json:"triagePrepareTicket"`
|
||||
TriagePrepareTicketReady int64 `json:"triagePrepareTicketReady"`
|
||||
TriageHandoff int64 `json:"triageHandoff"`
|
||||
TriageContinueAnswering int64 `json:"triageContinueAnswering"`
|
||||
AnalyzeCount int64 `json:"analyzeCount"`
|
||||
PrepareDraftCount int64 `json:"prepareDraftCount"`
|
||||
CreateTicketCount int64 `json:"createTicketCount"`
|
||||
HandoffCount int64 `json:"handoffCount"`
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package services
|
||||
|
||||
import (
|
||||
"cs-agent/internal/models"
|
||||
"cs-agent/internal/pkg/toolx"
|
||||
"cs-agent/internal/repositories"
|
||||
"strings"
|
||||
|
||||
@@ -17,6 +18,18 @@ func newAgentRunLogService() *agentRunLogService {
|
||||
|
||||
type agentRunLogService struct{}
|
||||
|
||||
type AgentRunGraphSummary struct {
|
||||
TriageCount int64
|
||||
TriagePrepareTicket int64
|
||||
TriagePrepareTicketReady int64
|
||||
TriageHandoff int64
|
||||
TriageContinueAnswering int64
|
||||
AnalyzeCount int64
|
||||
PrepareDraftCount int64
|
||||
CreateTicketCount int64
|
||||
HandoffCount int64
|
||||
}
|
||||
|
||||
func (s *agentRunLogService) Get(id int64) *models.AgentRunLog {
|
||||
return repositories.AgentRunLogRepository.Get(sqls.DB(), id)
|
||||
}
|
||||
@@ -83,3 +96,37 @@ func (s *agentRunLogService) ApplyHITLStatusFilter(cnd *sqls.Cnd, hitlStatus str
|
||||
}
|
||||
return cnd
|
||||
}
|
||||
|
||||
func (s *agentRunLogService) BuildGraphSummary(aiAgentID int64) *AgentRunGraphSummary {
|
||||
buildBaseCnd := func() *sqls.Cnd {
|
||||
cnd := sqls.NewCnd()
|
||||
if aiAgentID > 0 {
|
||||
cnd.Eq("ai_agent_id", aiAgentID)
|
||||
}
|
||||
return cnd
|
||||
}
|
||||
return &AgentRunGraphSummary{
|
||||
TriageCount: s.countByGraphTool(buildBaseCnd(), toolx.GraphTriageServiceRequestToolCode),
|
||||
TriagePrepareTicket: s.countByGraphToolAndPlanReason(buildBaseCnd(), toolx.GraphTriageServiceRequestToolCode, "%prepare_ticket%"),
|
||||
TriagePrepareTicketReady: s.countByGraphToolAndPlanReason(buildBaseCnd(), toolx.GraphTriageServiceRequestToolCode, "%prepare_ticket with ready ticket draft%"),
|
||||
TriageHandoff: s.countByGraphToolAndPlanReason(buildBaseCnd(), toolx.GraphTriageServiceRequestToolCode, "%handoff_to_human%"),
|
||||
TriageContinueAnswering: s.countByGraphToolAndPlanReason(buildBaseCnd(), toolx.GraphTriageServiceRequestToolCode, "%continue_answering%"),
|
||||
AnalyzeCount: s.countByGraphTool(buildBaseCnd(), toolx.GraphAnalyzeConversationToolCode),
|
||||
PrepareDraftCount: s.countByGraphTool(buildBaseCnd(), toolx.GraphPrepareTicketDraftToolCode),
|
||||
CreateTicketCount: s.countByGraphTool(buildBaseCnd(), toolx.GraphCreateTicketConfirmToolCode),
|
||||
HandoffCount: s.countByGraphTool(buildBaseCnd(), toolx.GraphHandoffConversationToolCode),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *agentRunLogService) countByGraphTool(baseCnd *sqls.Cnd, graphToolCode string) int64 {
|
||||
cnd := baseCnd
|
||||
cnd.Eq("graph_tool_code", strings.TrimSpace(graphToolCode))
|
||||
return s.Count(cnd)
|
||||
}
|
||||
|
||||
func (s *agentRunLogService) countByGraphToolAndPlanReason(baseCnd *sqls.Cnd, graphToolCode string, planReasonLike string) int64 {
|
||||
cnd := baseCnd
|
||||
cnd.Eq("graph_tool_code", strings.TrimSpace(graphToolCode))
|
||||
cnd.Where("plan_reason LIKE ?", strings.TrimSpace(planReasonLike))
|
||||
return s.Count(cnd)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user