mirror of
https://git.boos.lat/aibo/BossChat.git
synced 2026-10-30 23:26:09 +00:00
0f40930a41
- Rename Go module: cs-agent → bosschat - Rename all import paths across 200+ Go files - Rename SDK: cs-ai-agent-sdk → bosschat-sdk - Rename message protocol: cs-agent:* → bosschat:* - Rename JS globals: CSAgentConfig → BossChatConfig - Rename CSS classes: cs-agent-* → bosschat-* - Update Makefile APP_NAME and ARCHIVE_NAME - Update logo assets - Fix display name: BoosChat → BossChat
178 lines
4.7 KiB
Go
178 lines
4.7 KiB
Go
package executor
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"bosschat/internal/ai/runtime/tooling"
|
|
"bosschat/internal/pkg/toolx"
|
|
|
|
"github.com/cloudwego/eino/adk"
|
|
"github.com/cloudwego/eino/schema"
|
|
)
|
|
|
|
func TestConsumeAgentEventsIgnoresPlainGraphToolText(t *testing.T) {
|
|
summary := &RunResult{
|
|
Status: "started",
|
|
InvokedToolCodes: make([]string, 0),
|
|
}
|
|
events, gen := adk.NewAsyncIteratorPair[*adk.AgentEvent]()
|
|
gen.Send(&adk.AgentEvent{
|
|
Output: &adk.AgentOutput{
|
|
MessageOutput: &adk.MessageVariant{
|
|
Role: schema.Tool,
|
|
ToolName: toolx.GraphHandoffConversation.Name,
|
|
Message: &schema.Message{
|
|
Content: "已为你转接人工客服,请稍候。,请稍候。",
|
|
},
|
|
},
|
|
},
|
|
})
|
|
gen.Close()
|
|
|
|
consumeAgentEvents(events, summary, nil, map[string]string{
|
|
toolx.GraphHandoffConversation.Name: toolx.GraphHandoffConversation.Code,
|
|
})
|
|
|
|
if summary.ReplyText != "" {
|
|
t.Fatalf("unexpected reply text: %q", summary.ReplyText)
|
|
}
|
|
if summary.Status != "completed" {
|
|
t.Fatalf("unexpected summary status: %q", summary.Status)
|
|
}
|
|
}
|
|
|
|
func TestConsumeAgentEventsUsesGraphToolResultReplyText(t *testing.T) {
|
|
summary := &RunResult{
|
|
Status: "started",
|
|
InvokedToolCodes: make([]string, 0),
|
|
}
|
|
payload, err := json.Marshal(tooling.ToolResult{
|
|
Handled: true,
|
|
Terminal: true,
|
|
Action: "off_hours_handoff",
|
|
ReplyText: "当前暂不在人工客服服务时间内,你可以先继续描述问题。",
|
|
ShouldRetry: false,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("marshal graph tool result: %v", err)
|
|
}
|
|
events, gen := adk.NewAsyncIteratorPair[*adk.AgentEvent]()
|
|
gen.Send(&adk.AgentEvent{
|
|
Output: &adk.AgentOutput{
|
|
MessageOutput: &adk.MessageVariant{
|
|
Role: schema.Tool,
|
|
ToolName: toolx.GraphHandoffConversation.Name,
|
|
Message: &schema.Message{
|
|
Content: string(payload),
|
|
},
|
|
},
|
|
},
|
|
})
|
|
gen.Send(&adk.AgentEvent{
|
|
Output: &adk.AgentOutput{
|
|
MessageOutput: &adk.MessageVariant{
|
|
Role: schema.Assistant,
|
|
Message: &schema.Message{
|
|
Content: "我再试一次转人工。",
|
|
},
|
|
},
|
|
},
|
|
})
|
|
gen.Close()
|
|
|
|
consumeAgentEvents(events, summary, nil, map[string]string{
|
|
toolx.GraphHandoffConversation.Name: toolx.GraphHandoffConversation.Code,
|
|
})
|
|
|
|
if summary.ReplyText != "当前暂不在人工客服服务时间内,你可以先继续描述问题。" {
|
|
t.Fatalf("unexpected reply text: %q", summary.ReplyText)
|
|
}
|
|
if summary.Status != "completed" {
|
|
t.Fatalf("unexpected summary status: %q", summary.Status)
|
|
}
|
|
}
|
|
|
|
func TestConsumeAgentEventsSuppressesGraphToolResultWhenReplyAlreadySent(t *testing.T) {
|
|
summary := &RunResult{
|
|
Status: "started",
|
|
InvokedToolCodes: make([]string, 0),
|
|
}
|
|
payload, err := json.Marshal(tooling.ToolResult{
|
|
Handled: true,
|
|
Terminal: true,
|
|
Action: "off_hours_handoff",
|
|
ReplyText: "当前暂不在人工客服服务时间内,你可以先继续描述问题。",
|
|
ReplySent: true,
|
|
ShouldRetry: false,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("marshal graph tool result: %v", err)
|
|
}
|
|
events, gen := adk.NewAsyncIteratorPair[*adk.AgentEvent]()
|
|
gen.Send(&adk.AgentEvent{
|
|
Output: &adk.AgentOutput{
|
|
MessageOutput: &adk.MessageVariant{
|
|
Role: schema.Tool,
|
|
ToolName: toolx.GraphHandoffConversation.Name,
|
|
Message: &schema.Message{
|
|
Content: string(payload),
|
|
},
|
|
},
|
|
},
|
|
})
|
|
gen.Send(&adk.AgentEvent{
|
|
Output: &adk.AgentOutput{
|
|
MessageOutput: &adk.MessageVariant{
|
|
Role: schema.Assistant,
|
|
Message: &schema.Message{
|
|
Content: "我再试一次转人工。",
|
|
},
|
|
},
|
|
},
|
|
})
|
|
gen.Close()
|
|
|
|
consumeAgentEvents(events, summary, nil, map[string]string{
|
|
toolx.GraphHandoffConversation.Name: toolx.GraphHandoffConversation.Code,
|
|
})
|
|
|
|
if summary.ReplyText != "" {
|
|
t.Fatalf("expected no committed reply because graph already sent it, got %q", summary.ReplyText)
|
|
}
|
|
if summary.Status != "completed" {
|
|
t.Fatalf("unexpected summary status: %q", summary.Status)
|
|
}
|
|
}
|
|
|
|
func TestConsumeAgentEventsCompletesGraphToolWithNoVisibleReply(t *testing.T) {
|
|
summary := &RunResult{
|
|
Status: "started",
|
|
InvokedToolCodes: make([]string, 0),
|
|
}
|
|
events, gen := adk.NewAsyncIteratorPair[*adk.AgentEvent]()
|
|
gen.Send(&adk.AgentEvent{
|
|
Output: &adk.AgentOutput{
|
|
MessageOutput: &adk.MessageVariant{
|
|
Role: schema.Tool,
|
|
ToolName: toolx.GraphHandoffConversation.Name,
|
|
Message: &schema.Message{
|
|
Content: "",
|
|
},
|
|
},
|
|
},
|
|
})
|
|
gen.Close()
|
|
|
|
consumeAgentEvents(events, summary, nil, map[string]string{
|
|
toolx.GraphHandoffConversation.Name: toolx.GraphHandoffConversation.Code,
|
|
})
|
|
|
|
if summary.ReplyText != "" {
|
|
t.Fatalf("expected no reply text, got %q", summary.ReplyText)
|
|
}
|
|
if summary.Status != "completed" {
|
|
t.Fatalf("unexpected summary status: %q", summary.Status)
|
|
}
|
|
}
|