feat: implement Spec method for tools and update tool resolution logic in the registry
This commit is contained in:
@@ -29,7 +29,11 @@ func (r *Registry) Resolve(ctx Context) (*ToolSet, error) {
|
||||
if toolDef == nil || !toolDef.Enabled(ctx) {
|
||||
continue
|
||||
}
|
||||
toolCode := strings.TrimSpace(toolDef.Code())
|
||||
spec := toolDef.Spec()
|
||||
toolCode := strings.TrimSpace(spec.Code)
|
||||
if toolCode == "" {
|
||||
toolCode = strings.TrimSpace(toolDef.Code())
|
||||
}
|
||||
if len(allowedToolCodes) > 0 && !isAllowedToolCode(toolCode, allowedToolCodes) {
|
||||
continue
|
||||
}
|
||||
@@ -40,13 +44,25 @@ func (r *Registry) Resolve(ctx Context) (*ToolSet, error) {
|
||||
if tool == nil {
|
||||
continue
|
||||
}
|
||||
toolName := strings.TrimSpace(toolDef.Name())
|
||||
toolName := strings.TrimSpace(spec.Name)
|
||||
if toolName == "" {
|
||||
toolName = strings.TrimSpace(toolDef.Name())
|
||||
}
|
||||
if toolName == "" || toolCode == "" {
|
||||
continue
|
||||
}
|
||||
ret.StaticTools = append(ret.StaticTools, tool)
|
||||
ret.StaticToolCodes[toolName] = toolCode
|
||||
resolvedMetadata := toolx.ResolveToolMetadata(toolCode, toolName)
|
||||
if strings.TrimSpace(resolvedMetadata.ServerCode) == "" {
|
||||
resolvedMetadata.ServerCode = strings.TrimSpace(spec.ServerCode)
|
||||
}
|
||||
if strings.TrimSpace(resolvedMetadata.ToolName) == "" {
|
||||
resolvedMetadata.ToolName = toolName
|
||||
}
|
||||
if strings.TrimSpace(resolvedMetadata.SourceType) == "" {
|
||||
resolvedMetadata.SourceType = strings.TrimSpace(spec.SourceType)
|
||||
}
|
||||
ret.StaticToolMetadata[toolName] = ToolMetadata{
|
||||
ToolCode: resolvedMetadata.ToolCode,
|
||||
ServerCode: resolvedMetadata.ServerCode,
|
||||
|
||||
@@ -17,6 +17,15 @@ type stubTool struct {
|
||||
code string
|
||||
}
|
||||
|
||||
func (t stubTool) Spec() toolx.ToolSpec {
|
||||
return toolx.ToolSpec{
|
||||
Code: t.code,
|
||||
Name: t.name,
|
||||
ServerCode: toolx.GraphCreateTicketConfirm.ServerCode,
|
||||
SourceType: toolx.GraphCreateTicketConfirm.SourceType,
|
||||
}
|
||||
}
|
||||
|
||||
func (t stubTool) Name() string { return t.name }
|
||||
func (t stubTool) Code() string { return t.code }
|
||||
func (t stubTool) Enabled(registry.Context) bool {
|
||||
|
||||
@@ -2,6 +2,7 @@ package registry
|
||||
|
||||
import (
|
||||
"cs-agent/internal/models"
|
||||
"cs-agent/internal/pkg/toolx"
|
||||
|
||||
einotool "github.com/cloudwego/eino/components/tool"
|
||||
)
|
||||
@@ -34,6 +35,7 @@ type ToolSet struct {
|
||||
}
|
||||
|
||||
type Tool interface {
|
||||
Spec() toolx.ToolSpec
|
||||
Name() string
|
||||
Code() string
|
||||
Enabled(ctx Context) bool
|
||||
|
||||
@@ -23,6 +23,10 @@ func NewAnalyzeConversationTool() *AnalyzeConversationTool {
|
||||
return &AnalyzeConversationTool{}
|
||||
}
|
||||
|
||||
func (t *AnalyzeConversationTool) Spec() toolx.ToolSpec {
|
||||
return toolx.GraphAnalyzeConversation
|
||||
}
|
||||
|
||||
func (t *AnalyzeConversationTool) Name() string {
|
||||
return toolx.GraphAnalyzeConversation.Name
|
||||
}
|
||||
|
||||
@@ -24,6 +24,10 @@ func NewCreateTicketGraphTool() *CreateTicketGraphTool {
|
||||
return &CreateTicketGraphTool{}
|
||||
}
|
||||
|
||||
func (t *CreateTicketGraphTool) Spec() toolx.ToolSpec {
|
||||
return toolx.GraphCreateTicketConfirm
|
||||
}
|
||||
|
||||
func (t *CreateTicketGraphTool) Name() string {
|
||||
return toolx.GraphCreateTicketConfirm.Name
|
||||
}
|
||||
|
||||
@@ -24,6 +24,10 @@ func NewHandoffGraphTool() *HandoffGraphTool {
|
||||
return &HandoffGraphTool{}
|
||||
}
|
||||
|
||||
func (t *HandoffGraphTool) Spec() toolx.ToolSpec {
|
||||
return toolx.GraphHandoffConversation
|
||||
}
|
||||
|
||||
func (t *HandoffGraphTool) Name() string {
|
||||
return toolx.GraphHandoffConversation.Name
|
||||
}
|
||||
|
||||
@@ -23,6 +23,10 @@ func NewPrepareTicketDraftTool() *PrepareTicketDraftTool {
|
||||
return &PrepareTicketDraftTool{}
|
||||
}
|
||||
|
||||
func (t *PrepareTicketDraftTool) Spec() toolx.ToolSpec {
|
||||
return toolx.GraphPrepareTicketDraft
|
||||
}
|
||||
|
||||
func (t *PrepareTicketDraftTool) Name() string {
|
||||
return toolx.GraphPrepareTicketDraft.Name
|
||||
}
|
||||
|
||||
@@ -26,6 +26,10 @@ func NewToolSearchTool() *ToolSearchTool {
|
||||
return &ToolSearchTool{}
|
||||
}
|
||||
|
||||
func (t *ToolSearchTool) Spec() toolx.ToolSpec {
|
||||
return toolx.BuiltinToolSearch
|
||||
}
|
||||
|
||||
func (t *ToolSearchTool) Name() string {
|
||||
return toolx.BuiltinToolSearch.Name
|
||||
}
|
||||
|
||||
@@ -23,6 +23,10 @@ func NewTriageServiceRequestTool() *TriageServiceRequestTool {
|
||||
return &TriageServiceRequestTool{}
|
||||
}
|
||||
|
||||
func (t *TriageServiceRequestTool) Spec() toolx.ToolSpec {
|
||||
return toolx.GraphTriageServiceRequest
|
||||
}
|
||||
|
||||
func (t *TriageServiceRequestTool) Name() string {
|
||||
return toolx.GraphTriageServiceRequest.Name
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user