feat: Enhance AI Agent and Channel Management
- Updated labels in the AI Agents dashboard for clarity, changing "流程状态" to "Playbook 状态" and "未发布流程" to "未发布 Playbook". - Introduced AI Agent rollout percentage management in channel editing, allowing users to set and rollback rollout percentages. - Added new API endpoints for rolling back AI Agent rollout and fetching agent run metrics. - Implemented new UI components for displaying agent run details, including status, duration, and input/output tokens. - Enhanced type definitions for AdminChannel and AIAgent to include rollout percentages and runtime modes. - Updated navigation to include a section for agent runs. - Added new translations for agent run features in both English and Chinese.
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"agent-desk/internal/models"
|
||||
"agent-desk/internal/pkg/enums"
|
||||
|
||||
@@ -13,6 +17,36 @@ func newReplyEligibility() *replyEligibility {
|
||||
return &replyEligibility{}
|
||||
}
|
||||
|
||||
// IsAIAgentRolloutEligible uses a stable conversation bucket so one customer
|
||||
// remains consistently inside or outside a gray release throughout a session.
|
||||
// Missing legacy values are treated as 100 to preserve existing behavior.
|
||||
func IsAIAgentRolloutEligible(conversation models.Conversation, aiAgent models.AIAgent, channel *models.Channel) bool {
|
||||
percent := normalizedRolloutPercent(aiAgent.RolloutPercent)
|
||||
if channel != nil {
|
||||
channelPercent := normalizedRolloutPercent(channel.AIAgentRolloutPercent)
|
||||
if channelPercent < percent {
|
||||
percent = channelPercent
|
||||
}
|
||||
}
|
||||
if percent >= 100 {
|
||||
return true
|
||||
}
|
||||
if conversation.ID <= 0 {
|
||||
return false
|
||||
}
|
||||
seed := fmt.Sprintf("channel=%d;conversation=%d;agent=%d", conversation.ChannelID, conversation.ID, aiAgent.ID)
|
||||
sum := sha256.Sum256([]byte(seed))
|
||||
bucket := int(binary.BigEndian.Uint64(sum[:8]) % 100)
|
||||
return bucket < percent
|
||||
}
|
||||
|
||||
func normalizedRolloutPercent(percent int) int {
|
||||
if percent <= 0 || percent > 100 {
|
||||
return 100
|
||||
}
|
||||
return percent
|
||||
}
|
||||
|
||||
func (e *replyEligibility) CanReply(conversation models.Conversation, message models.Message, aiAgent models.AIAgent) bool {
|
||||
if message.SenderType != enums.IMSenderTypeCustomer {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user