fix: add structured graph tool results

This commit is contained in:
mlogclub
2026-05-10 00:02:23 +08:00
parent 59b3509ca9
commit 7a9cffe21e
10 changed files with 211 additions and 92 deletions
@@ -58,9 +58,6 @@ func (s *conversationHumanDispatchService) TryOffHoursHandoffByAI(conversationID
if err := s.createEvent(conversationID, enums.IMEventTypeTransfer, enums.IMSenderTypeAI, aiAgent.ID, "转人工失败:非服务时间", strings.TrimSpace(reason)); err != nil {
return true, err
}
if s.hasLatestAIText(conversationID, HandoffOffHoursMessage) {
return true, nil
}
if err := s.sendAIText(conversationID, aiAgent.ID, HandoffOffHoursMessage); err != nil {
return true, err
}
@@ -291,14 +288,6 @@ func (s *conversationHumanDispatchService) sendAIText(conversationID, aiAgentID
return err
}
func (s *conversationHumanDispatchService) hasLatestAIText(conversationID int64, content string) bool {
latest, err := MessageService.GetConversationReadTarget(conversationID, 0)
if err != nil || latest == nil {
return false
}
return latest.SenderType == enums.IMSenderTypeAI && strings.TrimSpace(latest.Content) == strings.TrimSpace(content)
}
func orderedPositiveIDs(value string) []int64 {
return uniquePositiveInt64sFromStrings(strings.Split(value, ","))
}
@@ -47,32 +47,6 @@ func TestConversationHumanDispatchAIHandoffOffHoursKeepsAIServingAndSendsNotice(
}
}
func TestConversationHumanDispatchAIHandoffOffHoursDoesNotDuplicateNotice(t *testing.T) {
db := setupConversationHumanDispatchTestDB(t)
aiAgent := createHumanDispatchAIAgent(t, db, enums.IMConversationServiceModeAIFirst, "1")
conversation := createHumanDispatchConversation(t, db, aiAgent.ID, enums.IMConversationStatusAIServing)
for i := 0; i < 3; i++ {
result, err := services.ConversationHumanDispatchService.HandoffByAI(conversation.ID, aiAgent, "用户要求转人工")
if err != nil {
t.Fatalf("HandoffByAI() round %d error = %v", i+1, err)
}
if result == nil || result.Decision != services.HandoffDecisionOffHours {
t.Fatalf("expected off_hours decision on round %d, got %+v", i+1, result)
}
}
var count int64
if err := db.Model(&models.Message{}).
Where("conversation_id = ? AND sender_type = ? AND content = ?", conversation.ID, enums.IMSenderTypeAI, services.HandoffOffHoursMessage).
Count(&count).Error; err != nil {
t.Fatalf("count off-hours messages error = %v", err)
}
if count != 1 {
t.Fatalf("expected one off-hours notice, got %d", count)
}
}
func TestConversationHumanDispatchAIHandoffAssignsAvailableAgent(t *testing.T) {
db := setupConversationHumanDispatchTestDB(t)
aiAgent := createHumanDispatchAIAgent(t, db, enums.IMConversationServiceModeAIFirst, "1")