Refactor AI Agent and AI Config handling across multiple files
- Updated function signatures to accept AI Agent and AI Config as non-pointer types for better clarity and safety. - Modified instances where AI Agent and AI Config were dereferenced to improve code readability. - Removed unnecessary nil checks for AI Agent and AI Config, simplifying the logic. - Adjusted related tests and services to align with the new function signatures. - Cleaned up code in runtime, skills, and executor packages to ensure consistency in handling AI configurations.
This commit is contained in:
@@ -38,10 +38,10 @@ func init() {
|
||||
|
||||
type CreateTicketGraph struct {
|
||||
conversation *models.Conversation
|
||||
aiAgent *models.AIAgent
|
||||
aiAgent models.AIAgent
|
||||
}
|
||||
|
||||
func NewCreateTicketGraph(conversation *models.Conversation, aiAgent *models.AIAgent) *CreateTicketGraph {
|
||||
func NewCreateTicketGraph(conversation *models.Conversation, aiAgent models.AIAgent) *CreateTicketGraph {
|
||||
return &CreateTicketGraph{
|
||||
conversation: conversation,
|
||||
aiAgent: aiAgent,
|
||||
@@ -49,7 +49,7 @@ func NewCreateTicketGraph(conversation *models.Conversation, aiAgent *models.AIA
|
||||
}
|
||||
|
||||
func (g *CreateTicketGraph) Run(ctx context.Context, argumentsInJSON string) (string, error) {
|
||||
if g == nil || g.conversation == nil || g.aiAgent == nil {
|
||||
if g == nil || g.conversation == nil {
|
||||
return "", fmt.Errorf("create ticket graph not initialized")
|
||||
}
|
||||
wasInterrupted, hasState, state := componenttool.GetInterruptState[CreateTicketGraphState](ctx)
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
package graphs
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"cs-agent/internal/models"
|
||||
)
|
||||
|
||||
func TestCreateTicketGraphBuildCreateRequest(t *testing.T) {
|
||||
graph := NewCreateTicketGraph(&models.Conversation{
|
||||
ID: 12,
|
||||
Subject: "fallback-title",
|
||||
LastMessageSummary: "fallback-description",
|
||||
}, &models.AIAgent{Name: "AI"})
|
||||
|
||||
req, err := graph.buildCreateRequest(`{"title":" test title ","description":" desc ","priority":2,"severity":3}`)
|
||||
if err != nil {
|
||||
t.Fatalf("buildCreateRequest returned error: %v", err)
|
||||
}
|
||||
if req.Title != "test title" || req.Description != "desc" {
|
||||
t.Fatalf("unexpected request text fields: %#v", req)
|
||||
}
|
||||
if req.Priority != 2 || req.Severity != 3 {
|
||||
t.Fatalf("unexpected request numeric fields: %#v", req)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateTicketGraphBuildCreateRequestFallbacks(t *testing.T) {
|
||||
graph := NewCreateTicketGraph(&models.Conversation{
|
||||
ID: 12,
|
||||
Subject: "fallback-title",
|
||||
LastMessageSummary: "fallback-description",
|
||||
}, &models.AIAgent{Name: "AI"})
|
||||
|
||||
req, err := graph.buildCreateRequest(`{}`)
|
||||
if err != nil {
|
||||
t.Fatalf("buildCreateRequest returned error: %v", err)
|
||||
}
|
||||
if req.Title != "fallback-title" {
|
||||
t.Fatalf("unexpected fallback title: %#v", req)
|
||||
}
|
||||
if req.Description != "fallback-description" {
|
||||
t.Fatalf("unexpected fallback description: %#v", req)
|
||||
}
|
||||
}
|
||||
@@ -33,10 +33,10 @@ func init() {
|
||||
|
||||
type HandoffGraph struct {
|
||||
conversation *models.Conversation
|
||||
aiAgent *models.AIAgent
|
||||
aiAgent models.AIAgent
|
||||
}
|
||||
|
||||
func NewHandoffGraph(conversation *models.Conversation, aiAgent *models.AIAgent) *HandoffGraph {
|
||||
func NewHandoffGraph(conversation *models.Conversation, aiAgent models.AIAgent) *HandoffGraph {
|
||||
return &HandoffGraph{
|
||||
conversation: conversation,
|
||||
aiAgent: aiAgent,
|
||||
@@ -44,7 +44,7 @@ func NewHandoffGraph(conversation *models.Conversation, aiAgent *models.AIAgent)
|
||||
}
|
||||
|
||||
func (g *HandoffGraph) Run(ctx context.Context, argumentsInJSON string) (string, error) {
|
||||
if g == nil || g.conversation == nil || g.aiAgent == nil {
|
||||
if g == nil || g.conversation == nil {
|
||||
return "", fmt.Errorf("handoff graph not initialized")
|
||||
}
|
||||
wasInterrupted, hasState, state := componenttool.GetInterruptState[HandoffGraphState](ctx)
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package graphs
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"cs-agent/internal/models"
|
||||
)
|
||||
|
||||
func TestHandoffGraphBuildReason(t *testing.T) {
|
||||
graph := NewHandoffGraph(&models.Conversation{ID: 1}, &models.AIAgent{Name: "AI"})
|
||||
|
||||
reason, err := graph.buildReason(`{"reason":" 用户需要人工确认 "}`)
|
||||
if err != nil {
|
||||
t.Fatalf("buildReason returned error: %v", err)
|
||||
}
|
||||
if reason != "用户需要人工确认" {
|
||||
t.Fatalf("unexpected reason: %q", reason)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandoffGraphBuildReasonFallback(t *testing.T) {
|
||||
graph := NewHandoffGraph(&models.Conversation{ID: 1}, &models.AIAgent{Name: "AI"})
|
||||
|
||||
reason, err := graph.buildReason(`{}`)
|
||||
if err != nil {
|
||||
t.Fatalf("buildReason returned error: %v", err)
|
||||
}
|
||||
if reason != "用户需要转人工支持" {
|
||||
t.Fatalf("unexpected fallback reason: %q", reason)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandoffGraphBuildSuccessReply(t *testing.T) {
|
||||
graph := NewHandoffGraph(&models.Conversation{ID: 1}, &models.AIAgent{Name: "AI"})
|
||||
|
||||
got := graph.buildSuccessReply()
|
||||
want := "已为你转接人工客服,请稍候。,请稍候。"
|
||||
if got != want {
|
||||
t.Fatalf("unexpected success reply: %q", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user