fix: add structured graph tool results
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"cs-agent/internal/ai/runtime/tooling"
|
||||
"cs-agent/internal/models"
|
||||
"cs-agent/internal/pkg/dto"
|
||||
"cs-agent/internal/pkg/dto/request"
|
||||
@@ -84,9 +85,21 @@ func (g *CreateTicketGraph) Run(ctx context.Context, argumentsInJSON string) (st
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return fmt.Sprintf("工单已创建,工单号:%s,标题:%s。", strings.TrimSpace(item.TicketNo), strings.TrimSpace(item.Title)), nil
|
||||
return tooling.MarshalToolResult(tooling.ToolResult{
|
||||
Handled: true,
|
||||
Terminal: true,
|
||||
Action: "ticket_created",
|
||||
ReplyText: fmt.Sprintf("工单已创建,工单号:%s,标题:%s。", strings.TrimSpace(item.TicketNo), strings.TrimSpace(item.Title)),
|
||||
ShouldRetry: false,
|
||||
}), nil
|
||||
case ConfirmationDecisionCancel:
|
||||
return CancelCreateTicketReply, nil
|
||||
return tooling.MarshalToolResult(tooling.ToolResult{
|
||||
Handled: true,
|
||||
Terminal: true,
|
||||
Action: "ticket_cancelled",
|
||||
ReplyText: CancelCreateTicketReply,
|
||||
ShouldRetry: false,
|
||||
}), nil
|
||||
default:
|
||||
info := CreateTicketGraphInterruptInfo{
|
||||
Type: InterruptTypeTicketCreationConfirmation,
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"cs-agent/internal/ai/runtime/tooling"
|
||||
"cs-agent/internal/models"
|
||||
"cs-agent/internal/services"
|
||||
|
||||
@@ -53,7 +54,14 @@ func (g *HandoffGraph) Run(ctx context.Context, argumentsInJSON string) (string,
|
||||
handled, err := services.ConversationService.TryOffHoursHandoffByAI(g.conversation.ID, g.aiAgent, reason)
|
||||
if err != nil || handled {
|
||||
if handled && err == nil {
|
||||
return services.HandoffOffHoursMessage, nil
|
||||
return tooling.MarshalToolResult(tooling.ToolResult{
|
||||
Handled: true,
|
||||
Terminal: true,
|
||||
Action: "off_hours_handoff",
|
||||
ReplyText: services.HandoffOffHoursMessage,
|
||||
ReplySent: true,
|
||||
ShouldRetry: false,
|
||||
}), nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
@@ -87,9 +95,21 @@ func (g *HandoffGraph) Run(ctx context.Context, argumentsInJSON string) (string,
|
||||
return "", err
|
||||
}
|
||||
// ConversationService sends the customer-visible handoff notice according to the dispatch decision.
|
||||
return "", nil
|
||||
return tooling.MarshalToolResult(tooling.ToolResult{
|
||||
Handled: true,
|
||||
Terminal: true,
|
||||
Action: "handoff_confirmed",
|
||||
ReplySent: true,
|
||||
ShouldRetry: false,
|
||||
}), nil
|
||||
case ConfirmationDecisionCancel:
|
||||
return CancelHandoffReply, nil
|
||||
return tooling.MarshalToolResult(tooling.ToolResult{
|
||||
Handled: true,
|
||||
Terminal: true,
|
||||
Action: "handoff_cancelled",
|
||||
ReplyText: CancelHandoffReply,
|
||||
ShouldRetry: false,
|
||||
}), nil
|
||||
default:
|
||||
info := HandoffGraphInterruptInfo{
|
||||
Type: InterruptTypeHandoffConfirmation,
|
||||
|
||||
@@ -2,10 +2,12 @@ package graphs
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"cs-agent/internal/ai/runtime/tooling"
|
||||
"cs-agent/internal/models"
|
||||
"cs-agent/internal/pkg/enums"
|
||||
"cs-agent/internal/services"
|
||||
@@ -25,8 +27,18 @@ func TestHandoffGraphOffHoursSendsNoticeWithoutConfirmation(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Run() error = %v", err)
|
||||
}
|
||||
if reply != services.HandoffOffHoursMessage {
|
||||
t.Fatalf("expected off-hours graph reply, got %q", reply)
|
||||
var result tooling.ToolResult
|
||||
if err := json.Unmarshal([]byte(reply), &result); err != nil {
|
||||
t.Fatalf("expected graph tool result JSON, got %q: %v", reply, err)
|
||||
}
|
||||
if !result.Handled || !result.Terminal || result.ShouldRetry {
|
||||
t.Fatalf("unexpected graph result flags: %+v", result)
|
||||
}
|
||||
if !result.ReplySent {
|
||||
t.Fatalf("expected graph result to mark replySent, got %+v", result)
|
||||
}
|
||||
if result.Action != "off_hours_handoff" || result.ReplyText != services.HandoffOffHoursMessage {
|
||||
t.Fatalf("unexpected off-hours graph result: %+v", result)
|
||||
}
|
||||
|
||||
message := services.MessageService.FindOne(sqls.NewCnd().Eq("conversation_id", conversation.ID).Desc("id"))
|
||||
|
||||
Reference in New Issue
Block a user