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