feat: refactor tool catalog to use NewRuntimeStaticTool for dynamic tool creation

This commit is contained in:
mlogclub
2026-04-14 09:56:52 +08:00
parent 200631cc0b
commit 3254ba1bf4
2 changed files with 24 additions and 11 deletions
@@ -21,20 +21,13 @@ func newToolCatalog() *toolCatalog {
} }
func buildRuntimeStaticTools() []registry.Tool { func buildRuntimeStaticTools() []registry.Tool {
builders := map[string]func() registry.Tool{ ret := make([]registry.Tool, 0, len(toolx.ListRuntimeStaticToolSpecs()))
toolx.GraphTriageServiceRequest.Code: func() registry.Tool { return tools.NewTriageServiceRequestTool() },
toolx.GraphAnalyzeConversation.Code: func() registry.Tool { return tools.NewAnalyzeConversationTool() },
toolx.GraphPrepareTicketDraft.Code: func() registry.Tool { return tools.NewPrepareTicketDraftTool() },
toolx.GraphCreateTicketConfirm.Code: func() registry.Tool { return tools.NewCreateTicketGraphTool() },
toolx.GraphHandoffConversation.Code: func() registry.Tool { return tools.NewHandoffGraphTool() },
}
ret := make([]registry.Tool, 0, len(builders))
for _, spec := range toolx.ListRuntimeStaticToolSpecs() { for _, spec := range toolx.ListRuntimeStaticToolSpecs() {
build := builders[strings.TrimSpace(spec.Code)] tool := tools.NewRuntimeStaticTool(spec.Code)
if build == nil { if tool == nil {
continue continue
} }
ret = append(ret, build()) ret = append(ret, tool)
} }
return ret return ret
} }
+20
View File
@@ -3,6 +3,9 @@ package tools
import ( import (
"fmt" "fmt"
"strings" "strings"
"cs-agent/internal/ai/runtime/registry"
"cs-agent/internal/pkg/toolx"
) )
type Decision string type Decision string
@@ -61,3 +64,20 @@ func getInt64Value(data map[string]any, key string) int64 {
return 0 return 0
} }
} }
func NewRuntimeStaticTool(toolCode string) registry.Tool {
switch toolx.NormalizeToolCodeAlias(strings.TrimSpace(toolCode)) {
case toolx.GraphTriageServiceRequest.Code:
return NewTriageServiceRequestTool()
case toolx.GraphAnalyzeConversation.Code:
return NewAnalyzeConversationTool()
case toolx.GraphPrepareTicketDraft.Code:
return NewPrepareTicketDraftTool()
case toolx.GraphCreateTicketConfirm.Code:
return NewCreateTicketGraphTool()
case toolx.GraphHandoffConversation.Code:
return NewHandoffGraphTool()
default:
return nil
}
}