feat: remove fallback mode and max AI reply rounds from AIAgent model and related components
This commit is contained in:
@@ -3,6 +3,8 @@ package registry
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"cs-agent/internal/pkg/toolx"
|
||||
|
||||
einotool "github.com/cloudwego/eino/components/tool"
|
||||
)
|
||||
|
||||
@@ -28,7 +30,7 @@ func (r *Registry) Resolve(ctx Context) (*ToolSet, error) {
|
||||
}
|
||||
toolCode := strings.TrimSpace(toolDef.Code())
|
||||
if len(allowedToolCodes) > 0 {
|
||||
if _, ok := allowedToolCodes[toolCode]; !ok {
|
||||
if _, ok := allowedToolCodes[toolCode]; !ok && !isAlwaysAllowedToolCode(toolCode) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
@@ -63,3 +65,7 @@ func makeAllowedToolCodeSet(input []string) map[string]struct{} {
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func isAlwaysAllowedToolCode(toolCode string) bool {
|
||||
return strings.TrimSpace(toolCode) == toolx.GraphHandoffConversationToolCode
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ func (s *service) prepareToolsForRun(req *Request) error {
|
||||
AIAgent: req.AIAgent,
|
||||
AIConfig: req.AIConfig,
|
||||
UserMessage: req.UserMessage,
|
||||
AllowedToolCodes: ensureCoreGraphToolCodes(resolveAllowedToolCodes(req.AIAgent, req.SelectedSkill)),
|
||||
AllowedToolCodes: resolveAllowedToolCodes(req.AIAgent, req.SelectedSkill),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -113,7 +113,7 @@ func (s *service) prepareToolsForResume(req *ResumeRequest) error {
|
||||
Conversation: req.Conversation,
|
||||
AIAgent: req.AIAgent,
|
||||
AIConfig: req.AIConfig,
|
||||
AllowedToolCodes: ensureCoreGraphToolCodes(parseAgentAllowedToolCodes(req.AIAgent)),
|
||||
AllowedToolCodes: parseAgentAllowedToolCodes(req.AIAgent),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -281,18 +281,3 @@ func resolveAllowedToolCodes(aiAgent *models.AIAgent, skill *models.SkillDefinit
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
func ensureCoreGraphToolCodes(toolCodes []string) []string {
|
||||
if len(toolCodes) == 0 {
|
||||
return nil
|
||||
}
|
||||
ret := make([]string, 0, len(toolCodes)+1)
|
||||
ret = append(ret, toolCodes...)
|
||||
for _, item := range ret {
|
||||
if strings.TrimSpace(item) == toolx.GraphHandoffConversationToolCode {
|
||||
return ret
|
||||
}
|
||||
}
|
||||
ret = append(ret, toolx.GraphHandoffConversationToolCode)
|
||||
return ret
|
||||
}
|
||||
|
||||
@@ -124,9 +124,6 @@ func buildAIAgentResponse(item *models.AIAgent) response.AIAgentResponse {
|
||||
ReplyTimeoutSeconds: item.ReplyTimeoutSeconds,
|
||||
HandoffMode: item.HandoffMode,
|
||||
HandoffModeName: enums.GetAIAgentHandoffModeLabel(item.HandoffMode),
|
||||
MaxAIReplyRounds: item.MaxAIReplyRounds,
|
||||
FallbackMode: item.FallbackMode,
|
||||
FallbackModeName: enums.GetAIAgentFallbackModeLabel(item.FallbackMode),
|
||||
FallbackMessage: item.FallbackMessage,
|
||||
KnowledgeIDs: utils.SplitInt64s(item.KnowledgeIDs),
|
||||
SkillIDs: utils.SplitInt64s(item.SkillIDs),
|
||||
|
||||
@@ -510,8 +510,6 @@ type AIAgent struct {
|
||||
ReplyTimeoutSeconds int `gorm:"type:int;not null;default:180"` // ReplyTimeoutSeconds 为异步自动回复超时秒数。
|
||||
TeamIDs string `gorm:"type:varchar(500);not null;default:''"` // TeamIDs 为转人工时可路由的客服组ID列表,多个之间使用逗号分隔。
|
||||
HandoffMode enums.AIAgentHandoffMode `gorm:"type:int;not null;default:1"` // HandoffMode 为转人工模式,如进入待接入池、进入默认客服组待接入池。
|
||||
MaxAIReplyRounds int `gorm:"type:int;not null;default:2"` // MaxAIReplyRounds 为单个会话允许的 AI 最大成功回复次数,超过后强制转人工。
|
||||
FallbackMode enums.AIAgentFallbackMode `gorm:"type:int;not null;default:2"` // FallbackMode 为无答案或低置信度时的兜底模式。
|
||||
FallbackMessage string `gorm:"type:text"` // FallbackMessage 为兜底回复文案。
|
||||
KnowledgeIDs string `gorm:"type:varchar(500);not null;default:''"` // KnowledgeIDs 为绑定的知识库ID列表,按顺序表示优先级。
|
||||
SkillIDs string `gorm:"type:varchar(500);not null;default:''"` // SkillIDs 为绑定的技能ID列表,按顺序表示允许路由的范围。
|
||||
|
||||
@@ -52,8 +52,6 @@ type CreateAIAgentRequest struct {
|
||||
ReplyTimeoutSeconds int `json:"replyTimeoutSeconds"`
|
||||
TeamIDs []int64 `json:"teamIds"`
|
||||
HandoffMode enums.AIAgentHandoffMode `json:"handoffMode"`
|
||||
MaxAIReplyRounds int `json:"maxAiReplyRounds"`
|
||||
FallbackMode enums.AIAgentFallbackMode `json:"fallbackMode"`
|
||||
FallbackMessage string `json:"fallbackMessage"`
|
||||
KnowledgeIDs []int64 `json:"knowledgeIds"`
|
||||
SkillIDs []int64 `json:"skillIds"`
|
||||
|
||||
@@ -83,9 +83,6 @@ type AIAgentResponse struct {
|
||||
Teams []AIAgentTeamResponse `json:"teams"`
|
||||
HandoffMode enums.AIAgentHandoffMode `json:"handoffMode"`
|
||||
HandoffModeName string `json:"handoffModeName"`
|
||||
MaxAIReplyRounds int `json:"maxAiReplyRounds"`
|
||||
FallbackMode enums.AIAgentFallbackMode `json:"fallbackMode"`
|
||||
FallbackModeName string `json:"fallbackModeName"`
|
||||
FallbackMessage string `json:"fallbackMessage"`
|
||||
KnowledgeIDs []int64 `json:"knowledgeIds"`
|
||||
KnowledgeBaseNames []string `json:"knowledgeBaseNames"`
|
||||
|
||||
@@ -212,30 +212,6 @@ func GetAIAgentHandoffModeLabel(mode AIAgentHandoffMode) string {
|
||||
return aiAgentHandoffModeLabelMap[mode]
|
||||
}
|
||||
|
||||
type AIAgentFallbackMode int
|
||||
|
||||
const (
|
||||
AIAgentFallbackModeNoAnswer AIAgentFallbackMode = 1
|
||||
AIAgentFallbackModeGuideRephrase AIAgentFallbackMode = 2
|
||||
AIAgentFallbackModeHandoff AIAgentFallbackMode = 3
|
||||
)
|
||||
|
||||
var AIAgentFallbackModeValues = []AIAgentFallbackMode{
|
||||
AIAgentFallbackModeNoAnswer,
|
||||
AIAgentFallbackModeGuideRephrase,
|
||||
AIAgentFallbackModeHandoff,
|
||||
}
|
||||
|
||||
var aiAgentFallbackModeLabelMap = map[AIAgentFallbackMode]string{
|
||||
AIAgentFallbackModeNoAnswer: "直接声明无答案",
|
||||
AIAgentFallbackModeGuideRephrase: "引导补充信息或换个问法",
|
||||
AIAgentFallbackModeHandoff: "直接转人工",
|
||||
}
|
||||
|
||||
func GetAIAgentFallbackModeLabel(mode AIAgentFallbackMode) string {
|
||||
return aiAgentFallbackModeLabelMap[mode]
|
||||
}
|
||||
|
||||
const (
|
||||
IMRealtimeEventConnected = "connected"
|
||||
IMRealtimeEventPong = "pong"
|
||||
|
||||
@@ -101,8 +101,6 @@ func (s *aIAgentService) UpdateAIAgent(req request.UpdateAIAgentRequest, operato
|
||||
"reply_timeout_seconds": item.ReplyTimeoutSeconds,
|
||||
"team_ids": item.TeamIDs,
|
||||
"handoff_mode": item.HandoffMode,
|
||||
"max_ai_reply_rounds": item.MaxAIReplyRounds,
|
||||
"fallback_mode": item.FallbackMode,
|
||||
"fallback_message": item.FallbackMessage,
|
||||
"knowledge_ids": item.KnowledgeIDs,
|
||||
"skill_ids": item.SkillIDs,
|
||||
@@ -162,10 +160,6 @@ func (s *aIAgentService) buildAIAgentModel(id int64, req request.CreateAIAgentRe
|
||||
if enums.AIAgentHandoffMode(req.HandoffMode) == enums.AIAgentHandoffModeDefaultTeamPool && len(teamIDs) == 0 {
|
||||
return nil, errorsx.InvalidParam("默认客服组待接入池模式必须至少选择一个客服组")
|
||||
}
|
||||
|
||||
if !slices.Contains(enums.AIAgentFallbackModeValues, enums.AIAgentFallbackMode(req.FallbackMode)) {
|
||||
return nil, errorsx.InvalidParam("兜底模式不合法")
|
||||
}
|
||||
if req.ReplyTimeoutSeconds < 0 {
|
||||
return nil, errorsx.InvalidParam("回复超时秒数不能小于 0")
|
||||
}
|
||||
@@ -203,8 +197,6 @@ func (s *aIAgentService) buildAIAgentModel(id int64, req request.CreateAIAgentRe
|
||||
ReplyTimeoutSeconds: req.ReplyTimeoutSeconds,
|
||||
TeamIDs: utils.JoinInt64s(teamIDs),
|
||||
HandoffMode: req.HandoffMode,
|
||||
MaxAIReplyRounds: req.MaxAIReplyRounds,
|
||||
FallbackMode: req.FallbackMode,
|
||||
FallbackMessage: strings.TrimSpace(req.FallbackMessage),
|
||||
KnowledgeIDs: utils.JoinInt64s(knowledgeIDs),
|
||||
SkillIDs: utils.JoinInt64s(skillIDs),
|
||||
|
||||
Reference in New Issue
Block a user