18c9354095
- 注入数据库、运行时配置、统一响应、文件存储和平台 AI 能力,补充业务读写工具与客户快捷操作契约。 - 移除模块内重复的组织、客户、工单、标签、技能、旧工作流、MCP 和迁移实现,将身份权限与业务主体交由宿主管理。 - 使用 libSQL 重构向量存储,并完善图片消息、访客身份、排队调度、企业微信和支持聊天页面。 - 统一 HTTP、DTO 与 WebSocket 的 snake_case 协议,补齐模块初始化、业务动作和公共载荷等回归测试。
71 lines
2.3 KiB
Go
71 lines
2.3 KiB
Go
package graphs
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
|
"code.tczkiot.com/wlw/ai-agent/internal/services"
|
|
)
|
|
|
|
type TriageServiceRequestInput struct {
|
|
Goal string `json:"goal"`
|
|
ObservedIssue string `json:"observed_issue"`
|
|
NeedHumanHandoff bool `json:"need_human_handoff"`
|
|
AdditionalContext string `json:"additional_context"`
|
|
}
|
|
|
|
type TriageServiceRequestResult struct {
|
|
Analysis AnalyzeConversationResult `json:"analysis"`
|
|
RecommendedAction string `json:"recommended_action"`
|
|
Ready bool `json:"ready"`
|
|
}
|
|
|
|
type TriageServiceRequestGraph struct {
|
|
conversation models.Conversation
|
|
}
|
|
|
|
func NewTriageServiceRequestGraph(conversation models.Conversation) *TriageServiceRequestGraph {
|
|
return &TriageServiceRequestGraph{conversation: conversation}
|
|
}
|
|
|
|
func (g *TriageServiceRequestGraph) Run(_ context.Context, argumentsInJSON string) (string, error) {
|
|
input, err := g.parseInput(argumentsInJSON)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
messages, _, _ := services.MessageService.FindByConversationIDCursor(g.conversation.ID, 0, 8, "", "")
|
|
analysis := buildAnalyzeConversationResult(g.conversation, messages, AnalyzeConversationInput{
|
|
Goal: input.Goal,
|
|
ObservedIssue: input.ObservedIssue,
|
|
NeedHumanHandoff: input.NeedHumanHandoff,
|
|
AdditionalContext: input.AdditionalContext,
|
|
})
|
|
result := TriageServiceRequestResult{
|
|
Analysis: analysis,
|
|
RecommendedAction: analysis.RecommendedNextAction,
|
|
Ready: analysis.RecommendedNextAction == "continue_answering" || analysis.RecommendedNextAction == "handoff_to_human",
|
|
}
|
|
buf, err := json.Marshal(result)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(buf), nil
|
|
}
|
|
|
|
func (g *TriageServiceRequestGraph) parseInput(argumentsInJSON string) (TriageServiceRequestInput, error) {
|
|
var input TriageServiceRequestInput
|
|
if strings.TrimSpace(argumentsInJSON) == "" {
|
|
return input, nil
|
|
}
|
|
if err := json.Unmarshal([]byte(argumentsInJSON), &input); err != nil {
|
|
return input, fmt.Errorf("invalid triage service request arguments: %w", err)
|
|
}
|
|
input.Goal = strings.TrimSpace(input.Goal)
|
|
input.ObservedIssue = strings.TrimSpace(input.ObservedIssue)
|
|
input.AdditionalContext = strings.TrimSpace(input.AdditionalContext)
|
|
return input, nil
|
|
}
|