Enhance skill debugging and response structure by adding skill name and allowed tool codes, and refactor related data handling
This commit is contained in:
@@ -73,6 +73,7 @@ func buildSkillDebugRunResponse(req request.SkillDebugRunRequest, summary *Summa
|
|||||||
resp.ReplyText = summary.ReplyText
|
resp.ReplyText = summary.ReplyText
|
||||||
resp.PlanReason = summary.PlanReason
|
resp.PlanReason = summary.PlanReason
|
||||||
resp.SkillRouteTrace = summary.SkillRouteTrace
|
resp.SkillRouteTrace = summary.SkillRouteTrace
|
||||||
|
resp.SkillAllowedToolCodes = append([]string(nil), summary.SkillAllowedToolCodes...)
|
||||||
resp.ToolCodes = append([]string(nil), summary.ToolCodes...)
|
resp.ToolCodes = append([]string(nil), summary.ToolCodes...)
|
||||||
resp.InvokedToolCodes = append([]string(nil), summary.InvokedToolCodes...)
|
resp.InvokedToolCodes = append([]string(nil), summary.InvokedToolCodes...)
|
||||||
resp.CheckPointID = summary.CheckPointID
|
resp.CheckPointID = summary.CheckPointID
|
||||||
|
|||||||
@@ -95,11 +95,19 @@ func (s *Service) Run(ctx context.Context, req Request) (*Summary, error) {
|
|||||||
collector.Data.Model.Provider = string(req.AIConfig.Provider)
|
collector.Data.Model.Provider = string(req.AIConfig.Provider)
|
||||||
collector.Data.Model.Name = req.AIConfig.ModelName
|
collector.Data.Model.Name = req.AIConfig.ModelName
|
||||||
summary.SelectedSkillCode = ""
|
summary.SelectedSkillCode = ""
|
||||||
|
summary.SelectedSkillName = ""
|
||||||
summary.SkillRouteReason = strings.TrimSpace(req.SkillRouteReason)
|
summary.SkillRouteReason = strings.TrimSpace(req.SkillRouteReason)
|
||||||
summary.SkillRouteTrace = strings.TrimSpace(req.SkillRouteTrace)
|
summary.SkillRouteTrace = strings.TrimSpace(req.SkillRouteTrace)
|
||||||
if req.SelectedSkill != nil {
|
if req.SelectedSkill != nil {
|
||||||
summary.SelectedSkillCode = strings.TrimSpace(req.SelectedSkill.Code)
|
summary.SelectedSkillCode = strings.TrimSpace(req.SelectedSkill.Code)
|
||||||
|
summary.SelectedSkillName = strings.TrimSpace(req.SelectedSkill.Name)
|
||||||
|
summary.SkillAllowedToolCodes = parseJSONArrayList(req.SelectedSkill.AllowedToolCodes)
|
||||||
|
collector.Data.Skill.Code = summary.SelectedSkillCode
|
||||||
|
collector.Data.Skill.Name = summary.SelectedSkillName
|
||||||
|
collector.Data.Skill.AllowedToolCodes = append([]string(nil), summary.SkillAllowedToolCodes...)
|
||||||
}
|
}
|
||||||
|
collector.Data.Skill.RouteReason = summary.SkillRouteReason
|
||||||
|
collector.Data.Skill.RouteTrace = summary.SkillRouteTrace
|
||||||
|
|
||||||
agent, err := s.agentFactory.BuildCustomerServiceAgent(ctx, req.AIAgent, req.AIConfig, req.SelectedSkill, filteredToolDefs, req.ExtraTools, req.ExtraToolCodes, collector)
|
agent, err := s.agentFactory.BuildCustomerServiceAgent(ctx, req.AIAgent, req.AIConfig, req.SelectedSkill, filteredToolDefs, req.ExtraTools, req.ExtraToolCodes, collector)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -287,6 +295,22 @@ func filterToolDefinitionsBySkill(definitions []adapter.MCPToolDefinition, skill
|
|||||||
}
|
}
|
||||||
|
|
||||||
func parseJSONArraySet(raw string) map[string]struct{} {
|
func parseJSONArraySet(raw string) map[string]struct{} {
|
||||||
|
raw = strings.TrimSpace(raw)
|
||||||
|
if raw == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
items := parseJSONArrayList(raw)
|
||||||
|
if len(items) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
ret := make(map[string]struct{}, len(items))
|
||||||
|
for _, item := range items {
|
||||||
|
ret[item] = struct{}{}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseJSONArrayList(raw string) []string {
|
||||||
raw = strings.TrimSpace(raw)
|
raw = strings.TrimSpace(raw)
|
||||||
if raw == "" {
|
if raw == "" {
|
||||||
return nil
|
return nil
|
||||||
@@ -295,13 +319,13 @@ func parseJSONArraySet(raw string) map[string]struct{} {
|
|||||||
if err := json.Unmarshal([]byte(raw), &items); err != nil {
|
if err := json.Unmarshal([]byte(raw), &items); err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ret := make(map[string]struct{}, len(items))
|
ret := make([]string, 0, len(items))
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
item = strings.TrimSpace(item)
|
item = strings.TrimSpace(item)
|
||||||
if item == "" {
|
if item == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ret[item] = struct{}{}
|
ret = append(ret, item)
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,8 +40,10 @@ type Summary struct {
|
|||||||
Status string
|
Status string
|
||||||
ReplyText string
|
ReplyText string
|
||||||
SelectedSkillCode string
|
SelectedSkillCode string
|
||||||
|
SelectedSkillName string
|
||||||
SkillRouteReason string
|
SkillRouteReason string
|
||||||
SkillRouteTrace string
|
SkillRouteTrace string
|
||||||
|
SkillAllowedToolCodes []string
|
||||||
ModelName string
|
ModelName string
|
||||||
PromptTokens int
|
PromptTokens int
|
||||||
CompletionTokens int
|
CompletionTokens int
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ type RuntimeTraceData struct {
|
|||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
RunID string `json:"runId,omitempty"`
|
RunID string `json:"runId,omitempty"`
|
||||||
|
Skill SkillTraceData `json:"skill,omitempty"`
|
||||||
Interrupt struct {
|
Interrupt struct {
|
||||||
CheckPointID string `json:"checkPointId,omitempty"`
|
CheckPointID string `json:"checkPointId,omitempty"`
|
||||||
Items []InterruptTraceContext `json:"items,omitempty"`
|
Items []InterruptTraceContext `json:"items,omitempty"`
|
||||||
@@ -56,6 +57,14 @@ type RuntimeTraceData struct {
|
|||||||
} `json:"error"`
|
} `json:"error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SkillTraceData struct {
|
||||||
|
Code string `json:"code,omitempty"`
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
|
RouteReason string `json:"routeReason,omitempty"`
|
||||||
|
RouteTrace string `json:"routeTrace,omitempty"`
|
||||||
|
AllowedToolCodes []string `json:"allowedToolCodes,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type InterruptTraceContext struct {
|
type InterruptTraceContext struct {
|
||||||
Type string `json:"type,omitempty"`
|
Type string `json:"type,omitempty"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
|
|||||||
@@ -128,8 +128,10 @@ func toSummary(summary *engine.Summary) *Summary {
|
|||||||
Status: summary.Status,
|
Status: summary.Status,
|
||||||
ReplyText: summary.ReplyText,
|
ReplyText: summary.ReplyText,
|
||||||
PlannedSkillCode: strings.TrimSpace(summary.SelectedSkillCode),
|
PlannedSkillCode: strings.TrimSpace(summary.SelectedSkillCode),
|
||||||
|
PlannedSkillName: strings.TrimSpace(summary.SelectedSkillName),
|
||||||
PlanReason: strings.TrimSpace(summary.SkillRouteReason),
|
PlanReason: strings.TrimSpace(summary.SkillRouteReason),
|
||||||
SkillRouteTrace: strings.TrimSpace(summary.SkillRouteTrace),
|
SkillRouteTrace: strings.TrimSpace(summary.SkillRouteTrace),
|
||||||
|
SkillAllowedToolCodes: append([]string(nil), summary.SkillAllowedToolCodes...),
|
||||||
ModelName: summary.ModelName,
|
ModelName: summary.ModelName,
|
||||||
PromptTokens: summary.PromptTokens,
|
PromptTokens: summary.PromptTokens,
|
||||||
CompletionTokens: summary.CompletionTokens,
|
CompletionTokens: summary.CompletionTokens,
|
||||||
|
|||||||
@@ -41,8 +41,10 @@ type Summary struct {
|
|||||||
Status string
|
Status string
|
||||||
ReplyText string
|
ReplyText string
|
||||||
PlannedSkillCode string
|
PlannedSkillCode string
|
||||||
|
PlannedSkillName string
|
||||||
PlanReason string
|
PlanReason string
|
||||||
SkillRouteTrace string
|
SkillRouteTrace string
|
||||||
|
SkillAllowedToolCodes []string
|
||||||
ModelName string
|
ModelName string
|
||||||
PromptTokens int
|
PromptTokens int
|
||||||
CompletionTokens int
|
CompletionTokens int
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package skills
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -157,13 +158,40 @@ func buildSkillRoutePrompt(userMessage string, candidates []models.SkillDefiniti
|
|||||||
lines = append(lines, "")
|
lines = append(lines, "")
|
||||||
lines = append(lines, "候选 Skills:")
|
lines = append(lines, "候选 Skills:")
|
||||||
for _, item := range candidates {
|
for _, item := range candidates {
|
||||||
lines = append(lines, fmt.Sprintf("- skillCode=%s; name=%s; description=%s", strings.TrimSpace(item.Code), strings.TrimSpace(item.Name), strings.TrimSpace(item.Description)))
|
line := fmt.Sprintf("- skillCode=%s; name=%s; description=%s", strings.TrimSpace(item.Code), strings.TrimSpace(item.Name), strings.TrimSpace(item.Description))
|
||||||
|
if examples := parseSkillExamples(item.Examples); len(examples) > 0 {
|
||||||
|
line += "; examples=" + strings.Join(examples, " | ")
|
||||||
|
}
|
||||||
|
lines = append(lines, line)
|
||||||
}
|
}
|
||||||
lines = append(lines, "")
|
lines = append(lines, "")
|
||||||
lines = append(lines, "请只输出一个 skillCode 或 NONE。")
|
lines = append(lines, "请只输出一个 skillCode 或 NONE。")
|
||||||
return strings.Join(lines, "\n")
|
return strings.Join(lines, "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseSkillExamples(raw string) []string {
|
||||||
|
raw = strings.TrimSpace(raw)
|
||||||
|
if raw == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
var items []string
|
||||||
|
if err := json.Unmarshal([]byte(raw), &items); err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
ret := make([]string, 0, len(items))
|
||||||
|
for _, item := range items {
|
||||||
|
item = strings.TrimSpace(item)
|
||||||
|
if item == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ret = append(ret, item)
|
||||||
|
if len(ret) >= 3 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
func normalizeRouteDecision(raw string) string {
|
func normalizeRouteDecision(raw string) string {
|
||||||
raw = strings.TrimSpace(raw)
|
raw = strings.TrimSpace(raw)
|
||||||
if raw == "" {
|
if raw == "" {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ type SkillDebugRunResponse struct {
|
|||||||
ReplyText string `json:"replyText"`
|
ReplyText string `json:"replyText"`
|
||||||
PlanReason string `json:"planReason"`
|
PlanReason string `json:"planReason"`
|
||||||
SkillRouteTrace string `json:"skillRouteTrace"`
|
SkillRouteTrace string `json:"skillRouteTrace"`
|
||||||
|
SkillAllowedToolCodes []string `json:"skillAllowedToolCodes"`
|
||||||
ToolCodes []string `json:"toolCodes"`
|
ToolCodes []string `json:"toolCodes"`
|
||||||
InvokedToolCodes []string `json:"invokedToolCodes"`
|
InvokedToolCodes []string `json:"invokedToolCodes"`
|
||||||
CheckPointID string `json:"checkPointId"`
|
CheckPointID string `json:"checkPointId"`
|
||||||
|
|||||||
Reference in New Issue
Block a user